Setting up Monetisation

Advertisement Module is responsible for handling all ad-related procedures for banner, interstitial, and rewarded ads.

Banner Ads

How to show a banner ad?

// To show a banner ad you can use this API call.

CodaGameManager.Instance.AdManager.ShowBannerAd();

// Optionally you can set banner position & dimensions

CodaGameManager.Instance.AdManager.ShowBannerAd(MoPub.AdPosition.BottomCenter, MoPub.MaxAdSize.Width320Height50);

🚧

Banner Auto Refreshing

Note that Coda SDK will be automatically refreshing banners once you call ShowBannerAd. You do not need to call this function again unless you hide the banner.

How to hide a banner ad?

// If you want to hide the banner ad you can use this API call 

CodaGameManager.Instance.AdManager.HideBannerAd();

How to subscribe/unsubscribe to banner ad events?

// Banner Ad Requested Event will be fired when Coda SDK makes a banner ad request to Mopub. 

void SubscribeBannerAdRequested(OnBannerAdRequested callback);
void UnsubscribeBannerAdRequested(OnBannerAdRequested callback);

// Banner Ad Loaded or Failed event will be fired when mopub responses to a banner request event or auto refresh requests.

void SubscribeBannerAdLoaded(OnBannerAdLoaded callback);
void SubscribeBannerAdFailed(OnBannerAdFailed callback);
void UnsubscribeBannerAdLoaded(OnBannerAdLoaded callback);
void UnsubscribeBannerAdFailed(OnBannerAdFailed callback);

// Banner Impression Event will be fired when the banner is shown to the player. 
// This will happen right after you receieve a Banner Ad Loaded event if the Banner Ads are visible.

void SubscribeBannerImpression(OnBannerAdImpression callback);
void UnsubscribeBannerImpression(OnBannerAdImpression callback);

// Banner Ad Clicked Event will be fired when the user click on the banner

void SubscribeBannerAdClicked(OnBannerAdClicked callback);
void UnsubscribeBannerAdClicked(OnBannerAdClicked callback);

// Banner Ad Visibility Changed event will be fired when you change the banner visibility.
// you can change visibility by calling ShowBannerAd or HideBannerAd APIs.

void SubscribeBannerVisibilityChanged(BannerVisibilityChangeDelegate callback);
void UnsubscribeBannerVisibilityChanged(BannerVisibilityChangeDelegate callback);

// How to subscribe/unsubscribe these events ?
CodaGameManager.Instance.AdManager.SubscribeBannerAdRequested(myCallback);
CodaGameManager.Instance.AdManager.UnsubscribeBannerAdRequested(myCallback);

📘

Tracking of banner ad events

Note That all of these events are automatically tracked by Coda SDK via supported platforms. Currently, we are tracking these events with Game Analytics, Firebase Analytics, and Coda Platform Analytics. No additional code required to track these events.

Interstitial Ads

How to check if an interstitial ad is ready to be shown?

// This function will return true if an interstitial ad is loaded and it is ready to be shown, false otherwise.

CodaGameManager.Instance.AdManager.InterstitialAdReadyToShow();

How to show an interstitial ad?

// This function will attempt to show an interstitial ad.
// Returns true if the Coda SDK was able to show an interstitial ad, false otherwise.

CodaGameManager.Instance.AdManager.ShowInterstitialAd();

📘

When does Coda SDK fails to show an interstitial ad ?

Showing an interstitial ad might not be possible due to the following reasons

  1. There is no interstitial ad ready to be shown.
  2. Ad ruleset that was provided via remote configuration is not satisfied. An Example ad rule is Show maximum of 1 interstitial in every 60 seconds of gameplay. You can set these rules via remote config configurations. Please check AB Testing Integration section to see how.

❗️

Important Notice

Please do not introduce your own interstitial ad showing ruleset since it can be conflicting with Coda SDK remote configuration and resulting in no interstitial ad showing. Simply call show interstitial after every core game cycle without any custom logic.

How to subscribe/unsubscribe to interstitial ad events?

// Interstitial Ad Requested event will be fired once Coda SDK makes a request to Mopub to load an interstitial ad.

void SubscribeInterstitialAdRequested(OnInterstitialAdRequested callback);
void UnsubscribeInterstitialAdRequested(OnInterstitialAdRequested callback);

// Interstitial Ad Loaded&Failed events will be fired once Mopub responses to Coda SDK after a load request.

void SubscribeInterstitialAdLoaded(OnInterstitialAdLoaded callback);
void SubscribeInterstitialAdFailed(OnInterstitialAdFailed callback);
void UnsubscribeInterstitialAdLoaded(OnInterstitialAdLoaded callback);
void UnsubscribeInterstitialAdFailed(OnInterstitialAdFailed callback);

// Interstitial Ad Impression event will be fired when the loaded interstitial ad is shown to user. 
// Note that this event will be catched once app is resumed.

void SubscribeInterstitialAdImpression(OnInterstitialAdImpression callback);
void UnsubscribeInterstitialAdImpression(OnInterstitialAdImpression callback);

// Interstitial Ad Clicked event will be fired when player clicks the interstitial ad while it is being showed.

void SubscribeInterstitialAdClicked(OnInterstitialAdClicked callback);
void UnsubscribeInterstitialAdClicked(OnInterstitialAdClicked callback);

// Interstitial Ad Dismissed event will be fired when user clicks x button to close the ad. 
// This event will be fired regardless of player watched the ad until the end or not.

void SubscribeInterstitialAdDismissed(OnInterstitialAdDismissed callback);
void UnsubscribeInterstitialAdDismissed(OnInterstitialAdDismissed callback); 

