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.

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.

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:

Methods

Definition

didLoadOguryInterstitialAd

The SDK is ready to display the ad provided by the ad server.

didDisplayOguryInterstitialAd

The ad has been displayed on the screen.

didClickOguryInterstitialAd

The as has been clicked by the user.

didCloseOguryInterstitialAd

The ad has been closed by the user.

didFailOguryInterstitialAdWithError

The ad failed to load or display. The error parameter contains the reason of the failure. All error codes are detailed in the section below.

didTriggerImpressionOguryInterstitialAd

The ad has triggered an impression.

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:

Name

Value

Definition

OguryCoreErrorTypeNoInternetConnection

0

No Internet connection

The device has no Internet connection. Try again once the device is connected to the Internet.

OguryAdsAdDisabledError

2001

Ad disabled

Ad serving has been disabled for this placement/application.

OguryAdsProfigNotSyncedError

2002

Profig not synchronized

An internal SDK error has occurred.

OguryAdsAdExpiredError

2003

Ad expired

The loaded ad is expired. You must call the show method within 4 hours after the load.

OguryAdsSdkInitNotCalledError

2004

SDK init not called

The Ogury.start() method has not been called before a call to the load or show methods.

OguryAdsAnotherAdAlreadyDisplayedError

2005

Another ad already displayed

Another ad is already displayed on the screen.

OguryAdsAssetKeyNotValidError

2006

SDK init failed

An error occurred during the initialization of the SDK.

OguryAdsNotAvailableError

2008

Ad not available

The server returns no ads.

OguryAdsCantShowAdsInPresentingViewControllerError

2010

A view controller is already being presented

Only one view controller may be presented at a time.

OguryAdsUnknownError

2011

Unknown error

An unknown error occurred.

Last updated