บทแนะนำ: ทดสอบการใช้รูปแบบโฆษณา 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 SDK และ Firebase SDK สำหรับ Google Analytics ลงในไฟล์บิลด์โปรเจ็กต์ของคุณ

Swift

เพิ่มและติดตั้งพ็อดต่อไปนี้ใน podfile ของคุณ:

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

วัตถุประสงค์-C

เพิ่มและติดตั้งพ็อดต่อไปนี้ใน podfile ของคุณ:

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

Java

เพิ่มการพึ่งพาไลบรารีต่อไปนี้ในไฟล์ build.gradle ของคุณ:

implementation 'com.google.android.gms:play-services-ads:22.4.0'
implementation 'com.google.firebase:firebase-analytics:21.3.0'
implementation 'com.google.firebase:firebase-config:21.4.1'

Kotlin+KTX

เพิ่มการพึ่งพาไลบรารีต่อไปนี้ในไฟล์ build.gradle ของคุณ:

implementation 'com.google.android.gms:play-services-ads:22.4.0'
implementation 'com.google.firebase:firebase-analytics-ktx:21.3.0'
implementation 'com.google.firebase:firebase-config-ktx:21.4.1'

ความสามัคคี

ดาวน์โหลดและติดตั้ง Firebase Unity SDK จากนั้นเพิ่มแพ็คเกจ Unity ต่อไปนี้ในโปรเจ็กต์ของคุณ:

  • FirebaseAnalytics.unitypackage
  • FirebaseRemoteConfig.unitypackage

กำหนดค่าอินสแตนซ์การกำหนดค่าระยะไกล

หากต้องการใช้ค่าพารามิเตอร์การกำหนดค่าระยะไกล ให้กำหนดค่าอินสแตนซ์การกำหนดค่าระยะไกลเพื่อให้ตั้งค่าให้ดึงค่าใหม่สำหรับอินสแตนซ์แอปไคลเอ็นต์

ในตัวอย่างนี้ การกำหนดค่าระยะไกลได้รับการกำหนดค่าให้ตรวจสอบค่าพารามิเตอร์ใหม่ทุกๆ ชั่วโมง

Swift

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

ดึงข้อมูลและเปิดใช้งานพารามิเตอร์ 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()
}

วัตถุประสงค์-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();
});

แอปของคุณพร้อมที่จะจัดการกับพารามิเตอร์ Remote Config ที่คุณสร้างขึ้นระหว่างการตั้งค่าการทดสอบ A/B ก่อนหน้านี้ในบทช่วยสอนนี้

ใช้ค่าพารามิเตอร์การกำหนดค่าระยะไกล

ใช้ค่าการกำหนดค่าระยะไกลที่ดึงไว้ล่วงหน้าใน 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.
  }
}

วัตถุประสงค์-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.
  }
}

เพิ่มการตรวจสอบอื่น ๆ สำหรับค่าพารามิเตอร์

มีด้านอื่นๆ ในโค้ดแอปพลิเคชันของคุณที่คุณจะต้องตรวจสอบค่าของพารามิเตอร์การกำหนดค่าระยะไกลนี้เพื่อกำหนดประสบการณ์โฆษณาที่จะโหลด ตัวอย่างเช่น คุณสามารถตัดสินใจว่าจะโหลดโฆษณาซ้ำหลังจากที่ผู้ใช้ดูโฆษณาปัจจุบันเสร็จแล้วหรือไม่

ควรทำการเรียกข้อมูลและเปิดใช้งานการเรียกก่อนเพื่อรับการเปลี่ยนแปลงค่าพารามิเตอร์ ตัวอย่างเช่น หากคุณตัดสินใจที่จะสิ้นสุดหรือสร้างการทดสอบใหม่

จากที่นั่น คุณสามารถตรวจสอบค่าของพารามิเตอร์ได้ตลอดเวลาโดยใช้การเรียกต่อไปนี้:

Swift

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 และตรวจทานผลการทดสอบ