तीसरा चरण: अपने ऐप्लिकेशन के कोड में Remote Config पैरामीटर वैल्यू को मैनेज करना
परिचय: Firebase का इस्तेमाल करके, AdMob विज्ञापन फ़्रीक्वेंसी को ऑप्टिमाइज़ करें |
पहला चरण: टेस्टिंग के लिए, विज्ञापन यूनिट के नए वैरिएंट बनाने के लिए AdMob का इस्तेमाल करना |
दूसरा चरण: Firebase कंसोल में A/B टेस्ट सेट अप करना |
तीसरा चरण: अपने ऐप्लिकेशन के कोड में Remote Config पैरामीटर वैल्यू को मैनेज करना |
चौथा चरण: A/B टेस्ट शुरू करें और Firebase कंसोल में टेस्ट के नतीजों की समीक्षा करें |
पांचवां चरण: यह तय करना कि नया विज्ञापन फ़ॉर्मैट रोल आउट करना है या नहीं |
पिछले चरण के आखिर में, आपने Remote Config पैरामीटर (INTERSTITIAL_AD_KEY
) बनाया था. इस चरण में, आपको अपने ऐप्लिकेशन के कोड में लॉजिक जोड़ना होगा, ताकि उस पैरामीटर की वैल्यू के आधार पर आपके ऐप्लिकेशन में क्या दिखे.
ज़रूरी SDK टूल जोड़ना
अपने ऐप्लिकेशन कोड में Remote Config का इस्तेमाल करने से पहले, अपनी प्रोजेक्ट बिल्ड फ़ाइलों में Remote Config SDK टूल और Google Analytics के लिए Firebase SDK टूल, दोनों को जोड़ें.
अपनी Podfile में ये पॉड जोड़ें और इंस्टॉल करें:
pod 'Google-Mobile-Ads-SDK'
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'
अपनी 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 वैल्यू का इस्तेमाल करके, यह तय करें कि इस ऐप्लिकेशन इंस्टेंस के लिए, विज्ञापन की फ़्रीक्वेंसी का कौनसा वैरिएंट दिखाया जाना चाहिए.
private func loadAdUnit() {
let adUnitId = remoteConfig["INTERSTITIAL_AD_KEY"].stringValue;
let request = GADRequest()
GADInterstitialAd.load(withAdUnitID: adUnitId,
request: request,
completionHandler: { [self] ad, error in
if let error = error {
print("Failed to load: \(error.localizedDescription)")
return
}
interstitial = ad
// Register for callbacks.
}
)
}
// Register for callbacks.
- (void)loadAdUnit {
NSString *adUnitId =
self.remoteConfig[@"INTERSTITIAL_AD_KEY"].stringValue;
GADRequest *request = [GADRequest request];
[GADInterstitialAd loadAdWithAdUnitId:adUnitId
request:request
completionHandler:^(GADInterstitialAd *ad,
NSError *error) {
if (error) {
NSLog(@"Failed to load interstitial ad with error: %@",
[error localizedDescription]);
return;
}
self.interstitial = ad;
}];
}
private void loadAdUnit() {
String adUnitId =
mFirebaseRemoteConfig.getString("INTERSTITIAL_AD_KEY");
// Load Interstitial Ad (assume adUnitId not null)
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(this, adUnitId, adRequest, new
InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd intertitialAd) {
mInterstitialAd = interstitialAd;
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
mInterstitialAd = null;
}
});
}
private fun loadAdUnit() {
String adUnitId = remoteConfig.getString("INTERSTITIAL_AD_KEY")
var adRequest = AdRequestBuilder.Builder().build()
AdRequestBuilder.load(this, adUnitId, adRequest, object :
InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
mInterstitialAd = null
}
override fun onAdLoaded(interstitialAd: InterstitialAd) {
mInterstitialAd = interstitialAd
}
})
}
void LoadAdUnit() {
// Note that you may want to encode and parse two sets of ad unit IDs for
// Android / iOS in the Unity implementation.
String adUnitId = remoteConfig.GetValue("INTERSTITIAL_AD_KEY").StringValue;
this.interstitial = new InterstitialAd(adUnitId);
}
पैरामीटर वैल्यू के लिए अन्य जांच जोड़ना
आपके ऐप्लिकेशन कोड में ऐसे अन्य हिस्से भी हैं जहां आपको यह तय करने के लिए, इस Remote Config पैरामीटर की वैल्यू की जांच करनी होगी कि कौनसा विज्ञापन अनुभव लोड किया जाएगा. उदाहरण के लिए, आपके पास यह तय करने का विकल्प होता है कि उपयोगकर्ता मौजूदा विज्ञापन देखना बंद करने के बाद, विज्ञापन को फिर से लोड करना है या नहीं.
पैरामीटर की वैल्यू में हुए किसी भी बदलाव को पाने के लिए, फ़ेच और चालू करने के कॉल पहले किए जाने चाहिए. उदाहरण के लिए, अगर आपको कोई नया एक्सपेरिमेंट खत्म करना है या बनाना है.
वहां से, इन कॉल का इस्तेमाल करके पैरामीटर की वैल्यू कभी भी देखी जा सकती है:
remoteConfig["INTERSTITIAL_AD_KEY"].stringValue
self.remoteConfig[@"INTERSTITIAL_AD_KEY"].stringValue;
mFirebaseRemoteConfig.getString(INTERSTITIAL_AD_KEY)
remoteConfig.getString(INTERSTITIAL_AD_KEY)
remoteConfig.GetValue("INTERSTITIAL_AD_KEY").StringValue
ये कॉल, किसी ऐप्लिकेशन इंस्टेंस के लिए हमेशा एक ही वैल्यू दिखाएंगे. यह इस बात पर निर्भर करता है कि उसे कंट्रोल ग्रुप में रखा गया था या विज्ञापन के नए वैरिएंट ग्रुप में से किसी एक में. ऐसा तब तक होगा, जब तक Firebase कंसोल में कोई ऐसा बदलाव नहीं किया जाता जिसे पिछले कॉल में फ़ेच और चालू किया गया था.
Firebase कंसोल में A/B टेस्ट सेट अप करना दूसरा चरण: चौथा चरण: A/B टेस्ट शुरू करना और टेस्ट के नतीजों की समीक्षा करना