ट्यूटोरियल: AdMob में नए विज्ञापन फ़ॉर्मैट टेस्ट करने का तरीका

तीसरा चरण: अपने ऐप्लिकेशन के कोड में रिमोट कॉन्फ़िगरेशन पैरामीटर की वैल्यू मैनेज करना


बुनियादी जानकारी: Firebase का इस्तेमाल करके, AdMob के नए विज्ञापन फ़ॉर्मैट की जांच करें
पहला चरण: टेस्टिंग के लिए, विज्ञापन यूनिट का नया वैरिएंट बनाने के लिए AdMob का इस्तेमाल करना
दूसरा चरण: Firebase कंसोल में A/B टेस्ट सेट अप करें

तीसरा चरण: अपने ऐप्लिकेशन के कोड में, रिमोट कॉन्फ़िगरेशन की पैरामीटर वैल्यू को मैनेज करना

चौथा चरण: A/B टेस्ट शुरू करें और Firebase कंसोल में टेस्ट के नतीजे देखें
पांचवां चरण: तय करें कि नए विज्ञापन फ़ॉर्मैट को रोल आउट करना है या नहीं


आखिरी चरण के आखिर में, आपने एक रिमोट कॉन्फ़िगरेशन पैरामीटर (SHOW_NEW_AD_KEY) बनाया था. इस चरण में, आपको अपने ऐप्लिकेशन के कोड में यह लॉजिक जोड़ना होगा कि उस पैरामीटर की वैल्यू के आधार पर आपके ऐप्लिकेशन को क्या दिखाना चाहिए — true (नया विज्ञापन दिखाएं) बनाम false (नया विज्ञापन न दिखाएं).

ज़रूरी SDK टूल जोड़ना

अपने ऐप्लिकेशन कोड में रिमोट कॉन्फ़िगरेशन का इस्तेमाल करने से पहले, अपनी प्रोजेक्ट बिल्ड फ़ाइलों में रिमोट कॉन्फ़िगरेशन SDK टूल और Google Analytics के लिए Firebase SDK टूल, दोनों जोड़ें.

Apple के प्लैटफ़ॉर्म

अपनी पॉडफ़ाइल में, इन पॉड को जोड़ें और इंस्टॉल करें:

pod 'Google-Mobile-Ads-SDK'
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'

Android

अपनी build.gradle फ़ाइल में, ये लाइब्रेरी डिपेंडेंसी जोड़ें:

implementation 'com.google.android.gms:play-services-ads:23.1.0'
implementation 'com.google.firebase:firebase-analytics:22.0.2'
implementation 'com.google.firebase:firebase-config:22.0.0'

Unity

Firebase Unity SDK टूल को डाउनलोड और इंस्टॉल करें. इसके बाद, अपने प्रोजेक्ट में ये Unity पैकेज जोड़ें:

  • FirebaseAnalytics.unitypackage
  • FirebaseRemoteConfig.unitypackage

रिमोट कॉन्फ़िगरेशन के इंस्टेंस को कॉन्फ़िगर करना

रिमोट कॉन्फ़िगरेशन की पैरामीटर वैल्यू इस्तेमाल करने के लिए, रिमोट कॉन्फ़िगरेशन इंस्टेंस कॉन्फ़िगर करें. इससे क्लाइंट ऐप्लिकेशन इंस्टेंस की नई वैल्यू फ़ेच करने के लिए, इसे सेट अप किया जा सकता है.

इस उदाहरण में, रिमोट कॉन्फ़िगरेशन को इस तरह कॉन्फ़िगर किया गया है कि हर घंटे एक बार नई पैरामीटर वैल्यू की जांच की जा सके.

Swift

remoteConfig = RemoteConfig.remoteConfig()
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 3600
remoteConfig.configSettings = settings

Objective-C

self.remoteConfig = [FIRRemoteConfig remoteConfig];
FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] init];
remoteConfigSettings.minimumFetchInterval = 3600;
self.remoteConfig.configSettings = remoteConfigSettings;

Java

mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
        .setMinimumFetchIntervalInSeconds(3600)
        .build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);

