מדריך: אופטימיזציה של המונטיזציה ההיברידית באמצעות AdMob , Google Analytics ו-Firebase

שלב 3: מגדירים את Firebase Remote Config כך שיציג חוויות ספציפיות של הצגת מודעות


מבוא: אופטימיזציה של מודל מונטיזציה משולב באמצעות AdMob,‏ Google Analytics ו-Firebase
שלב 1: משתמשים ב-AdMob כדי ליצור יחידות של מודעות חדשות להצגה
שלב 2: הגדרת Google Analytics

שלב 3: הגדרת Firebase Remote Config להצגת חוויות ספציפיות של הצגת מודעות


בסוף השלב האחרון למדתם על קהלים ב-Google Analytics. בשלב הזה, יוצרים פרמטר Remote Config מבוקר-בוליאני (שנקרא ad_control_switch) שמשתמש בקהל 'קונים'. לאחר מכן, תצטרכו להוסיף לקוד של האפליקציה את הלוגיקה של מה שהאפליקציה צריכה להציג על סמך הערך של הפרמטר הזה.

הגדרת תנאים ופרמטרים של Remote Config במסוף Firebase

  1. פותחים את פרויקט Firebase במסוף Firebase.

  2. בחלונית הימנית, מרחיבים את הקטע Engage ובוחרים באפשרות Remote Config.

  3. לוחצים על Create configuration (או על Add parameter אם כבר השתמשתם ב-Remote Config).

  4. בחלונית Create parameter, מבצעים את הפעולות הבאות:

    1. בשדה שם הפרמטר, מזינים ad_control_switch.

    2. בתפריט הנפתח Data type, בוחרים באפשרות Boolean.

    3. לוחצים על Create new (יצירת תנאי חדש) ובוחרים באפשרות Create new condition (יצירת תנאי חדש).

  5. בתיבת הדו-שיח Define a new condition (הגדרת תנאי חדש), מבצעים את השלבים הבאים:

    1. בשדה Name, מזינים Purchasers Group (או כל שם אחר שקל לזהות אותו).

    2. בתפריט הנפתח Applies if…, בוחרים באפשרות User audience(s).

    3. בתפריט הנפתח Select audiences, בוחרים באפשרות Purchasers.

    4. לוחצים על שמירת התנאי.

  6. חוזרים לחלונית Create parameter ומבצעים את הפעולות הבאות:

    1. בשדה Value של Purchasers Group, בוחרים באפשרות false.

    2. בשדה ערך ברירת מחדל, בוחרים באפשרות true.

  7. לוחצים על Save (שמירה) ואז על Publish changes (פרסום השינויים).

ההגדרה הזו תבדוק אם המשתמש נכלל בקהל 'קונים' (כלומר, הוא משתמש שמשלם):

  • אם המשתמש נמצא בקהל 'קונים', הפונקציה Remote Config תחזיר את הערך של false לפרמטר ad_control_switch.

  • אם המשתמש לא נכלל בקהל 'קונים', הפונקציה Remote Config תחזיר את הערך של true לפרמטר ad_control_switch.

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

הוספת ה-SDK של Remote Config לאפליקציה

לפני שמשתמשים ב-Remote Config בקוד האפליקציה, צריך להוסיף את ה-SDK של Remote Config לקוד הבסיסי של האפליקציה. חשוב לזכור שכבר אמורים להיות באפליקציה ה-SDK של Google Mobile Ads‏ (AdMob) ו-Google Analytics for Firebase SDK מהשלבים הקודמים במדריך הזה.

Swift

מוסיפים את ה-pod של Remote Config ומתקינים אותו ב-Podfile:

pod 'Firebase/RemoteConfig'

Android

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

implementation 'com.google.firebase:firebase-config:22.0.1'

Flutter

מהשורש של פרויקט Flutter, מריצים את הפקודה הבאה כדי להתקין את הפלאגין Remote Config:

flutter pub add firebase_remote_config

Unity

