ट्यूटोरियल: नए AdMob विज्ञापन प्रारूपों को अपनाने का परीक्षण करें

चरण 3: अपने ऐप के कोड में रिमोट कॉन्फिग पैरामीटर मानों को संभालें


परिचय: Firebase का उपयोग करके नए AdMob विज्ञापन प्रारूप अपनाने का परीक्षण करें
चरण 1: परीक्षण के लिए एक नया विज्ञापन इकाई संस्करण बनाने के लिए AdMob का उपयोग करें
चरण 2: Firebase कंसोल में A/B परीक्षण सेट करें

चरण 3: अपने ऐप के कोड में रिमोट कॉन्फिग पैरामीटर मानों को संभालें

चरण 4: A/B परीक्षण प्रारंभ करें और Firebase कंसोल में परीक्षण परिणामों की समीक्षा करें
चरण 5: तय करें कि नया विज्ञापन प्रारूप तैयार करना है या नहीं


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

आवश्यक एसडीके जोड़ें

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

तीव्र

अपने पॉडफाइल में निम्नलिखित पॉड्स जोड़ें और स्थापित करें:

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

उद्देश्य सी

अपने पॉडफाइल में निम्नलिखित पॉड्स जोड़ें और स्थापित करें:

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

Java

अपनी build.gradle फ़ाइल में निम्न लाइब्रेरी निर्भरताएँ जोड़ें:

implementation 'com.google.android.gms:play-services-ads:22.4.0'
implementation 'com.google.firebase:firebase-analytics:21.3.0'
implementation 'com.google.firebase:firebase-config:21.4.1'

Kotlin+KTX

अपनी build.gradle फ़ाइल में निम्न लाइब्रेरी निर्भरताएँ जोड़ें:

implementation 'com.google.android.gms:play-services-ads:22.4.0'
implementation 'com.google.firebase:firebase-analytics-ktx:21.3.0'
implementation 'com.google.firebase:firebase-config-ktx:21.4.1'

एकता

फायरबेस यूनिटी एसडीके डाउनलोड और इंस्टॉल करें, फिर अपने प्रोजेक्ट में निम्नलिखित यूनिटी पैकेज जोड़ें:

  • FirebaseAnalytics.unitypackage
  • FirebaseRemoteConfig.unitypackage

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

रिमोट कॉन्फिग पैरामीटर मानों का उपयोग करने के लिए, रिमोट कॉन्फिग इंस्टेंस को कॉन्फ़िगर करें ताकि इसे क्लाइंट ऐप इंस्टेंस के लिए नए मान लाने के लिए सेट किया जा सके।

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

तीव्र

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;

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)

एकता

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");
}

रिमोट कॉन्फिग लायें और सक्रिय करें

रिमोट कॉन्फ़िगरेशन पैरामीटर प्राप्त करें और सक्रिय करें ताकि यह नए पैरामीटर मानों का उपयोग शुरू कर सके।

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

तीव्र

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];
}];

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

एकता

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 परीक्षण के दौरान बनाए गए Remote Config पैरामीटर को संभालने के लिए तैयार है।

रिमोट कॉन्फ़िगरेशन पैरामीटर मान का उपयोग करें

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

तीव्र

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

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

एकता

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;

Java

mFirebaseRemoteConfig.getBoolean(SHOW_NEW_AD_KEY)

Kotlin+KTX

remoteConfig.getBoolean(SHOW_NEW_AD_KEY)

एकता

remoteConfig.GetValue("SHOW_NEW_AD_KEY").BooleanValue

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




चरण 2 : फायरबेस कंसोल में ए/बी परीक्षण सेट अप करें चरण 4 : ए/बी परीक्षण प्रारंभ करें और परीक्षण परिणामों की समीक्षा करें