Kotlin+KTX

remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
    minimumFetchIntervalInSeconds = 3600
}
remoteConfig.setConfigSettingsAsync(configSettings)

Unity

var remoteConfig = FirebaseRemoteConfig.DefaultInstance;
var configSettings = new ConfigSettings {
  MinimumFetchInternalInMilliseconds =
        (ulong)(new TimeSpan(1, 0, 0).TotalMilliseconds)
};
remoteConfig.SetConfigSettingsAsync(configSettings)
        .ContinueWithOnMainThread(task => {
          Debug.Log("Config settings confirmed");
}

रिमोट कॉन्फ़िगरेशन फ़ेच और चालू करना

रिमोट कॉन्फ़िगरेशन पैरामीटर फ़ेच और चालू करें, ताकि यह नई पैरामीटर वैल्यू का इस्तेमाल कर सके.

ऐप्लिकेशन लोड होने के दौरान आपको जल्द से जल्द यह कॉल करना चाहिए, क्योंकि यह कॉल एसिंक्रोनस है और आपको रिमोट कॉन्फ़िगरेशन की वैल्यू पहले से फ़ेच करनी होगी, ताकि आपके ऐप्लिकेशन को पता चल सके कि विज्ञापन दिखाना है या नहीं.

Swift

remoteConfig.fetch() { (status, error) -> Void in
  if status == .success {
    print("Config fetched!")
    self.remoteConfig.activate() { (changed, error) in
      // ...
    }
  } else {
    print("Config not fetched")
    print("Error: \(error?.localizedDescription ?? "No error available.")")
  }
  self.loadAdUnit()
}

Objective-C

[self.remoteConfig fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) {
    if (status == FIRRemoteConfigFetchStatusSuccess) {
        NSLog(@"Config fetched!");
      [self.remoteConfig activateWithCompletion:^(BOOL changed, NSError * _Nullable error) {
        // ...
      }];
    } else {
        NSLog(@"Config not fetched");
        NSLog(@"Error %@", error.localizedDescription);
    }
    [self loadAdUnit];
}];

Java

mFirebaseRemoteConfig.fetchAndActivate()
        .addOnCompleteListener(this, new OnCompleteListener<Boolean>() {
            @Override
            public void onComplete(@NonNull Task<Boolean> task) {
                if (task.isSuccessful()) {
                    boolean updated = task.getResult();
                    Log.d(TAG, "Config params updated: " + updated);
                } else {
                    Log.d(TAG, "Config params failed to update");
                }
                loadAdUnit();
            }
        });

Kotlin+KTX

remoteConfig.fetchAndActivate()
        .addOnCompleteListener(this) { task ->
            if (task.isSuccessful) {
                val updated = task.result
                Log.d(TAG, "Config params updated: $updated")
            } else {
                Log.d(TAG, "Config params failed to update")
            }
            loadAdUnit()
        }

Unity

remoteConfig.FetchAndActivateAsync().ContinueWithOnMainThread(task => {
  if (task.IsFaulted) {
    Debug.LogWarning("Config params failed to update");
  } else {
    Debug.Log("Config params updated: " + task.Result);
  }
  LoadAdUnit();
});

अब आपका ऐप्लिकेशन उस रिमोट कॉन्फ़िगरेशन पैरामीटर को हैंडल करने के लिए तैयार है जिसे आपने इस ट्यूटोरियल में पहले A/B टेस्ट सेट अप के दौरान बनाया था.

रिमोट कॉन्फ़िगरेशन पैरामीटर की वैल्यू का इस्तेमाल करना

loadAdUnit() फ़ंक्शन में पहले से फ़ेच की गई रिमोट कॉन्फ़िगरेशन वैल्यू का इस्तेमाल करके तय करें कि ऐप्लिकेशन इंस्टेंस, इनाम वाली इंटरस्टीशियल विज्ञापन यूनिट की पैरामीटर वैल्यू (true की पैरामीटर वैल्यू) या नहीं दिखाएं (पैरामीटर वैल्यू false).

Swift

