Ad Event Listener
To be notified about ad events such as ad was delivered or ad request failed, a listener/delegate can be used.
For Android there is only a single listener type SevenOneAdsListener
which can be used for both display and overlay ads. However, for iOS there is two types: SevenOneAdsDelegate
and SevenOneAdsOverlayDelegate
used for display and overlay ads respectively.
// Create an ad listener object
val adListener = object: SevenOneAdsListener {
override fun onAdLoaded() {
super.onAdLoaded()
}
override fun onAdFailedToLoad(errorCode: Int) {
super.onAdFailedToLoad(errorCode)
}
override fun onAdOpened() {
super.onAdOpened()
}
override fun onAdClicked() {
super.onAdClicked()
}
override fun onAdClosed() {
super.onAdClosed()
}
override fun onAdLeftApplication() {
super.onAdLeftApplication()
}
override fun onFrequencyCappingReached() {
super.onFrequencyCappingReached()
}
}
// Add the listener to a display ad
bannerAd.adListener = adListener
// Add the listener to an overlay ad
SevenOneAds.displayOverlay(adListener)
class DisplayAdDelegate: SevenOneAdsDelegate {
// Tells the delegate an ad request loaded an ad.
func adContainerDidReceiveAd(adContainer: SomAdContainer) {
}
// Tells the delegate an ad request failed.
func adContainerDidFailToReceiveAd(adContainer: SomAdContainer, error: String) {
}
// Tells the delegate that a full-screen view will be presented in response
// to the user clicking on an ad.
func adContainerWillPresentScreen(adContainer: SomAdContainer) {
}
// Tells the delegate that the full-screen view will be dismissed.
func adContainerWillDismissScreen(adContainer: SomAdContainer) {
}
// Tells the delegate that the full-screen view has been dismissed.
func adContainerDidDismissScreen(adContainer: SomAdContainer) {
}
// Tells the delegate that a user click will open another app (such as
// the App Store), backgrounding the current app.
func adContainerWillLeaveApplication(adContainer: SomAdContainer) {
}
}
// Create a display ad delegate
let adDelegate = DisplayAdDelegate()
// Add the delegate to a display ad
ad.delegate = adDelegate
class OverlayAdDelegate: SevenOneAdsOverlayDelegate {
// Tells the delegate an ad request succeeded.
func overlayDidReceiveAd(overlayContainer: OverlayContainer) {
}
// Tells the delegate an ad request failed.
func overlayDidFailToReceiveAd(overlayContainer: OverlayContainer, error: String) {
}
// Tells the delegate that an interstitial will be presented.
func overlayWillPresentScreen(overlayContainer: OverlayContainer) {
}
// Tells the delegate the interstitial is to be animated off the screen.
func overlayWillDismissScreen(overlayContainer: OverlayContainer) {
}
// Tells the delegate the interstitial had been animated off the screen.
func overlayDidDismissScreen(overlayContainer: OverlayContainer) {
}
// Tells the delegate that a user click will open another app
// (such as the App Store), backgrounding the current app.
func overlayWillLeaveApplication(overlayContainer: OverlayContainer) {
}
// Tells the delegate that the reason why there is no overlay delivered
// is because the frequency capping has been reached.
func frequencyCappingReached() {
}
}
// Create an overlay ad delegate
let overlayDelegate = OverlayAdDelegate()
// Add the delegate to an overlay request
SevenOneAds.shared.displayOverlay(uiController: self, delegate: overlayDelegate)