Ad callbacks
Before you start to set up your ads, it is important to understand the ad callbacks available in the AwesomeAds SDK.
Banner ads, interstitial ads, and video ads all send a number of callbacks to notify you of important lifecycle events, enabling you to perform specific actions when those events occur.
For example, you can use the adLoaded
callback to play an ad as soon as it is loaded. Alternatively, you might wish to run some other custom code when you get the adLoaded
callback.
Callbacks versus methods
In some situations, you may need to choose between using a callback or a method. In general, it is recommended that you use a callback when you need to respond immediately to an event.
For example, to play an ad, you can use either the adLoaded
callback or the HasAdAvailable
method.
- If you want to play the ad as soon as it is loaded, it is recommended that you use the
adLoaded
callback. - If you want to load the ad at one point (for example, when the game starts) but not play it until some later stage, use the
HasAdAvailable
method.
For more information, see banner ad, interstitial ad, video ad.
Also see the examples:
- Set up a banner ad using the ‘adLoaded’ callback
- Set up multiple ads using the ‘HasAdAvailable’ method
AwesomeAds ad callbacks
These are all the ad callbacks available in the AwesomeAds SDK:
SAVideoAd.setCallback ((placementId, evt) => {
switch (evt) {
case SAEvent.adLoaded: // When an ad has finished loading
break;
case SAEvent.adEmpty: // When the request was successful but the server returned no ad
break;
case SAEvent.adFailedToLoad: // When an ad could not be loaded
break;
case SAEvent.adAlreadyLoaded: // called when the ad was previously loaded for the given creativeId
break;
case SAEvent.adShown: // When an ad is first shown
break;
case SAEvent.adFailedToShow: // When an ad fails to show
break;
case SAEvent.adClicked: // When an ad is clicked
break;
case SAEvent.adEnded: // When a video ad has ended playing (but hasn't yet closed)
break;
case SAEvent.adClosed: // When a fullscreen ad is closed
break;
case SAEvent.adPaused: // When the video ad is paused
break;
case SAEvent.adPlaying: // When the video ad starts or resumes playing
break;
}
});