إعلان بيني

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

يشرح هذا الدليل كيفية دمج الإعلانات البينية في تطبيق Flutter.

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

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

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

  • /6499/example/interstitial

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

تحميل إعلان

المثال التالي يحمّل إعلانًا بينيًا:

class InterstitialExampleState extends State<InterstitialExample> {
  AdManagerInterstitialAd? _interstitialAd;

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

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

أحداث الإعلانات البينية

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

class InterstitialExampleState extends State<InterstitialExample> {
  AdManagerInterstitialAd? _interstitialAd;

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

  /// Loads an interstitial ad.
  void loadAd() {
    AdManagerInterstitialAd.load(
        adUnitId: adUnitId,
        request: const AdManagerAdRequest(),
        adLoadCallback: AdManagerInterstitialAdLoadCallback(
          // 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.
            _interstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('AdManagerInterstitialAd failed to load: $error');
          },
        ));
  }
}

عرض إعلان بيني

يتم عرض AdManagerInterstitialAd على شكل Overlay. في أعلى كل محتوى التطبيق ويتم وضعها بشكل ثابت ومن ثم لا يمكن إضافته إلى شجرة تطبيقات Flutter المصغّرة يمكنك اختيار وقت عرض الإعلان من خلال الاتصال بالرقم show().

_interstitiaAd.show();

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

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

هذا كل شيء! تطبيقك جاهز الآن لعرض الإعلانات البينية.

الخطوات التالية