ステップ3:アプリのコードでRemoteConfigパラメーター値を処理する
はじめに: Firebaseを使用して新しいAdMob広告フォーマットの採用をテストする |
ステップ1: AdMobを使用して、テスト用の新しい広告ユニットバリアントを作成します |
手順2: FirebaseコンソールでA/Bテストを設定する |
ステップ3:アプリのコードでRemoteConfigパラメーター値を処理する |
ステップ4: A / Bテストを開始し、Firebaseコンソールでテスト結果を確認します |
ステップ5:新しい広告フォーマットを展開するかどうかを決定する |
最後のステップの最後に、Remote Configパラメーター( SHOW_NEW_AD_KEY
)を作成しました。このステップでは、パラメーターの値に基づいてアプリが表示する内容のロジックをアプリのコードに追加します— true
(新しい広告を表示)とfalse
(新しい広告を表示しない)。
必要なSDKを追加します
アプリケーションコードでRemoteConfigを使用する前に、RemoteConfigSDKとFirebaseSDKforGoogleAnalyticsの両方をプロジェクトビルドファイルに追加してください。
迅速
podfileに次のポッドを追加してインストールします。
pod 'Google-Mobile-Ads-SDK'
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'
Objective-C
podfileに次のポッドを追加してインストールします。
pod 'Google-Mobile-Ads-SDK'
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'
Java
次のライブラリの依存関係をbuild.gradle
ファイルに追加します。
implementation 'com.google.android.gms:play-services-ads:21.0.0'
implementation 'com.google.firebase:firebase-analytics:21.0.0'
implementation 'com.google.firebase:firebase-config:21.1.0'
Kotlin+KTX
次のライブラリの依存関係をbuild.gradle
ファイルに追加します。
implementation 'com.google.android.gms:play-services-ads:21.0.0'
implementation 'com.google.firebase:firebase-analytics-ktx:21.0.0'
implementation 'com.google.firebase:firebase-config-ktx:21.1.0'
団結
Firebase Unity SDKをダウンロードしてインストールしてから、次のUnityパッケージをプロジェクトに追加します。
-
FirebaseAnalytics.unitypackage
-
FirebaseRemoteConfig.unitypackage
RemoteConfigインスタンスを構成する
Remote Configパラメーター値を使用するには、Remote Configインスタンスを構成して、クライアントアプリインスタンスの新しい値をフェッチするように設定します。
この例では、RemoteConfigは1時間に1回新しいパラメーター値をチェックするように構成されています。
迅速
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");
}
RemoteConfigをフェッチしてアクティブ化します
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テスト中に作成したRemoteConfigパラメーターをアプリで処理できるようになりました。
RemoteConfigパラメーター値を使用する
loadAdUnit()
関数でプリフェッチされたRemote Config値を使用して、アプリインスタンスに新しいリワードインタースティシャル広告ユニットを表示する( 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.
}
}
パラメータ値の他のチェックを追加します
アプリケーションコードには、このRemote Configパラメータの値をチェックして、ロードされる広告エクスペリエンスを指定する必要がある他の領域があります。たとえば、ユーザーが現在の広告の表示を終了した後に広告をリロードするかどうかを決定できます。
パラメータ値の変更を取得するには、最初にフェッチとアクティブ化の呼び出しを行う必要があります。たとえば、新しい実験を終了または作成する場合などです。
そこから、次の呼び出しを使用して、パラメーターの値をいつでも確認できます。
迅速
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 :FirebaseコンソールでA / Bテストを設定するステップ4 :A / Bテストを開始し、テスト結果を確認する