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

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

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

  • פלאגין Flutter מגרסה 1.1.0 ואילך.
  • מבצעים את הפעולה שנתחיל?. הפלאגין של Google Mobile Ads ל-Flutter כבר אמור להיות מיובא לאפליקציה שלכם ב-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 התקשרות חזרה.

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