ขั้นตอนที่ 3: จัดการค่าพารามิเตอร์การกำหนดค่าระยะไกลในโค้ดของแอป
บทนำ: ทดสอบการใช้รูปแบบโฆษณา AdMob ใหม่โดยใช้ Firebase |
ขั้นตอนที่ 1: ใช้ AdMob เพื่อสร้างหน่วยโฆษณารูปแบบใหม่สำหรับการทดสอบ |
ขั้นตอนที่ 2: ตั้งค่าการทดสอบ A/B ในคอนโซล Firebase |
ขั้นตอนที่ 3: จัดการค่าพารามิเตอร์การกำหนดค่าระยะไกลในโค้ดของแอป |
ขั้นตอนที่ 4: เริ่มการทดสอบ A/B และตรวจสอบผลการทดสอบในคอนโซล Firebase |
ขั้นตอนที่ 5: ตัดสินใจว่าจะเปิดตัวรูปแบบโฆษณาใหม่หรือไม่ |
ในตอนท้ายของขั้นตอนสุดท้าย คุณได้สร้างพารามิเตอร์ Remote Config ( SHOW_NEW_AD_KEY
) ในขั้นตอนนี้ คุณจะเพิ่มตรรกะลงในโค้ดของแอปสำหรับสิ่งที่แอปของคุณควรแสดงตามค่าของพารามิเตอร์นั้น ได้แก่ true
(แสดงโฆษณาใหม่) กับ false
( ไม่ แสดงโฆษณาใหม่)
เพิ่ม SDK ที่จำเป็น
ก่อนที่จะใช้การกำหนดค่าระยะไกลในโค้ดแอปพลิเคชันของคุณ ให้เพิ่มทั้ง Remote Config SDK และ Firebase SDK สำหรับ Google Analytics ลงในไฟล์บิลด์โปรเจ็กต์ของคุณ
แพลตฟอร์มของ Apple
เพิ่มและติดตั้งพ็อดต่อไปนี้ใน podfile ของคุณ:
pod 'Google-Mobile-Ads-SDK'
pod 'Firebase/Analytics'
pod 'Firebase/RemoteConfig'
หุ่นยนต์
เพิ่มการพึ่งพาไลบรารีต่อไปนี้ให้กับไฟล์ build.gradle
ของคุณ:
implementation 'com.google.android.gms:play-services-ads:22.5.0'
implementation 'com.google.firebase:firebase-analytics:21.5.0'
implementation 'com.google.firebase:firebase-config:21.6.0'
ความสามัคคี
ดาวน์โหลดและติดตั้ง Firebase Unity SDK จากนั้นเพิ่มแพ็คเกจ Unity ต่อไปนี้ในโปรเจ็กต์ของคุณ:
-
FirebaseAnalytics.unitypackage
-
FirebaseRemoteConfig.unitypackage
กำหนดค่าอินสแตนซ์การกำหนดค่าระยะไกล
หากต้องการใช้ค่าพารามิเตอร์การกำหนดค่าระยะไกล ให้กำหนดค่าอินสแตนซ์การกำหนดค่าระยะไกลเพื่อตั้งค่าให้ดึงค่าใหม่สำหรับอินสแตนซ์แอปไคลเอนต์
ในตัวอย่างนี้ การกำหนดค่าระยะไกลได้รับการกำหนดค่าให้ตรวจสอบค่าพารามิเตอร์ใหม่ทุกๆ ชั่วโมง
สวิฟท์
remoteConfig = RemoteConfig.remoteConfig()
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 3600
remoteConfig.configSettings = settings
วัตถุประสงค์-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 เพื่อให้สามารถเริ่มใช้ค่าพารามิเตอร์ใหม่ได้
คุณจะต้องทำการเรียกนี้ให้เร็วที่สุดเท่าที่จะเป็นไปได้ในช่วงการโหลดของแอปเนื่องจากการเรียกนี้ไม่พร้อมกัน และคุณจะต้องดึงค่าการกำหนดค่าระยะไกลล่วงหน้าเพื่อให้แอปรู้ว่าจะแสดงโฆษณาหรือไม่
สวิฟท์
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()
}
วัตถุประสงค์-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 ที่ตั้งค่าไว้ก่อนหน้าในบทแนะนำนี้แล้ว
ใช้ค่าพารามิเตอร์ 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.
}
}
วัตถุประสงค์-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
วัตถุประสงค์-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 และตรวจสอบผลการทดสอบ