שלב 3: טפל בערכי פרמטר Config מרחוק בקוד האפליקציה שלך
מבוא: בדוק אימוץ פורמט מודעות חדש של AdMob באמצעות Firebase |
שלב 1: השתמש ב-AdMob כדי ליצור גרסה חדשה של יחידת מודעות לבדיקה |
שלב 2: הגדר בדיקת A/B במסוף Firebase |
שלב 3: טפל בערכי פרמטר Config מרחוק בקוד האפליקציה שלך |
שלב 4: התחל את בדיקת A/B ובדוק את תוצאות הבדיקה במסוף Firebase |
שלב 5: החלט אם להפעיל את פורמט המודעה החדש |
בסוף השלב האחרון, יצרת פרמטר Config מרחוק ( SHOW_NEW_AD_KEY
). בשלב זה, תוסיף את ההיגיון לקוד האפליקציה שלך עבור מה שהאפליקציה שלך אמורה להציג בהתבסס על הערך של פרמטר זה - true
(הצג את המודעה החדשה) לעומת false
( אל תציג את המודעה החדשה).
הוסף את ערכות ה-SDK הנדרשות
לפני השימוש ב-Remote Config בקוד היישום שלך, הוסף גם את Remote Config SDK וגם את Firebase SDK עבור Google Analytics לקובצי בניית הפרויקט שלך.
פלטפורמות של אפל
הוסף והתקן את הפודים הבאים ב-podfile שלך:
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'
אַחְדוּת
הורד והתקן את Firebase Unity SDK, ולאחר מכן הוסף את חבילות Unity הבאות לפרויקט שלך:
-
FirebaseAnalytics.unitypackage
-
FirebaseRemoteConfig.unitypackage
הגדר מופע תצורה מרחוק
כדי להשתמש בערכי הפרמטרים של Remote Config, הגדר את מופע Config Remote כך שהוא מוגדר להביא ערכים חדשים עבור מופע אפליקציית הלקוח.
בדוגמה זו, Config Remote מוגדר לבדוק ערכי פרמטרים חדשים אחת לשעה.
מָהִיר
remoteConfig = RemoteConfig.remoteConfig()
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 3600
remoteConfig.configSettings = settings
Objective-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");
}
אחזר והפעל 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()
}
Objective-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();
});
האפליקציה שלך מוכנה כעת לטפל בפרמטר התצורה המרוחקת שיצרת במהלך בדיקת A/B שהוגדרה קודם לכן במדריך זה.
השתמש בערך של פרמטר Config Remote
השתמש בערך ה-Remote Config שאוחזר מראש בפונקציה loadAdUnit()
כדי לקבוע אם מופע האפליקציה צריך להציג (ערך פרמטר של 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.
}
}
Objective-C
- (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
Objective-C
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 : הגדר בדיקת A/B במסוף Firebaseשלב 4 : התחל את בדיקת A/B ובדוק את תוצאות הבדיקה