Interstitial

This guide explains how to integrate Interstitial ads using the Ogury SDK in your Android application.

Prerequisites

Before proceeding, make sure you have completed the steps outlined in the Getting Started section:

  • Registered your app and created ad units in the Ogury Publisher Platform.

  • Retrieved your asset key and ad unit IDs.

  • Updated your app-ads.txt file.

Before integrating any ad format, ensure you have completed the SDK Setup:

  • Integrated and initialized the Ogury SDK in your app.

Load an Interstitial ad

To load an Interstitial ad:

  1. Instantiate an OguryInterstitialAd object with a valid Interstitial ad unit ID.

  2. Call its load() method.

class MyActivity : Activity() {

    private lateinit var interstitialAd: OguryInterstitialAd

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        interstitialAd = OguryInterstitialAd(this, "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
        interstitialAd.load()
    }
}

The OguryInterstitialAd constructor takes the following parameters:

  • A reference to any kind of context.

  • Your Ogury ad unit ID for the Interstitial ad. It is in the form of a UUID, which consists of a 36-character string formatted as follows: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, where each x represents a hexadecimal digit. See Ad Unit Creation if you haven’t generated one.

  • If you are building a mediation adapter, an additional parameter, OguryMediation which should be instantiated with:

    • name: the name of the mediation.

    • version: the version of the mediation SDK.

interstitialAd = OguryInterstitialAd(
    this, 
    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    OguryMediation("your mediation name", "your mediation SDK version")
)

Register for callbacks

You can monitor the lifecycle of your Interstitial ad by implementing the OguryInterstitialAdListener interface. This listener provides real-time updates on key events, such as successful ad loading, display or errors.

To use it, set the listener on the instance of OguryInterstitialAd by calling the setListener() method before invoking the load() method. Implement the necessary methods in your class to ensure timely notifications, allowing you to manage the ad experience effectively.

If the onAdErrorcallback is triggered, refer to the Ad Error handling section below for detailed information on troubleshooting.

interstitialAd.setListener(object : OguryInterstitialAdListener {

    // Called when the ad is loaded and ready to be shown
    override fun onAdLoaded(interstitialAd: OguryInterstitialAd) {
        // Call show() to display the ad
    }

    // Called when an impression is recorded
    override fun onAdImpression(interstitialAd: OguryInterstitialAd) {
        // Track ad performance here
    }

    // Called when the user clicks on the ad
    override fun onAdClicked(interstitialAd: OguryInterstitialAd) {
        // Handle ad click tracking here
    }

    // Called when the ad is closed
    override fun onAdClosed(interstitialAd: OguryInterstitialAd) {
        // Resume app flow after ad is closed
    }

    // Called when the ad fails to load or display
    override fun onAdError(interstitialAd: OguryInterstitialAd, error: OguryAdError) {
        when (error.type) {
            OguryAdError.Type.LOAD_ERROR -> {
                // Handle loading error
            }
            OguryAdError.Type.SHOW_ERROR -> {
                // Handle display error
            }
        }
    }
})

Show an Interstitial ad

To display a loaded Interstitial ad, invoke the show() method on the instantiated OguryInterstitialAd object.

if (interstitialAd.isLoaded()) {
    // The ad is loaded and ready to be displayed.
    interstitialAd.show()
} else {
    // The ad is not loaded yet. Handle this situation appropriately.
}

Additional Resources

Integration Testing

Ensure your implementation works correctly by testing with test ads and verifying ad behavior.

See the Testing Guide.

Ad Error Handling

If Interstitial ads fail to load or display, we recommend implementing and logging the callbacks from OguryInterstitialAdListener to track the full ad lifecycle. Pay particular attention to the onAdError callback, which returns an OguryAdError object containing detailed information about the failure.

For a full list of error types, refer to the Ad Error Handling page.

Migration Guide

Still using Ogury SDK v5? Follow our step-by-step migration guide to smoothly upgrade to v6 and take advantage of the latest features and improvements.

View the Migration Guide.

Last updated

Was this helpful?