إعلان بيني

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

يشرح هذا الدليل كيفية دمج الإعلانات البينية في تطبيق 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.

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

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