チュートリアル: AdMob、Google アナリティクス、Firebase を使用してハイブリッド収益化を最適化する

ステップ 3: 特定の広告エクスペリエンスを表示するように Firebase Remote Config を設定する


概要: AdMob、Google アナリティクス、Firebase を使用してハイブリッド収益化を最適化する
ステップ 1: AdMob を使用して表示用の新しい広告ユニットを作成する
ステップ 2: Google アナリティクスを設定する

ステップ 3:特定の広告エクスペリエンスを表示するように Firebase Remote Config を設定する


最後のステップの終わりに、Google アナリティクスのオーディエンスについて学びました。この手順では、「購入者」オーディエンスを利用する Remote Config のブール制御パラメータ ( ad_control_switchと呼ばれます) を作成します。次に、そのパラメーターの値に基づいてアプリが表示する内容のロジックをアプリのコードに追加します。

Firebase コンソールで Remote Config のパラメータと条件を設定する

  1. Firebase コンソールで、Firebase プロジェクトを開きます。

  2. 左側のペインで、 「Engage」セクションを展開し、 「Remote Config」を選択します。

  3. [構成の作成]をクリックします (または、以前に Remote Config を使用したことがある場合は、パラメーターの追加) をクリックします。

  4. [パラメータの作成]パネルで、次の手順を実行します。

    1. 「パラメータ名」フィールドにad_control_switchと入力します。

    2. Data typeドロップダウン メニューから、 [ブール]を選択します。

    3. [新規作成]をクリックし、 [新しい条件の作成]を選択します。

  5. [新しい条件の定義]ダイアログで、次の手順を実行します。

    1. 「名前」フィールドに、 Purchasers Group 」(またはその他の簡単に識別できる条件の名前) を入力します。

    2. [適用条件]ドロップダウン メニューから、 [ユーザー対象]を選択します。

    3. [対象ユーザーの選択]ドロップダウン メニューから、 [購入者]を選択します。

    4. [条件を保存]をクリックします。

  6. [パラメータの作成]パネルに戻り、次の手順を実行します。

    1. [購入者グループ値]として、 [false]を選択します。

    2. デフォルト値としてtrueを選択します。

  7. 「保存」をクリックし、 「変更を公開」をクリックします。

この構成は、ユーザーが「購入者」対象ユーザー (つまり、有料ユーザー) に属しているかどうかを確認します。

  • ユーザーが「購入者」オーディエンスに属している場合、Remote Config はad_control_switchパラメータの値としてfalseを返します。

  • ユーザーが「購入者」オーディエンスに属していない場合、Remote Config はad_control_switchパラメータにtrueの値を返します。

次の手順では、アプリに Remote Config を実装して、これらのパラメーター値を処理します。

Remote Config SDK をアプリに追加する

アプリケーション コードで Remote Config を使用する前に、Remote Config SDK をアプリのコードベースに追加します。アプリには、このチュートリアルの前の手順で作成した Google Mobile Ads (AdMob) SDK と Firebase 向け Google アナリティクス SDK がすでに含まれている必要があることに注意してください。

迅速

Remote Config ポッドをポッドファイルに追加してインストールします。

pod 'Firebase/RemoteConfig'

アンドロイド

Remote Config ライブラリの依存関係をbuild.gradleファイルに追加します。

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

フラッター

Flutter プロジェクトのルートから次のコマンドを実行して、Remote Config プラグインをインストールします。

flutter pub add firebase_remote_config

団結

最新のFirebase Unity SDKをダウンロードしてインストールし、Remote Config パッケージをプロジェクトに追加します。
FirebaseRemoteConfig.unitypackage

Remote Config インスタンスを構成する

アプリで Remote Config パラメーター値を使用できるように、クライアント アプリ インスタンスの新しい値をフェッチできるように Remote Config インスタンスを構成します。

この例では、Remote Config は 1 時間ごとに新しいパラメータ値をチェックするように構成されています。

迅速

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

Kotlin+KTX

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

フラッター

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

団結

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

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

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

フラッター

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

団結

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 パラメータ値を使用する

loadAdUnit()関数でプリフェッチされた Remote Config 値を使用して、アプリ インスタンスが次のいずれかを実行する必要があるかどうかを決定します。

  • ad_control_switchパラメータ値はtrueに解決されます。インタースティシャル広告を表示します (ユーザーが無料ユーザーであるため)。

  • ad_control_switchパラメータ値はfalseに解決されます。つまり、広告は表示されません (ユーザーは有料ユーザーであるため)。

迅速

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+KTX

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

フラッター

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

団結

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 アナリティクス ダッシュボード (Firebase コンソールまたは Google アナリティクス UI) の両方でモニタリングできます。


以上です! AdMob、Google アナリティクス、Firebase を使用してハイブリッド収益化を最適化するためのチュートリアルは完了です。




ステップ 2: Google Analytics を設定する