تم منح المكافأة

الإعلانات التي تضم مكافأة هي إعلانات يتوفّر للمستخدمين خيار التفاعل معها مقابل مكافآت داخل التطبيق. يوضّح هذا الدليل كيفية دمج الإعلانات التي تضم مكافأة من "مدير الإعلانات" في تطبيق Flutter

الاختبار دائمًا باستخدام الإعلانات الاختبارية

عند إنشاء تطبيقاتك واختبارها، احرص على استخدام إعلانات تجريبية بدلاً من الإعلانات النهائية المباشرة. وقد يؤدي عدم الالتزام بذلك إلى تعليق حسابك.

أسهل طريقة لتحميل الإعلانات الاختبارية هي استخدام رقم تعريف الوحدة الإعلانية الاختبارية المخصّصة للإعلانات التي تتضمن مكافآت:

  • /6499/example/rewarded

يتم إعداد الوحدات الإعلانية الاختبارية لعرض إعلانات اختبارية لكل طلب، ويمكنك استخدامها في تطبيقاتك أثناء الترميز والاختبار وتصحيح الأخطاء. ما عليك سوى التأكد من استبدالها بأرقام تعريف الوحدات الإعلانية قبل نشر تطبيقك.

تحميل إعلان

في ما يلي مثال يحمّل إعلانًا يضم مكافأة:

class RewardedExampleState extends State<RewardedExample> {
  RewardedAd? _rewardedAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = '/6499/example/rewarded';

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedAd.loadWithAdManagerAdRequest(
        adUnitId: adUnitId,
        adManagerAdRequest: const AdManagerAdRequest(),
        adLoadCallback: RewardedAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _rewardedAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('RewardedAd failed to load: $error');
          },
        ));
  }
}

أحداث الإعلانات التي تضم مكافأة

من خلال استخدام FullScreenContentCallback، يمكنك رصد أحداث مراحل النشاط، مثل عرض الإعلان أو رفضه. اضبط RewardedAd.fullScreenContentCallback قبل عرض الإعلان لتلقّي إشعارات عن هذه الأحداث. ينفذ هذا المثال كل طريقة ويسجل رسالة في وحدة التحكم:

class RewardedExampleState extends State<RewardedExample> {
  RewardedAd? _rewardedAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = '/6499/example/rewarded';

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedAd.loadWithAdManagerAdRequest(
        adUnitId: adUnitId,
        adManagerAdRequest: const AdManagerAdRequest(),
        adLoadCallback: RewardedAdLoadCallback(
          // 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.
            _rewardedAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('RewardedAd failed to load: $error');
          },
        ));
  }
}

إعلان صوري

يتم عرض RewardedAd على شكل طبقة "تراكب" في أعلى كل محتوى التطبيق ويتم وضعها بشكل ثابت، وبالتالي لا يمكن إضافتها إلى شجرة تطبيقات Flutter المصغّرة. يمكنك اختيار وقت عرض الإعلان من خلال طلب الرقم show(). يحصل RewardedAd.show() على OnUserEarnedRewardCallback، والذي يتم استدعاؤه عندما يكسب المستخدم مكافأة. تأكد من تنفيذ ذلك وكافئ المستخدم على مشاهدة أحد الإعلانات.

_rewardedAd.show(onUserEarnedReward: (AdWithoutView ad, RewardItem rewardItem) {
  // Reward the user for watching an ad.
});

بعد طلب show()، لا يمكن إزالة Ad المعروضة بهذه الطريقة بشكل آلي، وهي تتطلّب إدخال المستخدم. لا يمكن عرض RewardedAd إلا مرة واحدة. وسيؤدي إظهار المكالمات اللاحقة إلى تشغيل onAdFailedToShowFullScreenContent.

يجب التخلص من الإعلان عند عدم الحاجة إلى الوصول إليه. تتمثل أفضل ممارسة لحالات الاتصال بـ dispose() في استدعاءَي FullScreenContentCallback.onAdDismissedFullScreenContent وFullScreenContentCallback.onAdFailedToShowFullScreenContent.

أكملت هذه الخطوة. أصبح تطبيقك جاهزًا الآن لعرض الإعلانات التي تضم مكافأة.