پاداش داده شد

پلتفرم مورد نظر را انتخاب کنید: اندروید (بتا)جدید اندروید، iOS، یونیتی ، فلاتر

تبلیغات جایزه‌دار، تبلیغاتی هستند که کاربران می‌توانند در ازای دریافت جوایز درون‌برنامه‌ای با آنها تعامل داشته باشند. این راهنما نحوه ادغام تبلیغات جایزه‌دار از Ad Manager را در یک برنامه Flutter نشان می‌دهد.

همیشه با تبلیغات آزمایشی تست کنید

هنگام ساخت و آزمایش برنامه‌های خود، مطمئن شوید که از تبلیغات آزمایشی به جای تبلیغات زنده و تولیدی استفاده می‌کنید. عدم انجام این کار می‌تواند منجر به مسدود شدن حساب شما شود.

ساده‌ترین راه برای بارگذاری تبلیغات آزمایشی، استفاده از شناسه واحد تبلیغات آزمایشی اختصاصی ما برای تبلیغات جایزه‌دار است:

  • /21775744923/example/rewarded

واحدهای تبلیغاتی آزمایشی طوری پیکربندی شده‌اند که برای هر درخواست، تبلیغات آزمایشی را برگردانند و شما می‌توانید هنگام کدنویسی، آزمایش و اشکال‌زدایی از آنها در برنامه‌های خود استفاده کنید. فقط قبل از انتشار برنامه، مطمئن شوید که آنها را با شناسه‌های واحدهای تبلیغاتی خود جایگزین می‌کنید.

بارگذاری یک تبلیغ

مثال زیر یک تبلیغ جایزه‌دار را بارگذاری می‌کند:

RewardedAd.load(
  adUnitId: "_adUnitId",
  request: const AdManagerAdRequest(),
  rewardedAdLoadCallback: RewardedAdLoadCallback(
    onAdLoaded: (RewardedAd ad) {
      // Called when an ad is successfully received.
      debugPrint('Ad was loaded.');
      // Keep a reference to the ad so you can show it later.
      _rewardedAd = ad;
    },
    onAdFailedToLoad: (LoadAdError error) {
      // Called when an ad request failed.
      debugPrint('Ad failed to load with error: $error');
    },
  ),
);

به جای _adUnitId ، شناسه واحد تبلیغاتی خودتان را قرار دهید.

رویدادهای تبلیغات جایزه‌دار

Through the use of FullScreenContentCallback , you can listen for lifecycle events, such as when the ad is shown or dismissed. Set RewardedAd.fullScreenContentCallback before showing the ad to receive notifications for these events. This example implements each method and logs a message to the console:

ad.fullScreenContentCallback = FullScreenContentCallback(
  onAdShowedFullScreenContent: (ad) {
    // Called when the ad showed the full screen content.
    debugPrint('Ad showed full screen content.');
  },
  onAdFailedToShowFullScreenContent: (ad, err) {
    // Called when the ad failed to show full screen content.
    debugPrint('Ad failed to show full screen content with error: $err');
    // Dispose the ad here to free resources.
    ad.dispose();
  },
  onAdDismissedFullScreenContent: (ad) {
    // Called when the ad dismissed full screen content.
    debugPrint('Ad was dismissed.');
    // Dispose the ad here to free resources.
    ad.dispose();
  },
  onAdImpression: (ad) {
    // Called when an impression occurs on the ad.
    debugPrint('Ad recorded an impression.');
  },
  onAdClicked: (ad) {
    // Called when a click is recorded for an ad.
    debugPrint('Ad was clicked.');
  },
);

نمایش آگهی

A RewardedAd is displayed as an Overlay on top of all app content and is statically placed; thus, it can't be added to the Flutter widget tree. You can choose when to show the ad by calling show() . RewardedAd.show() takes an OnUserEarnedRewardCallback , which is invoked when the user earns a reward. Be sure to implement this and reward the user for watching an ad.

_rewardedAd?.show(
  onUserEarnedReward:
      (AdWithoutView ad, RewardItem rewardItem) {
        debugPrint(
          'Reward amount: ${rewardItem.amount}',
        );
      },
);

Once show() is called, an Ad displayed this way can't be removed programmatically and requires user input. A RewardedAd can only be shown once. Subsequent calls to show will trigger onAdFailedToShowFullScreenContent .

زمانی که دیگر نیازی به دسترسی به یک تبلیغ نباشد، باید آن را دور انداخت. بهترین روش برای زمان فراخوانی dispose() در فراخوانی‌های FullScreenContentCallback.onAdDismissedFullScreenContent و FullScreenContentCallback.onAdFailedToShowFullScreenContent است.

[اختیاری] اعتبارسنجی کال‌بک‌های تأیید سمت سرور (SSV)

برنامه‌هایی که در فراخوانی‌های تأیید سمت سرور به داده‌های اضافی نیاز دارند، باید از ویژگی داده‌های سفارشی تبلیغات پاداشی استفاده کنند. هر مقدار رشته‌ای که روی یک شیء تبلیغ پاداشی تنظیم شود، به پارامتر پرس‌وجوی custom_data از فراخوانی SSV ارسال می‌شود. اگر هیچ مقدار داده سفارشی تنظیم نشود، مقدار پارامتر پرس‌وجوی custom_data در فراخوانی SSV وجود نخواهد داشت.

نمونه کد زیر نحوه تنظیم گزینه‌های SSV پس از بارگذاری تبلیغ جایزه‌دار را نشان می‌دهد:

RewardedAd.load(
  adUnitId: "_adUnitId",
  request: AdManagerAdRequest(),
  rewardedAdLoadCallback: RewardedAdLoadCallback(
    onAdLoaded: (ad) {
      ServerSideVerificationOptions _options =
          ServerSideVerificationOptions(
            customData: 'SAMPLE_CUSTOM_DATA_STRING',
          );
      ad.setServerSideOptions(_options);
      _rewardedAd = ad;
    },
    onAdFailedToLoad: (error) {},
  ),
);

SAMPLE_CUSTOM_DATA_STRING را با داده‌های سفارشی خود جایگزین کنید.