Overview
The Chartboost SDK’s delegate methods allow you to exercise a greater degree of control over your integration. For example, you can:
- Log debug messages when your game attempts to load an interstitial.
- Prevent ads from showing the first time a user plays your game.
- Determine whether a user has clicked an ad or just closed it – and react accordingly.
- Prevent an interstitial page appearing when and where it would interfere with your game.
SDK configuration methods
Click here to view Unity configuration methods.
▲ Back to top
SDK delegate setup
The Chartboost Unity SDK implements its delegate functionality using C# style delegates and events. Before using any of the delegate methods, you should first subscribe to the relevant SDK events in your MonoBehaviour as demonstrated:
void OnEnable() { // Listen to all impression-related events Chartboost.didFailToLoadInterstitial += didFailToLoadInterstitial; Chartboost.didDismissInterstitial += didDismissInterstitial; Chartboost.didCloseInterstitial += didCloseInterstitial; Chartboost.didClickInterstitial += didClickInterstitial; Chartboost.didCacheInterstitial += didCacheInterstitial; Chartboost.shouldDisplayInterstitial += shouldDisplayInterstitial; Chartboost.didDisplayInterstitial += didDisplayInterstitial; Chartboost.didFailToRecordClick += didFailToRecordClick; Chartboost.didFailToLoadRewardedVideo += didFailToLoadRewardedVideo; Chartboost.didDismissRewardedVideo += didDismissRewardedVideo; Chartboost.didCloseRewardedVideo += didCloseRewardedVideo; Chartboost.didClickRewardedVideo += didClickRewardedVideo; Chartboost.didCacheRewardedVideo += didCacheRewardedVideo; Chartboost.shouldDisplayRewardedVideo += shouldDisplayRewardedVideo; Chartboost.didCompleteRewardedVideo += didCompleteRewardedVideo; Chartboost.didDisplayRewardedVideo += didDisplayRewardedVideo; Chartboost.didPauseClickForConfirmation += didPauseClickForConfirmation; Chartboost.willDisplayVideo += willDisplayVideo; #if UNITY_IPHONE Chartboost.didCompleteAppStoreSheetFlow += didCompleteAppStoreSheetFlow; #endif }
Don’t make cache or show calls inside
You should also make sure to unsubscribe to those same events when appropriate:
didFailToLoad
delegates or the universe will implode.void OnDisable() { // Remove event handlers Chartboost.didFailToLoadInterstitial -= didFailToLoadInterstitial; Chartboost.didDismissInterstitial -= didDismissInterstitial; Chartboost.didCloseInterstitial -= didCloseInterstitial; Chartboost.didClickInterstitial -= didClickInterstitial; Chartboost.didCacheInterstitial -= didCacheInterstitial; Chartboost.shouldDisplayInterstitial -= shouldDisplayInterstitial; Chartboost.didDisplayInterstitial -= didDisplayInterstitial; Chartboost.didFailToRecordClick -= didFailToRecordClick; Chartboost.didFailToLoadRewardedVideo -= didFailToLoadRewardedVideo; Chartboost.didDismissRewardedVideo -= didDismissRewardedVideo; Chartboost.didCloseRewardedVideo -= didCloseRewardedVideo; Chartboost.didClickRewardedVideo -= didClickRewardedVideo; Chartboost.didCacheRewardedVideo -= didCacheRewardedVideo; Chartboost.shouldDisplayRewardedVideo -= shouldDisplayRewardedVideo; Chartboost.didCompleteRewardedVideo -= didCompleteRewardedVideo; Chartboost.didDisplayRewardedVideo -= didDisplayRewardedVideo; Chartboost.didPauseClickForConfirmation -= didPauseClickForConfirmation; Chartboost.willDisplayVideo -= willDisplayVideo; #if UNITY_IPHONE Chartboost.didCompleteAppStoreSheetFlow -= didCompleteAppStoreSheetFlow; #endif }
Don’t make cache or show calls inside
Feel free to subscribe to all events as above, or just the ones you need. Then proceed to implement the relevant delegate methods to handle responses to each event.
▲ Back to top
didFailToLoad
delegates or the universe will implode.Static & video interstitial delegate methods
// Called before an interstitial will be displayed on the screen. bool shouldDisplayInterstitial(CBLocation location) // Called after an interstitial has been displayed on the screen. void didDisplayInterstitial(CBLocation location) // Called after an interstitial has been loaded from the Chartboost API // servers and cached locally. void didCacheInterstitial(CBLocation location) // Called after an interstitial has attempted to load from the Chartboost API // servers but failed. void didFailToLoadInterstitial(CBLocation location, CBImpressionError error) // Called after an interstitial has been dismissed. void didDismissInterstitial(CBLocation location) // Called after an interstitial has been closed. void didCloseInterstitial(CBLocation location) // Called after an interstitial has been clicked. didClickInterstitial(CBLocation location)
Don’t make cache or show calls inside
Note: “didDisplayInterstitial” and “didDisplayRewardedVideo” are deprecated from Unity Android, we advise to use “willDisplayVideo”, “shouldDisplayInterstitial”, “shouldDisplayRewardedVideo” based on your needs instead
▲ Back to top
didFailToLoad
delegates or the universe will implode.Rewarded video delegate methods
// Called before a rewarded video will be displayed on the screen. bool shouldDisplayRewardedVideo(CBLocation location) // Called after a rewarded video has been displayed on the screen. void didDisplayRewardedVideo(CBLocation location) // Called after a rewarded video has been loaded from the Chartboost API // servers and cached locally. void didCacheRewardedVideo(CBLocation location) // Called after a rewarded video has attempted to load from the Chartboost API // servers but failed. void didFailToLoadRewardedVideo(CBLocation location, CBImpressionError error) // Called after a rewarded video has been dismissed. void didDismissRewardedVideo(CBLocation location) // Called after a rewarded video has been closed. void didCloseRewardedVideo(CBLocation location) // Called after a rewarded video has been clicked. void didClickRewardedVideo(CBLocation location) // Called after a rewarded video has been viewed completely and user is eligible for reward. void didCompleteRewardedVideo(CBLocation location, int reward) // Implement to be notified of when a video will be displayed on the screen for // a given CBLocation. You can then do things like mute effects and sounds. void willDisplayVideo(CBLocation location)
Don’t make cache or show calls inside
▲ Back to top
didFailToLoad
delegates or the universe will implode.Misc. delegate methods
// Called after the App Store sheet is dismissed, when displaying the embedded app sheet. // iOS only void didCompleteAppStoreSheetFlow() // Called after a click is registered, but the user is not forwarded to the App Store. void didFailToRecordClick(CBLocation location, CBImpressionError error) //Called after the SDK has been successfully initialized and video prefetching has been completed. void didInitialize(bool status)
Don’t make cache or show calls inside
▲ Back to top
didFailToLoad
delegates or the universe will implode.Age gate delegate methods
// Decide if Chartboost SDK should block for an age gate. public static void setShouldPauseClickForConfirmation(bool shouldPause) // Called if Chartboost SDK pauses click actions awaiting confirmation from the user. Use // to implement an age gate in your game. void didPauseClickForConfirmation() // Confirm if an age gate passed or failed. When specified Chartboost will wait for // this call before showing the IOS App Store. public static void didPassAgeGate(bool pass)
Don’t make cache or show calls inside
▲ Back to top
didFailToLoad
delegates or the universe will implode.Last Updated on March 11, 2020