تبلیغات جایزهدار، تبلیغاتی هستند که کاربران میتوانند در ازای دریافت جوایز درونبرنامهای با آنها تعامل داشته باشند. این راهنما نحوه ادغام تبلیغات جایزهدار از AdMob در یک برنامه Flutter را نشان میدهد.
همیشه با تبلیغات آزمایشی تست کنید
هنگام ساخت و آزمایش برنامههای خود، مطمئن شوید که از تبلیغات آزمایشی به جای تبلیغات زنده و تولیدی استفاده میکنید. عدم انجام این کار میتواند منجر به مسدود شدن حساب شما شود.
سادهترین راه برای بارگذاری تبلیغات آزمایشی، استفاده از شناسه واحد تبلیغات آزمایشی اختصاصی ما برای تبلیغات جایزهدار است:
اندروید
ca-app-pub-3940256099942544/5224354917
آیاواس
ca-app-pub-3940256099942544/1712485313
The test ad units are configured to return test ads for every request, and you're free to use them in your own apps while coding, testing, and debugging. Just make sure you replace them with your own ad unit IDs before publishing your app.
بارگذاری یک تبلیغ
مثال زیر یک تبلیغ جایزهدار را بارگذاری میکند:
به جای _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 .
An ad must be disposed when access to it is no longer needed. The best practice for when to call dispose() is in the FullScreenContentCallback.onAdDismissedFullScreenContent and FullScreenContentCallback.onAdFailedToShowFullScreenContent callbacks.
[اختیاری] اعتبارسنجی کالبکهای تأیید سمت سرور (SSV)
برنامههایی که در فراخوانیهای تأیید سمت سرور به دادههای اضافی نیاز دارند، باید از ویژگی دادههای سفارشی تبلیغات پاداشی استفاده کنند. هر مقدار رشتهای که روی یک شیء تبلیغ پاداشی تنظیم شود، به پارامتر پرسوجوی custom_data از فراخوانی SSV ارسال میشود. اگر هیچ مقدار داده سفارشی تنظیم نشود، مقدار پارامتر پرسوجوی custom_data در فراخوانی SSV وجود نخواهد داشت.
نمونه کد زیر نحوه تنظیم گزینههای SSV پس از بارگذاری تبلیغ جایزهدار را نشان میدهد:
SAMPLE_CUSTOM_DATA_STRING را با دادههای سفارشی خود جایگزین کنید.