الإعلانات البينية

اختيار النظام الأساسي: Android iOS Unity Flutter Android (الإصدار القديم)

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

يوضّح هذا الدليل كيفية دمج الإعلانات البينية في تطبيق Android.

المتطلبات الأساسية

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

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

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

ca-app-pub-3940256099942544/1033173712

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

للحصول على تفاصيل حول Google Mobile Ads SDK (Legacy) الإعلانات التجريبية، اطّلِع على مقالة تفعيل الإعلانات التجريبية.

تحميل إعلان

لعرض إعلان بيني، استدعِ الدالة InterstitialAd static load() ومرِّر InterstitialAdLoadCallback لتلقّي الإعلان الذي تم تحميله أو أي أخطاء محتملة. يُرجى العِلم أنّ InterstitialAdLoadCallback تستخدم LoadAdError، مثل غيرها من عمليات معاودة الاتصال لتحميل التنسيقات، وذلك لتقديم تفاصيل خطأ أكثر دقة.

جافا

InterstitialAd.load(
    this,
    AD_UNIT_ID,
    new AdRequest.Builder().build(),
    new InterstitialAdLoadCallback() {
      @Override
      public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
        Log.d(TAG, "Ad was loaded.");
        MyActivity.this.interstitialAd = interstitialAd;
      }

      @Override
      public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
        Log.d(TAG, loadAdError.getMessage());
        interstitialAd = null;
      }
    });

Kotlin

InterstitialAd.load(
  this,
  AD_UNIT_ID,
  AdRequest.Builder().build(),
  object : InterstitialAdLoadCallback() {
    override fun onAdLoaded(ad: InterstitialAd) {
      Log.d(TAG, "Ad was loaded.")
      interstitialAd = ad
    }

    override fun onAdFailedToLoad(adError: LoadAdError) {
      Log.d(TAG, adError.message)
      interstitialAd = null
    }
  },
)

ضبط FullScreenContentCallback

يتعامل FullScreenContentCallback مع الأحداث المرتبطة بعرض InterstitialAd. قبل عرض InterstitialAd، تأكَّد من ضبط دالة الرجوع على النحو التالي:

جافا

interstitialAd.setFullScreenContentCallback(
    new FullScreenContentCallback() {
      @Override
      public void onAdDismissedFullScreenContent() {
        // Called when fullscreen content is dismissed.
        Log.d(TAG, "The ad was dismissed.");
        // Make sure to set your reference to null so you don't
        // show it a second time.
        MyActivity.this.interstitialAd = null;
      }

      @Override
      public void onAdFailedToShowFullScreenContent(AdError adError) {
        // Called when fullscreen content failed to show.
        Log.d(TAG, "The ad failed to show.");
        // Make sure to set your reference to null so you don't
        // show it a second time.
        MyActivity.this.interstitialAd = null;
      }

      @Override
      public void onAdShowedFullScreenContent() {
        // Called when fullscreen content is shown.
        Log.d(TAG, "The ad was shown.");
      }

      @Override
      public void onAdImpression() {
        // Called when an impression is recorded for an ad.
        Log.d(TAG, "The ad recorded an impression.");
      }

      @Override
      public void onAdClicked() {
        // Called when ad is clicked.
        Log.d(TAG, "The ad was clicked.");
      }
    });

Kotlin

interstitialAd?.fullScreenContentCallback =
  object : FullScreenContentCallback() {
    override fun onAdDismissedFullScreenContent() {
      // Called when fullscreen content is dismissed.
      Log.d(TAG, "Ad was dismissed.")
      // Don't forget to set the ad reference to null so you
      // don't show the ad a second time.
      interstitialAd = null
    }

    override fun onAdFailedToShowFullScreenContent(adError: AdError) {
      // Called when fullscreen content failed to show.
      Log.d(TAG, "Ad failed to show.")
      // Don't forget to set the ad reference to null so you
      // don't show the ad a second time.
      interstitialAd = null
    }

    override fun onAdShowedFullScreenContent() {
      // Called when fullscreen content is shown.
      Log.d(TAG, "Ad showed fullscreen content.")
    }

    override fun onAdImpression() {
      // Called when an impression is recorded for an ad.
      Log.d(TAG, "Ad recorded an impression.")
    }

    override fun onAdClicked() {
      // Called when ad is clicked.
      Log.d(TAG, "Ad was clicked.")
    }
  }

عرض الإعلان

يجب عرض الإعلانات البينية أثناء فترات التوقف المؤقت الطبيعية في مسار التطبيق، مثل بين مستويات اللعبة أو بعد أن يكمل المستخدم مهمة ما. لعرض إعلان بيني، استخدِم طريقة show().

جافا

if (interstitialAd != null) {
  interstitialAd.show(this);
} else {
  Log.d(TAG, "The interstitial ad is still loading.");
}

Kotlin

interstitialAd?.show(this)

رمز مصدر

أمثلة على GitHub

  • مثال على الإعلانات البينية: Java | Kotlin

قصص النجاح

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