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

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


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

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

चरण 4: ए/बी परीक्षण शुरू करें और फायरबेस कंसोल में परीक्षण परिणामों की समीक्षा करें
चरण 5: तय करें कि नया विज्ञापन प्रारूप लागू करना है या नहीं


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

आवश्यक SDK जोड़ें

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

एप्पल प्लेटफार्म

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

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

एंड्रॉयड

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

implementation 'com.google.android.gms:play-services-ads:23.0.0'
implementation 'com.google.firebase:firebase-analytics:21.6.1'
implementation 'com.google.firebase:firebase-config:21.6.3'

एकता

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

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

आपका ऐप अब रिमोट कॉन्फिग पैरामीटर को संभालने के लिए तैयार है जिसे आपने इस ट्यूटोरियल में पहले सेट किए गए ए/बी टेस्ट के दौरान बनाया था।

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

यह निर्धारित करने के लिए कि ऐप इंस्टेंस को नई पुरस्कृत इंटरस्टिशियल विज्ञापन इकाई दिखानी चाहिए ( 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.
  }
}

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

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

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

वहां से, आप निम्नलिखित कॉल का उपयोग करके हमेशा पैरामीटर के लिए मान की जांच कर सकते हैं:

तीव्र

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

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




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