מדריך: בדיקת ההטמעה של פורמטים חדשים של מודעות ב-AdMob

שלב 3: טיפול בערכי הפרמטר Remote Config בקוד של האפליקציה


מבוא: בדיקה של הטמעה של AdMobפורמט מודעה חדש באמצעות Firebase
שלב 1: משתמשים ב-AdMob כדי ליצור וריאציה חדשה של יחידת מודעות לצורך בדיקה
שלב 2: מגדירים בדיקת A/B במסוף Firebase

שלב 3: טיפול בערכי הפרמטר Remote Config בקוד של האפליקציה

שלב 4: מתחילים את בדיקת ה-A/B ובודקים את תוצאות הבדיקה במסוף Firebase
שלב 5: מחליטים אם להשיק את פורמט המודעה החדש


בסוף השלב הקודם יצרתם פרמטר Remote Config (SHOW_NEW_AD_KEY). בשלב הזה תוסיפו את הלוגיקה לקוד של האפליקציה כדי להגדיר מה האפליקציה צריכה להציג על סמך הערך של הפרמטר הזה – true (הצגת המודעה החדשה) לעומת false (לא להציג את המודעה החדשה).

הוספת ערכות ה-SDK הנדרשות

לפני שמשתמשים ב-Remote Config בקוד האפליקציה, צריך להוסיף את Remote Config SDK ואת Firebase SDK ל-Google Analytics לקובצי ה-build של הפרויקט.

פלטפורמות של אפל

מוסיפים ומתקינים את ה-pods הבאים בקובץ ה-podfile:

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

Android

מוסיפים את יחסי התלות הבאים של הספרייה לקובץ build.gradle:

implementation 'com.google.android.gms:play-services-ads:25.2.0'
implementation 'com.google.firebase:firebase-analytics:23.2.0'
implementation 'com.google.firebase:firebase-config:23.1.0'

Unity

מורידים ומתקינים את Firebase Unity SDK, ואז מוסיפים את חבילות Unity הבאות לפרויקט:

  • FirebaseAnalytics.unitypackage
  • FirebaseRemoteConfig.unitypackage

הגדרת מכונת Remote Config

כדי להשתמש בערכי הפרמטרים Remote Config, צריך להגדיר את המופע Remote Config כך שהוא יוגדר לאחזור ערכים חדשים עבור מופע אפליקציית הלקוח.

בדוגמה הזו, Remote Config מוגדר לבדוק אם יש ערכים חדשים של פרמטרים פעם בשעה.

Swift

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

remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
    minimumFetchIntervalInSeconds = 3600
}
remoteConfig.setConfigSettingsAsync(configSettings)

Unity

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 כדי שהמערכת תדע אם להציג את המודעה באפליקציה.

Swift

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

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

Unity

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

משתמשים בערך Remote Config שאוחזר מראש בפונקציה loadAdUnit() כדי לקבוע אם מופע האפליקציה צריך להציג (ערך הפרמטר הוא true) או לא להציג (ערך הפרמטר הוא false) את היחידה החדשה של מודעות מעברון מתגמלות.

Swift

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

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

Unity

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 כדי לקבוע איזו חוויית צפייה במודעות תיטען. לדוגמה, אתם יכולים להחליט אם לטעון מחדש מודעה אחרי שהמשתמש סיים לצפות במודעה הנוכחית.

קודם צריך לבצע את הקריאות לאחזור ולהפעלה כדי לקבל שינויים בערכי הפרמטרים – לדוגמה, אם מחליטים לסיים ניסוי או ליצור ניסוי חדש.

מכאן, תמיד אפשר לבדוק את הערך של הפרמטר באמצעות הקריאות הבאות:

Swift

remoteConfig["showNewAdKey"].boolValue

Objective-C

self.remoteConfig[@"SHOW_NEW_AD_KEY"].boolValue;

Java

mFirebaseRemoteConfig.getBoolean(SHOW_NEW_AD_KEY)

Kotlin

remoteConfig.getBoolean(SHOW_NEW_AD_KEY)

Unity

remoteConfig.GetValue("SHOW_NEW_AD_KEY").BooleanValue

הקריאות האלה תמיד יחזירו את אותו ערך עבור מופע של אפליקציה, בהתאם למיקום שלה בקבוצת הבקרה או בקבוצת וריאציות המודעות החדשה, אלא אם בוצעו שינויים במסוף Firebase שאוחזרו והופעלו בקריאות הקודמות.




שלב 2: הגדרת בדיקת A/B במסוף Firebase שלב 4: הפעלת בדיקת ה-A/B ובדיקת התוצאות