Interstitial

This guide explains how to integrate Interstitial ads using the Ogury SDK in your iOS 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.

import UIKit
import OguryAds

class ViewController: UIViewController {
    private(set) var interstitialAd: OguryInterstitialAd!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        interstitialAd = OguryInterstitialAd(adUnitID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
        interstitialAd.load()
    }
}

The OguryInterstitialAd initializer takes the following parameters:

  • 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.

self.interstitialAd = OguryInterstitialAd(
    adUnitId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 
    mediation: OguryMediation(name: "your mediation name", 
                              version: "your mediation SDK version")
)

Register for callbacks

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

To use it, set your class as the delegate of OguryInterstitialAd and implement the necessary methods. This ensures timely notifications, allowing you to manage the ad experience effectively.

If the interstitialAd:didFailWithError: callback is triggered, refer to the Ad Error handling section below for detailed information on troubleshooting.

override func viewDidLoad() {
    super.viewDidLoad()
    interstitialAd = OguryInterstitialAd(
        adUnitID: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    )
    interstitialAd.delegate = self
    interstitialAd.load()
}

// Called when the ad is loaded and ready to be shown
func interstitialAdDidLoad(_ interstitialAd: OguryInterstitialAd) {
    // Call show() to display the ad
}

// Called when an impression is recorded
func interstitialAdDidTriggerImpression(_ interstitialAd: OguryInterstitialAd) {
    // Track ad performance here
}

// Called when the user clicks on the ad
func interstitialAdDidClick(_ interstitialAd: OguryInterstitialAd) {
    // Handle ad click tracking here
}

// Called when the ad is closed
func interstitialAdDidClose(_ interstitialAd: OguryInterstitialAd) {
    // Resume app flow after ad is closed
}

// Called when the ad fails to load or display
func interstitialAd(_ interstitialAd: OguryInterstitialAd, 
              didFailWithError error: OguryAdError) {
    switch error.type {
        case .load:
            // Handle loading error
        case .show:
            // 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(in: self)
} else {
    // The ad is not loaded yet. Handle this situation appropriately.
}

The show() method takes the following parameter:

  • A reference to the ViewController where the Interstitial ad will be presented.


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 OguryInterstitialAdDelegate to track the full ad lifecycle. Pay particular attention to the interstitialAd:didFailWithError: 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 v4? Follow our step-by-step migration guide to smoothly upgrade to v5 and take advantage of the latest features and improvements.

View the Migration Guide.

Last updated

Was this helpful?