// Interstitial Ad Expired event will be fired once a certain amount of time is passed after loading an intersitial ad without shoing it.
// Expiration time varies depending on which network the intersitial ad was loaded from.

void SubscribeInterstitialAdExpired(OnInterstitialAdExpired callback);
void UnsubscribeInterstitialAdExpired(OnInterstitialAdExpired callback);

// Interstitial Ad Finished event will be fired once everything regarding interstitial event is finished. 
// This is a helper event to understand when to continue your game logic.
// An interstitial event might finish with expiration/failed to watch video/dismissed etc. 
// To avoid subscribing all of these events you can simply use this event to detect when to continue your game logic.

void SubscribeInterstitialAdFinished(OnInterstitialAdFinished callback);
void UnsubscribeInterstitialAdFinished(OnInterstitialAdFinished callback);

// How to subscribe/unsubscribe these events ?
CodaGameManager.Instance.AdManager.SubscribeInterstitialAdLoaded(myCallback);
CodaGameManager.Instance.AdManager.UnsubscribeInterstitialAdLoaded(myCallback);

📘

Tracking of interstitial ad events

Note That all of these events are automatically tracked by Coda SDK via supported platforms. Currently, we are tracking these events with Game Analytics, Firebase Analytics, and Coda Platform Analytics. No additional code required to track these events.

Rewarded Ads

How to check if a rewarded ad is ready to be shown?

// This function will return true if a rewarded ad is loaded and it is ready to be shown, false otherwise.

CodaGameManager.Instance.AdManager.RewardedAdReadyToShow();

How to show a rewarded ad?

// This function will attempt to show a rewarded video ad.
// Returns true if the Coda SDK was able to show a rewarded ad, false if there is no rewarded ad ready to be shown.
// It takes a string parameter context to track the rewarded placement.
CodaGameManager.Instance.AdManager.ShowRewardedAd("ExtraLife");

🚧

Rewarded Ad Context Parameter

In a game, there might be multiple places to initiate a rewarded ad video. Please do not leave rewarded ad-context empty. This will prevent us from tracking for which placement the player was watching the rewarded ad. You can enter a descriptive tag as a string like "Extra-Life" or "Daily-Coin-Prize"

How to subscribe/unsubscribe to rewarded ad events?

// Rewarded Ad Requested event will be fired once Coda SDK makes a request to Mopub to load a rewarded ad.
void SubscribeRewardedAdRequested(OnRewardedAdRequested callback);
void UnsubscribeRewardedAdRequested(OnRewardedAdRequested callback);

// Rewarded Ad Loaded&Failed events will be fired once Mopub responses to Coda SDK after a load request.
void SubscribeRewardedAdLoaded(OnRewardedAdLoaded callback);
void SubscribeRewardedAdFailed(OnRewardedAdFailed callback);
void UnsubscribeRewardedAdLoaded(OnRewardedAdLoaded callback);
void UnsubscribeRewardedAdFailed(OnRewardedAdFailed callback);

// Rewarded Ad Impression event will be fired when the loaded rewarded ad is shown to user. 
// Note that this event will be catched once app is resumed.

void SubscribeRewardedAdImpression(OnRewardedAdImpression callback);
void UnsubscribeRewardedAdImpression(OnRewardedAdImpression callback);

// Rewarded Ad Clicked event will be fired when player clicks the rewarded ad while it is being showed.

void SubscribeRewardedAdClicked(OnRewardedAdClicked callback);
void UnsubscribeRewardedAdClicked(OnRewardedAdClicked callback);

// Rewarded Ad Dismissed event will be fired when user clicks x button to close the ad. 
// This event will be fired regardless of player watched the ad until the end or not.

void SubscribeRewardedAdDismissed(OnRewardedAdDismissed callback);
void UnsubscribeRewardedAdDismissed(OnRewardedAdDismissed callback);

// Rewarded Ad Expired event will be fired once a certain amount of time is passed after loading a rewarded ad without showing it.
// Expiration time varies depending on which network the intersitial ad was loaded from.
void SubscribeRewardedAdExpired(OnRewardedAdExpired callback);
void UnsubscribeRewardedAdExpired(OnRewardedAdExpired callback);

// Rewarded Ad Rewarded event will be fired if the player watched the ad until the end and earn the reward that was promised.

void SubscribeRewardedAdRewarded(OnRewardedAdRewarded callback);
void UnsubscribeRewardedAdRewarded(OnRewardedAdRewarded callback);

// Rewarded Ad Finished event will be fired once everything regarding rewarded ad event is finished. 
// This is a helper event to understand when to continue your game logic.
// An rewarded ad event might finish with expiration/failed to watch video/dismissed etc. 
// To avoid subscribing all of these events you can simply use this event to detect when to continue your game logic.

void SubscribeRewardedAdFinished(OnRewardedAdFinished callback);
void UnsubscribeRewardedAdFinished(OnRewardedAdFinished callback);

// How to subscribe/unsubscribe these events ?
CodaGameManager.Instance.AdManager.SubscribeRewardedAdImpression(myCallback);
CodaGameManager.Instance.AdManager.UnsubscribeRewardedAdImpression(myCallback);

📘

Tracking of rewarded ad events

Note That all of these events are automatically tracked by Coda SDK via supported platforms. Currently, we are tracking these events with Game Analytics, Firebase Analytics, and Coda Platform Analytics. No additional code required to track these events.

❗️

Important Notice

When you assign a callback to an Advertisement Event they are not going to be called from the main thread. So you can only call thread-safe operations from these callbacks. Please check operations that are not thread-safe in Unity 3D such as changing a transform component of a Unity GameObject.


What’s Next

Please continue with integrating A/B Testing Module from the link below

Did this page help you?