מורידים ומתקינים את Firebase Unity SDK העדכני ביותר, ואז מוסיפים את החבילה Remote Config לפרויקט:
FirebaseRemoteConfig.unitypackage

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

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

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

Swift

remoteConfig = RemoteConfig.remoteConfig()
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 3600
remoteConfig.configSettings = settings

Kotlin

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

Java

mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
        .setMinimumFetchIntervalInSeconds(3600)
        .build();
mFirebaseRemoteConfig.setConfigSettingsAsync(configSettings);

Flutter

remoteConfig = FirebaseRemoteConfig.instance;
  final configSettings = FirebaseRemoteConfigSettings(
    minimumFetchInterval: Duration(hours: 1),
  );
  await remoteConfig.setConfigSettings(configSettings);

  // Use the `onConfigUpdated` callback to listen for changes to the config settings.
  remoteConfig.onConfigUpdated.listen((_) {
    print('Config settings confirmed');
  });

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

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

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

Flutter

remoteConfig = FirebaseRemoteConfig.instance;

// Fetch and activate the latest Remote Config values.
final updated = await remoteConfig.fetchAndActivate();

// Check if the config params were updated successfully.
if (updated) {
  print('Config params updated');
} else {
  print('Config params failed to update');
}

// Load the ad unit.
_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 שיצרתם מוקדם יותר בשלב הזה.

שימוש בערך הפרמטר Remote Config

משתמשים בערך Remote Config שאוחזר מראש בפונקציה loadAdUnit() כדי לקבוע אם מופע האפליקציה צריך לבצע אחת מהפעולות הבאות:

  • ערך הפרמטר ad_control_switch מומר לערך true: הצגת המודעה המעברון (כי המשתמש הוא משתמש שלא משלם).

  • ערך הפרמטר ad_control_switch מומר לערך false: אין להציג את המודעה (כי המשתמש הוא משתמש שמשלם).

Swift

private func loadAdUnit() {
  let showAds = remoteConfig["ad_control_switch"].boolValue

  if showAds {
    // Load interstitial ad (implemented ad unit)
    // per AdMob instructions (the first step of this tutorial).
  } else {
    // Don't show ads.
  }
}

Kotlin

private fun loadAdUnit() {
  var showAds = remoteConfig.getBoolean(ad_control_switch)

  if (showAds) {
      // Load interstitial ad (implemented ad unit)
      // per AdMob instructions (the first step of this tutorial).
    } else {
      // Don't show ads.
    }
}

Java

private void loadAdUnit() {
    boolean showAds =
      mFirebaseRemoteConfig.getBoolean(ad_control_switch);

    if (showAds) {
      // Load interstitial ad (implemented ad unit)
      // per AdMob instructions (the first step of this tutorial).
    } else {
      // Don't show ads.
    }
}

Flutter

void _loadAdUnit() {
  bool showAds = remoteConfig.getBool(ad_control_switch);

  if (showAds) {
    // Load interstitial ad (implemented ad unit)
    // per AdMob instructions (the first step of this tutorial).
  } else {
    // Don't show ads.
  }
}

Unity

void LoadAdUnit() {
  bool showAds =
      remoteConfig.GetValue("ad_control_switch").BooleanValue;

  if (showAds) {
    // Load interstitial ad (implemented ad unit)
    // per AdMob instructions (the first step of this tutorial).
  } else {
    // Don't show ads.
  }
}

השקת האפליקציה

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

אם פעלתם לפי השלבים במדריך הזה, האפליקציה שלכם אמורה להתחיל להציג למשתמשים מודעות בהתאמה אישית באפליקציה באופן מיידי. אתם יכולים לעקוב אחרי ההכנסות ממודעות גם בחשבון AdMob וגם במרכזי הבקרה של Google Analytics (במסוף Firebase או בממשק המשתמש של Google Analytics).


זהו, סיימתם. סיימתם את המדריך לאופטימיזציה של מונטיזציה היברידית באמצעות AdMob,‏ Google Analytics ו-Firebase.




שלב 2: הגדרת Google Analytics