private func loadAdUnit() {
  let showNewAdFormat = remoteConfig["users"].boolValue
  if showNewAdFormat {
      // Load Rewarded Interstitial Ad.
      // This should load your new implemented ad unit
      // as per AdMob instructions (the first step of this tutorial).
  } else {
    // Show the existing ad unit.
  }
}

Objective-C

- (void)loadAdUnit {
    BOOL showAds = self.remoteConfig[@"SHOW_NEW_AD_KEY"].boolValue;
    if (showAds) {
      // Load Rewarded Interstitial Ad.
      // This should load your new implemented ad unit
      // per AdMob instructions (the first step of this tutorial).
    } else {
      // Show the existing ad unit.
    }
}

Java

private void loadAdUnit() {
    boolean showNewAdFormat =
      mFirebaseRemoteConfig.getBoolean(SHOW_NEW_AD_KEY);

    if (showNewAdFormat) {
      // Load Rewarded Interstitial Ad.
      // This should load your new implemented ad unit
      // per AdMob instructions (the first step of this tutorial).
    } else {
      // Show the existing ad unit.
    }
}

Kotlin+KTX

private fun loadAdUnit() {
  var showNewAdFormat = remoteConfig.getBoolean(SHOW_NEW_AD_KEY)

  if (showNewAdFormat) {
      // Load Rewarded Interstitial Ad.
      // This should load your new implemented ad unit
      // per AdMob instructions (the first step of this tutorial).
    } else {
      // Show the existing ad unit.
    }
}

Unity

void LoadAdUnit() {
  bool showNewAdFormat =
      remoteConfig.GetValue("SHOW_NEW_AD_KEY").BooleanValue;

  if (showNewAdFormat) {
    // Load Rewarded Interstitial Ad (new implemented ad unit)
    // per AdMob instructions (the first step of this tutorial).
  } else {
    // Show the existing ad unit.
  }
}

पैरामीटर वैल्यू के लिए अन्य जांच जोड़ना

आपके ऐप्लिकेशन कोड में कुछ ऐसी जगहें हैं जहां आपको इस रिमोट कॉन्फ़िगरेशन पैरामीटर की वैल्यू की जांच करके, यह तय करना होगा कि कौनसा विज्ञापन अनुभव लोड किया जाएगा. उदाहरण के लिए, आपके पास यह तय करने का विकल्प है कि उपयोगकर्ता मौजूदा विज्ञापन को देखने के बाद विज्ञापन को फिर से लोड करे या नहीं.

पैरामीटर की वैल्यू में कोई भी बदलाव करने के लिए, फ़ेच और ऐक्टिवेट कॉल सबसे पहले किए जाने चाहिए. उदाहरण के लिए, किसी नए एक्सपेरिमेंट को खत्म करने या नया एक्सपेरिमेंट बनाने के लिए.

वहां से, यहां दिए गए कॉल का इस्तेमाल करके, पैरामीटर की वैल्यू कभी भी देखी जा सकती है:

Swift

remoteConfig["showNewAdKey"].boolValue

Objective-C

self.remoteConfig[@"SHOW_NEW_AD_KEY"].boolValue;

Java

mFirebaseRemoteConfig.getBoolean(SHOW_NEW_AD_KEY)

Kotlin+KTX

remoteConfig.getBoolean(SHOW_NEW_AD_KEY)

Unity

remoteConfig.GetValue("SHOW_NEW_AD_KEY").BooleanValue

इन कॉल से, ऐप्लिकेशन इंस्टेंस के लिए हमेशा एक जैसी वैल्यू मिलेगी. हालांकि, यह इस बात पर निर्भर करेगा कि ऐप्लिकेशन इंस्टेंस को कंट्रोल ग्रुप में रखा गया था या विज्ञापन के नए वैरिएंट ग्रुप में. ऐसा तब तक होगा, जब तक पिछले कॉल में फ़ेच और चालू किए गए Firebase कंसोल में कोई बदलाव नहीं किया गया हो.




दूसरा चरण: Firebase कंसोल में A/B टेस्ट सेट अप करना चौथा चरण: A/B टेस्ट शुरू करना और टेस्ट के नतीजों की समीक्षा करना