Interstitial Ad

This article will go through all the steps required to display an Interstitial Ad in your application.

Interstitials Ads are skippable fullscreen ads.

Requirements

You have registered an application on your Ogury Dashboard. If not, please refer to the Getting Started section before the next steps.

Step 1: Create an Interstitial Ad ad unit

In all the following code samples, we will refer to this Ad unit id by using the string AD_UNIT_ID.

Step 2: Load an Interstitial Ad

The Ogury SDK provides the OguryInterstitialAd object that lets you load, display and control your Interstitial Ads.

Instantiate an Interstitial Ad

  • Declare a OguryInterstitialAd instance variable in the ViewController where you want to display an Interstitial Ads:

var interstitialAd: OguryInterstitialAd?
  • In the viewDidLoad method of the ViewController, instantiate the Interstitial Ad:

override func viewDidLoad() {
    super.viewDidLoad()
    self.interstitialAd = OguryInterstitialAd(adUnitId: "AD_UNIT_ID")
}

OguryInterstitialAdtakes the following parameter:

  • an adUnitID: the Ad unit id of the Interstitial Ad. If you do not have one yet, you can refer to the first step to create it.

If you are a mediation, you should provide an extra parameter OguryMediation that should be instanciated with :

  • Your current mediation name as MEDIATION_NAME

  • Your current SDK version as YOUR_SDK_VERSION

override func viewDidLoad() {
    super.viewDidLoad()
    self.interstitialAd = OguryInterstitialAd(
         adUnitId: "AD_UNIT_ID", 
         mediation: OguryMediation(name: "MEDIATION_NAME", 
                                   version: "YOUR_SDK_VERSION")
    )
}

Load an Interstitial Ad

To start loading an ad, call the load method:

interstitialAd?.load()

Since it may take a few seconds to fetch the ad resources (video, image, ...) from the network, you should call the load method as soon as possible after getting the user's consent.

Ideally, you should implement one of the two following examples depending on your use case:

  • Call the load method right after the start method in the ViewController that collects the consent:

import UIKit
import OgurySdk
import OguryAds
import OguryChoiceManager

class ViewController: UIViewController {

    var interstitialAd: OguryInterstitialAd?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let configuration = OguryConfigurationBuilder(assetKey: "OGY-XXXXXXXXXXXX").build()
        Ogury.start(with: configuration)

        interstitialAd = OguryInterstitialAd(adUnitID: "AD_UNIT_ID")
        interstitialAd?.load()
    }
}
  • Call the load method in the viewDidLoad of your other ViewController:

override func viewDidLoad() {
    super.viewDidLoad()
    
    interstitialAd = OguryInterstitialAd(adUnitID: "AD_UNIT_ID")
    interstitialAd?.load()
}

Additionally, if you want to follow the lifecycle of the Interstitial Ad, you can register a delegate.

Step 3: Show an Interstitial Ad

To display the ad, call show method:

self.interstitialAd?.show(in: self)

The show method takes the following parameter:

  • a reference to the ViewController where you will show the Interstitial Ad.

Make sure to call the show method in the main thread, otherwise, an exception will result.

If the method fails to show the ad, the following delegate is called:

didFailOguryInterstitialAdWithError(_ error: OguryError, for interstitial: OguryInterstitialAd)

The parameters of this callback are the following:

  • error: the error which occurred while trying to display the ad. Error codes are explained below.

  • interstitial: the Interstitial Ad for which the error occurred.

Step 4: Test your integration

Ogury exclusively serves ads to users who have given consent. It is essential to have responded to a valid TCFv2 consent form before conducting any tests.

As our algorithm works with personified targeting, you may not receive any ad while testing your application.

You can test your integration by adding the suffix _test to your interstitial ad unit id, for more details go to Test your implementation page.

Note that if you have just registered your application in the Ogury Dashboard, it will take around 15 minutes until you can successfully load an ad.

If you are not able to display any Interstitial Ad, we recommend you to log every delegate on OguryInterstitialAdDelegate to follow the lifecycle of the Interstitial Ad.

If you encounter the didFailOguryInterstitialAdWithErrorcallback , you can check the error codes section below to understand the error and get some advice on how to solve the issue.

Advanced topics

Check if an ad is ready to be displayed

Call the following method to check if an Interstitial Ad is ready to be displayed:

interstitialAd?.isLoaded()

If you want to be informed when the ad is ready to be displayed, you can also register a delegate and implement the didLoadOguryInterstitialAd method.

Delegate

The Ogury SDK provides the OguryInterstitialAdDelegate to listen to the lifecycle of an Interstitial Ad instance.

To register a OguryInterstitialAdDelegate, add the following code just after instantiating the OguryInterstitialAd :

interstitialAd?.delegate = self

The OguryInterstitialAdDelegate exposes the following methods:

Error codes

When an ad fails to load or to be displayed, the SDK will call the didFailOguryInterstitialAdWithError callback with one of error code defined in OguryAdsError:

Last updated