All skills
google avatar

/google-mobile-ads-interstitial

@329fa26
by googlegoogle/skills21k stars
1,698

Provides instructions for implementing, integrating, or configuring Google Mobile Ads (GMA) SDK interstitial ads in Android, iOS, or Unity mobile applications. Use when the task involves setting up interstitial ads. Don't use for "rewarded interstitial" ads.

Use this Skill: https://skilld.dev/gh/google/skills/google-mobile-ads-interstitial

This session only. Nothing lands on disk.

referencesunity-interstitial.md

≈836 tokens on demand. Your agent reads this file only when SKILL.md points to it.

AI Integration Agent Instructions for Unity Interstitial Ads

Required Imports

Use the following imports to implement an interstitial ad:

using System;
using UnityEngine;
using GoogleMobileAds.Api;
using GoogleMobileAds.Common;

Interstitial Ad Workflow

  1. Load the ad:

    Use the static InterstitialAd.Load() method passing the ad unit ID, an AdRequest object, and a completion callback (Action<InterstitialAd, LoadAdError>):

    // Test ad unit IDs. Replace with your own ad unit IDs.
    #if UNITY_ANDROID
        string adUnitId = "ca-app-pub-3940256099942544/1033173712";
    #elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/4411468910";
    #else
        string adUnitId = "unused";
    #endif
    InterstitialAd.Load(adUnitId, new AdRequest(),
        (InterstitialAd ad, LoadAdError error) =>
        {
            if (error != null || ad == null)
            {
                // Handle the error.
                return;
            }
            interstitialAd = ad;
        });

    Always destroy any existing InterstitialAd object before loading a new ad.

  2. Register for ad event callbacks:

    Subscribing to ad events on the InterstitialAd object is optional and depends on your application requirements:

    • OnAdPaid: Subscribe to log estimated ad revenue (AdValue) for impression-level ad monetization tracking.
    • OnAdImpressionRecorded: Subscribe to track ad impressions in internal telemetry or third-party analytics platforms.
    • OnAdClicked: Subscribe to record user clicks on the ad.
    • OnAdFullScreenContentOpened: Subscribe to pause game audio, timers, or gameplay loops when the interstitial ad covers the screen.
    • OnAdFullScreenContentClosed: Subscribe to resume game audio or gameplay loops when the ad is dismissed. Destroy the InterstitialAd object (interstitialAd.Destroy()) and reload another ad (InterstitialAd.Load()) so a fresh ad is ready for the next transition point.
    • OnAdFullScreenContentFailed: Subscribe to log display errors if the interstitial ad fails to show.

    Ensure background ad callbacks interacting with Unity objects (UnityEngine) are explicitly scheduled on the main thread using MobileAdsEventExecutor.ExecuteInUpdate(), because Unity APIs are not thread-safe and must be called from the main thread.

    interstitialAd.OnAdFullScreenContentOpened += () =>
    {
        MobileAdsEventExecutor.ExecuteInUpdate(() =>
        {
            // Interact with UnityEngine objects on the main thread here.
        });
    };
  3. Show the ad:

    Check CanShowAd() on the InterstitialAd object before calling the Show() method. Include a null check to avoid exceptions.

    if (interstitialAd != null && interstitialAd.CanShowAd())
    {
        interstitialAd.Show();
    }
  4. Verify the implementation: Ensure there are no compilation errors:

    • Verify the Unity Console has no C# script compile errors or missing GoogleMobileAds namespace references.

Links

Additional documentation:

Source: SKILL.md on GitHub

No alerts8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    This skill provides instructions for integrating mobile ad components into Android, iOS, and Unity projects. It follows standard development practices, including build verification steps and references to official developer documentation.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: LOW · No issues

Signed by skilld at 329fa26. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last week
metadata
{
  "version": "1.1.0",
  "category": "GoogleAds"
}

README badge

README badge for google/skills/google-mobile-ads-interstitial