Annonces interstitielles

Les annonces interstitielles s'affichent en plein écran et recouvrent l'interface de l'application hôte. Elles sont généralement diffusées à des points de transition naturels dans une application, par exemple entre deux activités ou pendant la pause entre les niveaux d'un jeu. Lorsqu'une application diffuse une annonce interstitielle, l'utilisateur peut appuyer dessus et continuer vers sa destination, ou la fermer et revenir à l'application.

Ce guide explique comment intégrer des annonces interstitielles à une application Android.

Prérequis

Toujours tester avec des annonces tests

Lorsque vous créez et testez vos applications, assurez-vous d'utiliser des annonces tests plutôt que des annonces de production. À défaut, votre compte risque d'être suspendu.

Le moyen le plus simple de charger les annonces tests consiste à utiliser notre ID de bloc d'annonces test dédié aux interstitiels Android:

/6499/example/interstitial

Il est spécialement configuré pour renvoyer des annonces tests pour chaque requête. Vous pouvez l'utiliser dans vos propres applications lors du codage, des tests et du débogage. Veillez simplement à le remplacer par votre propre ID de bloc d'annonces avant de publier votre application.

Pour en savoir plus sur le fonctionnement des annonces tests du SDK Mobile Ads, consultez Annonces tests.

Load an ad

To load an interstitial ad, call the AdManagerInterstitialAd static load() method and pass in an AdManagerInterstitialAdLoadCallback to receive the loaded ad or any possible errors. Notice that like other format load callbacks, AdManagerInterstitialAdLoadCallback leverages LoadAdError to provide higher fidelity error details.

Java

import com.google.android.gms.ads.admanager.AdManagerInterstitialAd;
import com.google.android.gms.ads.admanager.AdManagerInterstitialAdLoadCallback;

public class MainActivity extends Activity {

  private AdManagerInterstitialAd mAdManagerInterstitialAd;
  private static final String TAG = "MainActivity";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder().build();

    AdManagerInterstitialAd.load(this,"/6499/example/interstitial", adRequest,
        new AdManagerInterstitialAdLoadCallback() {
      @Override
      public void onAdLoaded(@NonNull AdManagerInterstitialAd interstitialAd) {
        // The mAdManagerInterstitialAd reference will be null until
        // an ad is loaded.
        mAdManagerInterstitialAd = interstitialAd;
        Log.i(TAG, "onAdLoaded");
      }

      @Override
      public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
        // Handle the error
        Log.d(TAG, loadAdError.toString());
        mAdManagerInterstitialAd = null;
      }
    });
  }
}

Kotlin

import com.google.android.gms.ads.admanager.AdManagerInterstitialAd;
import com.google.android.gms.ads.admanager.AdManagerInterstitialAdLoadCallback;

class MainActivity : AppCompatActivity() {

  private var mAdManagerInterstitialAd: AdManagerInterstitialAd? = null
  private final val TAG = "MainActivity"

    override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)

      var adRequest = AdManagerAdRequest.Builder().build()

      AdManagerInterstitialAd.load(this,"/6499/example/interstitial", adRequest, object : AdManagerInterstitialAdLoadCallback() {
        override fun onAdFailedToLoad(adError: LoadAdError) {
          Log.d(TAG, adError?.toString())
          mAdManagerInterstitialAd = null
        }

        override fun onAdLoaded(interstitialAd: AdManagerInterstitialAd) {
          Log.d(TAG, 'Ad was loaded.')
          mAdManagerInterstitialAd = interstitialAd
        }
      })
    }
}

Set the FullScreenContentCallback

The FullScreenContentCallback handles events related to displaying your InterstitialAd. Before showing InterstitialAd, make sure to set the callback:

Java

mAdManagerInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){
  @Override
  public void onAdClicked() {
    // Called when a click is recorded for an ad.
    Log.d(TAG, "Ad was clicked.");
  }

  @Override
  public void onAdDismissedFullScreenContent() {
    // Called when ad is dismissed.
    // Set the ad reference to null so you don't show the ad a second time.
    Log.d(TAG, "Ad dismissed fullscreen content.");
    mAdManagerInterstitialAd = null;
  }

  @Override
  public void onAdFailedToShowFullScreenContent(AdError adError) {
    // Called when ad fails to show.
    Log.e(TAG, "Ad failed to show fullscreen content.");
    mAdManagerInterstitialAd = null;
  }

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

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

Kotlin

mAdManagerInterstitialAd?.fullScreenContentCallback = object: FullScreenContentCallback() {
  override fun onAdClicked() {
    // Called when a click is recorded for an ad.
    Log.d(TAG, "Ad was clicked.")
  }

  override fun onAdDismissedFullScreenContent() {
    // Called when ad is dismissed.
    Log.d(TAG, "Ad dismissed fullscreen content.")
    mAdManagerInterstitialAd = null
  }

  override fun onAdFailedToShowFullScreenContent(adError: AdError?) {
    // Called when ad fails to show.
    Log.e(TAG, "Ad failed to show fullscreen content.")
    mAdManagerInterstitialAd = null
  }

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

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

Show the ad

Interstitial ads should be displayed during natural pauses in the flow of an app. Between levels of a game is a good example, or after the user completes a task. To show an interstitial, use the show() method.

Java

if (mAdManagerInterstitialAd != null) {
  mAdManagerInterstitialAd.show(MyActivity.this);
} else {
  Log.d("TAG", "The interstitial ad wasn't ready yet.");
}

Kotlin

if (mAdManagerInterstitialAd != null) {
  mAdManagerInterstitialAd?.show(this)
} else {
  Log.d("TAG", "The interstitial ad wasn't ready yet.")
}

Quelques bonnes pratiques

Déterminez si les annonces interstitielles sont le bon type d'annonce pour votre application.
Les annonces interstitielles sont plus efficaces dans les applications qui présentent des points de transition naturels. La fin d'une tâche dans une application, comme le partage d'une image ou la fin d'un niveau de jeu, crée un tel point. Réfléchissez à à quels stades du workflow de votre application vous diffuserez des annonces interstitielles, et à la manière dont l'utilisateur est susceptible de répondre.
N'oubliez pas de mettre en veille l'action lors de l'affichage d'une annonce interstitielle.
Il existe plusieurs types d'annonces interstitielles: textuelles, illustrées, vidéo, etc. Lorsque votre application affiche une annonce interstitielle, vous devez vous assurer que l'utilisation de certaines ressources est également suspendue pour que l'annonce puisse en profiter. Par exemple, lorsque vous effectuez l'appel pour afficher une annonce interstitielle, veillez à mettre en pause toute sortie audio produite par votre application.
Prévoyez un temps de chargement adéquat.
Tout comme vous devez vous assurer que vous diffusez des annonces interstitielles au bon moment, vous devez faire en sorte que l'utilisateur n'ait pas à attendre que leur chargement soit terminé. En chargeant l'annonce à l'avance en appelant load() avant d'appeler show(), vous pouvez vous assurer que votre application dispose d'une annonce interstitielle entièrement chargée le moment venu.
N'inondez pas l'utilisateur d'annonces.
L'augmentation de la fréquence des annonces interstitielles dans votre application peut sembler être un excellent moyen d'augmenter vos revenus, mais cela peut également avoir un impact négatif sur l'expérience utilisateur et réduire les taux de clics. Assurez-vous que les utilisateurs ne soient pas interrompus trop souvent au point qu'ils ne puissent plus profiter de votre application.

Exemples sur GitHub

  • Exemple d'annonces interstitielles : Java | Kotlin

Étapes suivantes