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

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

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

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

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

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

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

Android

ca-app-pub-3940256099942544/5354046379

iOS

ca-app-pub-3940256099942544/6978759866

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

טעינת מודעה

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

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

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = Platform.isAndroid
    ? 'ca-app-pub-3940256099942544/5354046379'
    : 'ca-app-pub-3940256099942544/6978759866';

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedInterstitialAd.load(
        adUnitId: adUnitId,
        adRequest: const AdRequest(),
        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 לפני הצגת המודעה בפני לקבל התראות על האירועים האלה. בדוגמה הזו מוטמע כל method ומופיעה הודעה ביומן במסוף:

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

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = Platform.isAndroid
    ? 'ca-app-pub-3940256099942544/5354046379'
    : 'ca-app-pub-3940256099942544/6978759866';

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedInterstitialAd.load(
        adUnitId: adUnitId,
        adRequest: const AdRequest(),
        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 התקשרות חזרה.

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

הקישור המלא ב-GitHub

מודעת מעברון מתגמלת