מודעות מעברון הן מודעות במסך מלא שמכסות את הממשק של האפליקציה. אתם מציגים את המודעות האלה בנקודות מעבר טבעיות באפליקציה, למשל בין פעילויות או במהלך הפסקות בשלבים במשחק. כשמודעת מעברון מוצגת באפליקציה, המשתמשים יכולים להקיש על המודעה ולהמשיך, או לסגור את המודעה ולחזור לאפליקציה. מומלץ לקרוא את אחד ממחקרים המקרה שלנו.
במדריך הזה מוסבר איך לשלב מודעות מעברון באפליקציית Android.
דרישות מוקדמות
תמיד כדאי לבצע בדיקות באמצעות מודעות בדיקה
כשמפתחים ובודקים את האפליקציות, חשוב להשתמש במודעות בדיקה ולא במודעות פעילות לפרסום מוצרים. אם לא תשתמשו במודעות לבדיקה, Google עשויה להשעות את החשבון שלכם.
הדרך הכי קלה לטעון מודעות בדיקה היא להשתמש במזהה הייעודי של יחידת המודעות לבדיקה עבור מודעות מעברון ב-Android:
ca-app-pub-3940256099942544/1033173712
מזהה יחידת המודעות הזה הוגדר במיוחד כדי להחזיר מודעות בדיקה לכל בקשה. אתם יכולים להשתמש בו באפליקציות שלכם במהלך תכנות, בדיקה וניפוי באגים. חשוב להחליף אותו במזהה יחידת המודעות שלכם לפני שמפרסמים את האפליקציה.
פרטים על GMA Next-Gen SDK מודעות בדיקה זמינים במאמר הפעלת מודעות בדיקה.
טעינת מודעה
בדוגמה הבאה אפשר לראות איך טוענים מודעה יחידה:
Kotlin
// Load ads after you initialize MobileAds. InterstitialAd.load( AdRequest.Builder(adUnitId).build(), object : AdLoadCallback<InterstitialAd> { override fun onAdLoaded(ad: InterstitialAd) { // Interstitial ad loaded. interstitialAd = ad } override fun onAdFailedToLoad(adError: LoadAdError) { // Interstitial ad failed to load. Log.e(TAG, "Interstitial ad failed to load: ${adError.message}") interstitialAd = null } }, )
Java
// Load ads after you initialize MobileAds. InterstitialAd.load( new AdRequest.Builder(adUnitId).build(), new AdLoadCallback<InterstitialAd>() { @Override public void onAdLoaded(@NonNull InterstitialAd ad) { // Interstitial ad loaded. interstitialAd = ad; } @Override public void onAdFailedToLoad(@NonNull LoadAdError adError) { // Interstitial ad failed to load. Log.e(TAG, "Interstitial ad failed to load: " + adError.getMessage()); interstitialAd = null; } });
במהלך הבדיקה, צריך להשתמש במזהה של יחידת המודעות לבדיקה:
ca-app-pub-3940256099942544/1033173712.
הצגת המודעה
כדי להציג מודעת מעברון, משתמשים בשיטה show.
Kotlin
private fun showAd(interstitialAd: InterstitialAd, activity: Activity) { // Show the ad. interstitialAd.show(activity) }
Java
private void showAd(InterstitialAd interstitialAd, Activity activity) { // Show the ad. interstitialAd.show(activity); }
האזנה לאירועים של מודעות
לפני הצגת המודעה, צריך להמתין לאירועים במחזור החיים של המודעה:
Kotlin
// Listen for ad events. val ad = interstitialAd if (ad == null) { Log.e(TAG, "Interstitial ad is not ready yet.") return } ad.adEventCallback = object : InterstitialAdEventCallback { override fun onAdShowedFullScreenContent() { // Interstitial ad did show. } override fun onAdDismissedFullScreenContent() { // Interstitial ad did dismiss. interstitialAd = null } override fun onAdFailedToShowFullScreenContent( fullScreenContentError: FullScreenContentError ) { // Interstitial ad failed to show. Log.e(TAG, "Interstitial ad failed to show: ${fullScreenContentError.message}") } override fun onAdImpression() { // Interstitial ad did record an impression. } override fun onAdClicked() { // Interstitial ad did record a click. } }
Java
// Listen for ad events. if (interstitialAd == null) { Log.e(TAG, "Interstitial ad is not ready yet."); return; } interstitialAd.setAdEventCallback( new InterstitialAdEventCallback() { @Override public void onAdShowedFullScreenContent() { // Interstitial ad did show. } @Override public void onAdDismissedFullScreenContent() { // Interstitial ad did dismiss. interstitialAd = null; } @Override public void onAdFailedToShowFullScreenContent( @NonNull FullScreenContentError fullScreenContentError) { // Interstitial ad failed to show. Log.e(TAG, "Interstitial ad failed to show: " + fullScreenContentError.getMessage()); } @Override public void onAdImpression() { // Interstitial ad did record an impression. } @Override public void onAdClicked() { // Interstitial ad did record a click. } });