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.
You have registered an application on your Ogury Dashboard. If not, please refer to the Getting Started section before the next steps.
- Click on the Monetization settings in the left-menu.
- Copy the Ad unit id as you will need this information later to finish the integration.
In all the following code samples, we will refer to this Ad unit id by using the string
AD_UNIT_ID
.The Ogury SDK provides the
OguryInterstitialAd
object that lets you load, display and control your Interstitial Ads.- Declare a
OguryInterstitialAd
instance variable in theViewController
where you want to display an Interstitial Ads:
Swift
Objective-C
var interstitialAd: OguryInterstitialAd?
@property (nonatomic, strong) OguryInterstitialAd *interstitialAd;
- In the
viewDidLoad
method of theViewController
, instantiate the Interstitial Ad:
Swift
Objective-C
override func viewDidLoad() {
super.viewDidLoad()
self.interstitialAd = OguryInterstitialAd(adUnitId: "AD_UNIT_ID")
}
- (void)viewDidLoad {
[super viewDidLoad];
self.interstitialAd = [[OguryInterstitialAd alloc] initWithAdUnitId:@"AD_UNIT_ID"];
}
OguryInterstitialAd
takes 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.
To start loading an ad, call the
load
method:Swift
Objective-C
interstitialAd?.load()
[self.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 thestart
method in theViewController
that collects the consent:
Swift
Objective-C
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()
}
}
#import "ViewController.h"
#import <OgurySdk/Ogury.h>
#import <OguryAds/OguryAds.h>
#import <OguryChoiceManager/OguryChoiceManager.h>
@interface ViewController ()
@property (nonatomic, strong) OguryInterstitialAd *interstitialAd;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
OguryConfigurationBuilder *configurationBuilder = [[OguryConfigurationBuilder alloc] initWithAssetKey:@"OGY-XXXXXXXXXXXX"];
[Ogury startWithConfiguration:[configurationBuilder build]];
self.interstitialAd = [[OguryInterstitialAd alloc] initWithAdUnitId:@"AD_UNIT_ID"];
[self.interstitialAd load];
}
@end
- Call the
load
method in theviewDidLoad
of your otherViewController
:
Swift
Objective-C
override func viewDidLoad() {
super.viewDidLoad()
interstitialAd = OguryInterstitialAd(adUnitID: "AD_UNIT_ID")
interstitialAd?.load()
}
- (void)viewDidLoad {
[super viewDidLoad];
self.interstitialAd = [[OguryInterstitialAd alloc] initWithAdUnitID:@"AD_UNIT_ID"];
[self.interstitialAd load];
}
Additionally, if you want to follow the lifecycle of the Interstitial Ad, you can register a delegate.
To display the ad, call
show
method:Swift
Objective-C
self.interstitialAd?.show(in: self)
[self.interstitialAd showAdInViewController:self];
The
show
method takes the following parameter:- a reference to the
ViewController
where you will show the Interstitial Ad.
Swift
Objective-C
didFailOguryInterstitialAdWithError(_ error: OguryError, for interstitial: OguryInterstitialAd)
didFailOguryInterstitialAdWithError:(OguryError *)error forAd:(OguryInterstitialAd *)interstitial
The parameters of this callback are the following:
interstitial
: the Interstitial Ad for which the error occurred.
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
didFailOguryInterstitialAdWithError
callback , you can check the error codes section below to understand the error and get some advice on how to solve the issue.Call the following method to check if an Interstitial Ad is ready to be displayed:
Swift
Objective-C
interstitialAd?.isLoaded()
[self.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.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
:Swift
Objective C
interstitialAd?.delegate = self
self.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. |
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 modified 11mo ago