מודעות מעברון מתגמלות (בטא)

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

דרישות מוקדמות

  • פלאגין Flutter מגרסה 1.1.0 ואילך.
  • מבצעים את הפעולה שנתחיל?. שלך אפליקציית Flutter כבר צריכה לכלול את הפלאגין של Google Mobile Ads Flutter שיובאו.

ביצוע בדיקות באמצעות מודעות בדיקה תמיד

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

הדרך הקלה ביותר לטעון מודעות בדיקה היא להשתמש במזהה הייעודי של יחידת מודעות לבדיקה עבור מודעות מעברון מתגמלות:

  • /21775744923/example/rewarded_interstitial

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

טעינת מודעה

כך נטען מודעת מעברון מתגמלת:

class RewardedInterstitialExampleState extends State<RewardedInterstitialExample> {
  RewardedInterstitialAd? _rewardeInterstitialdAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = '/21775744923/example/rewarded_interstitial';

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedInterstitialAd.loadWithAdManagerAdRequest(
        adUnitId: adUnitId,
        adManagerAdRequest: const AdManagerAdRequest(),
        adLoadCallback: RewardedInterstitialAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _rewardedInterstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('RewardedInterstitialAd failed to load: $error');
          },
        ));
  }
}

אירועים של מודעות מעברון מתגמלות

בעזרת FullScreenContentCallback, אפשר להאזין למחזור החיים אירועים, כמו המועד שבו המודעה מוצגת או נסגרת. סיום RewardedInterstitialAd.fullScreenContentCallback לפני הצגת המודעה בפני לקבל התראות על האירועים האלה. בדוגמה הזו אנחנו מיישמים כל אחת מהשיטות רושם הודעה במסוף:

class RewardedInterstitialExampleState extends State<RewardedInterstitialExample> {
  RewardedInterstitialAd? _rewardedInterstitialAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = '/21775744923/example/rewarded_interstitial';

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedInterstitialAd.loadWithAdManagerAdRequest(
        adUnitId: adUnitId,
        adManagerAdRequest: const AdManagerAdRequest(),
        adLoadCallback: RewardedInterstitialAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
            ad.fullScreenContentCallback = FullScreenContentCallback(
              // Called when the ad showed the full screen content.
              onAdShowedFullScreenContent: (ad) {},
              // Called when an impression occurs on the ad.
              onAdImpression: (ad) {},
              // Called when the ad failed to show full screen content.
              onAdFailedToShowFullScreenContent: (ad, err) {
                // Dispose the ad here to free resources.
                ad.dispose();
              },
              // Called when the ad dismissed full screen content.
              onAdDismissedFullScreenContent: (ad) {
                // Dispose the ad here to free resources.
                ad.dispose();
              },
              // Called when a click is recorded for an ad.
              onAdClicked: (ad) {});

            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _rewardedInterstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugprint('RewardedInterstitialAd failed to load: $error');
          },
        ));
  }
}

מודעה ברשת המדיה

השדה RewardedInterstitialAd מוצג כשכבת-על מעל לכל תוכן האפליקציה וממוקמת באופן סטטי, ולכן לא ניתן להוסיף אותו לעץ הווידג'ט של Flutter. ניתן לבחור מתי להציג את המודעה על ידי התקשרות למספר show(). RewardedInterstitialAd.show() לוקח OnUserEarnedRewardCallback, כלומר מופעלות כשהמשתמש זוכה בפרס. חשוב ליישם את זה ולתגמל את משתמש שצופה במודעה.

_rewardedInterstitialAd.show(onUserEarnedReward: (AdWithoutView ad, RewardItem rewardItem) {
  // Reward the user for watching an ad.
});

לאחר הקריאה אל show(), אי אפשר להסיר Ad שמוצג כך באופן פרוגרמטי ומחייב קלט של משתמשים. RewardedInterstitialAd יכול רק יוצגו פעם אחת. הקריאות הבאות להצגה יפעילו onAdFailedToShowFullScreenContent.

מודעה חייבת להשליך כאשר אין יותר צורך בגישה אליה. השיטה המומלצת מתי להתקשר אל dispose() בטווח FullScreenContentCallback.onAdDismissedFullScreenContent והקבוצה FullScreenContentCallback.onAdFailedToShowFullScreenContent התקשרות חזרה.

זהו! האפליקציה מוכנה עכשיו להצגה של מודעות מעברון מתגמלות.