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

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



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

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

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

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

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

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

implementation 'com.google.android.gms:play-services-ads:24.0.0'
implementation 'com.google.firebase:firebase-analytics:22.3.0'
implementation 'com.google.firebase:firebase-config:22.1.0'

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

  • FirebaseAnalytics.unitypackage
  • FirebaseRemoteConfig.unitypackage

Remote Config इंस्टेंस कॉन्फ़िगर करना

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

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

remoteConfig = RemoteConfig.remoteConfig()
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 3600
remoteConfig.configSettings = settings
self.remoteConfig = [FIRRemoteConfig remoteConfig];
FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] init];
remoteConfigSettings.minimumFetchInterval = 3600;
self.remoteConfig.configSettings = remoteConfigSettings;
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
        .setMinimumFetchIntervalInSeconds(3600)
        .build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);
remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
    minimumFetchIntervalInSeconds = 3600
}
remoteConfig.setConfigSettingsAsync(configSettings)
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");
}

Remote Config को फ़ेच और चालू करें

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

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

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()
}
[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];
}];
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();
            }
        });
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()
        }
remoteConfig.FetchAndActivateAsync().ContinueWithOnMainThread(task => {
  if (task.IsFaulted) {
    Debug.LogWarning("Config params failed to update");
  } else {
    Debug.Log("Config params updated: " + task.Result);
  }
  LoadAdUnit();
});

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

Remote Config पैरामीटर वैल्यू का इस्तेमाल करना

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

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.
  }
}
- (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.
    }
}
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.
    }
}
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.
    }
}
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.
  }
}

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

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

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

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

remoteConfig["showNewAdKey"].boolValue
self.remoteConfig[@"SHOW_NEW_AD_KEY"].boolValue;
mFirebaseRemoteConfig.getBoolean(SHOW_NEW_AD_KEY)
remoteConfig.getBoolean(SHOW_NEW_AD_KEY)
remoteConfig.GetValue("SHOW_NEW_AD_KEY").BooleanValue

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




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