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

בחירת פלטפורמה: Android iOS Unity Flutter

מודעת מעברון מתגמלת היא סוג של פורמט מודעה מתגמלת שמאפשר לכם להציע תגמולים בתמורה לצפייה במודעות שמופיעות באופן אוטומטי בנקודות מעבר טבעיות באפליקציה. בשונה ממודעות מתגמלות, המשתמשים לא צריכים להביע הסכמה לצפייה במודעת מעברון מתגמלת. במדריך הזה מוסבר איך לשלב מודעות מעברון מתגמלות מ-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 של החזרת ערכים.

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