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

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

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

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

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

تحميل إعلان

لتحميل إعلان بيني، استدعِ طريقة AdManagerInterstitialAd الثابتة load() وأدخِل AdManagerInterstitialAdLoadCallback لتلقّي الإعلان المحمَّل أو أي أخطاء محتملة. تستخدم AdManagerInterstitialAdLoadCallback LoadAdError لتقديم تفاصيل الخطأ.

جافا

AdManagerInterstitialAd.load(
    this,
    AD_UNIT_ID,
    new AdManagerAdRequest.Builder().build(),
    new AdManagerInterstitialAdLoadCallback() {
      @Override
      public void onAdLoaded(@NonNull AdManagerInterstitialAd 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

AdManagerInterstitialAd.load(
  this,
  AD_UNIT_ID,
  AdManagerAdRequest.Builder().build(),
  object : AdManagerInterstitialAdLoadCallback() {
    override fun onAdLoaded(interstitialAd: AdManagerInterstitialAd) {
      Log.d(TAG, "Ad was loaded.")
      this@MyActivity.interstitialAd = interstitialAd
    }

    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)

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

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

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

/21775744923/example/interstitial

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

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

أمثلة على GitHub

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

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