Step 3: Handle Remote Config parameter values in your app's code
ভূমিকা: Firebase ব্যবহার করে AdMob বিজ্ঞাপন ফ্রিকোয়েন্সি অপ্টিমাইজ করুন |
ধাপ 1: পরীক্ষার জন্য নতুন বিজ্ঞাপন ইউনিট ভেরিয়েন্ট তৈরি করতে AdMob ব্যবহার করুন |
Step 2: Set up an A/B test in the Firebase console |
Step 3: Handle Remote Config parameter values in your app's code |
Step 4: Start the A/B test and review the test results in the Firebase console |
Step 5: Decide whether to roll out the new ad format |
শেষ ধাপের শেষে, আপনি একটি Remote Config প্যারামিটার তৈরি করেছেন ( INTERSTITIAL_AD_KEY
)। এই ধাপে, সেই প্যারামিটারের মানের উপর ভিত্তি করে আপনার অ্যাপটি কী প্রদর্শন করবে তার জন্য আপনি আপনার অ্যাপের কোডে যুক্তি যোগ করবেন।
Add the required SDKs
আপনার অ্যাপ্লিকেশন কোডে Remote Config ব্যবহার করার আগে, আপনার প্রোজেক্ট বিল্ড ফাইলগুলিতে Google Analytics জন্য Remote Config SDK এবং Firebase SDK উভয়ই যোগ করুন।
সুইফট
Add and install the following pods in your podfile:
pod 'Google-Mobile-Ads-SDK'
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'
উদ্দেশ্য-C
Add and install the following pods in your podfile:
pod 'Google-Mobile-Ads-SDK'
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'
অ্যান্ড্রয়েড
Add the following library dependencies to your build.gradle
file:
implementation 'com.google.android.gms:play-services-ads:23.3.0'
implementation 'com.google.firebase:firebase-analytics:22.1.0'
implementation 'com.google.firebase:firebase-config:22.0.0'
ঐক্য
Download and install the Firebase Unity SDK, then add the following Unity packages to your project:
-
FirebaseAnalytics.unitypackage
-
FirebaseRemoteConfig.unitypackage
Configure Remote Config instance
Remote Config প্যারামিটার মানগুলি ব্যবহার করতে, Remote Config ইনস্ট্যান্স কনফিগার করুন যাতে এটি ক্লায়েন্ট অ্যাপের উদাহরণের জন্য নতুন মান আনতে সেট আপ হয়।
In this example, Remote Config is configured to check for new parameter values once every hour.
সুইফট
remoteConfig = RemoteConfig.remoteConfig()
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 3600
remoteConfig.configSettings = settings
উদ্দেশ্য-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)
ঐক্য
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");
}
Fetch and activate Remote Config
Fetch and activate the Remote Config parameters so that it can start using the new parameter values.
You'll want to make this call as early as possible in your app's loading phase because this call is asynchronous and you'll need the Remote Config value pre-fetched so that your app knows which ad to show.
সুইফট
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()
}
উদ্দেশ্য-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()
}
ঐক্য
remoteConfig.FetchAndActivateAsync().ContinueWithOnMainThread(task => {
if (task.IsFaulted) {
Debug.LogWarning("Config params failed to update");
} else {
Debug.Log("Config params updated: " + task.Result);
}
LoadAdUnit();
});
Your app is now ready to handle the Remote Config parameter that you created during the A/B test set up earlier in this tutorial.
Use the Remote Config parameter value
Use the pre-fetched Remote Config value in the loadAdUnit()
function to determine which ad frequency variant should be shown for this app instance.
সুইফট
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.
উদ্দেশ্য-C
- (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;
}];
}
Java
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;
}
});
}
Kotlin+KTX
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);
}
Add other checks for the parameter value
There are other areas in your application code where you'll need to check the value of this Remote Config parameter to dictate which ad experience will be loaded. For example, you can decide whether to reload an ad after the user has finished viewing the current one.
The fetch and activate calls should be made first to get any parameter value changes — for example, if you decide to end or create a new experiment.
From there, you can always check the value for the parameter using the following calls:
সুইফট
remoteConfig["INTERSTITIAL_AD_KEY"].stringValue
উদ্দেশ্য-C
self.remoteConfig[@"INTERSTITIAL_AD_KEY"].stringValue;
Java
mFirebaseRemoteConfig.getString(INTERSTITIAL_AD_KEY)
Kotlin+KTX
remoteConfig.getString(INTERSTITIAL_AD_KEY)
ঐক্য
remoteConfig.GetValue("INTERSTITIAL_AD_KEY").StringValue
These calls will always return the same value for an app instance depending on whether it was placed in the control group or one of the new ad variant groups, unless any changes were made in the Firebase console that were fetched and activated in the previous calls.
Firebase console Step 2 : Set up an A/B test in the Step 4 : Start the A/B test & review test results