Delegate Usage

Overview

The Mediation 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 closed an ad
  • Get the price of the bid that won the auction

SDK Delegates Setup

The Mediation 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 SetupDelegates() {
    //Helium Start Delegate
    HeliumSdk.didStart += didStart;
      
    //Helium Interstitial Ad Delegates
    HeliumSdk.didLoadInterstitial += DidLoadInterstitial;
    HeliumSdk.didShowInterstitial += DidShowInterstitial;
    HeliumSdk.didCloseInterstitial += DidCloseInterstitial;
    HeliumSdk.didWinBidInterstitial += DidWinBidInterstitial;
    HeliumSdk.didClickInterstitial += DidClickInterstitial;
      
    //Helium Rewarded Ad Delegates
    HeliumSdk.didLoadRewarded += DidLoadRewarded;
    HeliumSdk.didShowRewarded += DidShowRewarded;
    HeliumSdk.didCloseRewarded += DidCloseRewarded;
    HeliumSdk.didReceiveReward += DidReceiveReward;
    HeliumSdk.didWinBidRewarded += DidWinBidRewarded;
    HeliumSdk.didClickRewarded += DidClickRewarded;
      
    //Helium Banner Ad Delegates
    HeliumSdk.didLoadBanner += DidLoadBanner;
    HeliumSdk.didShowBanner += DidShowBanner;
    HeliumSdk.didWinBidBanner += DidWinBidBanner;
    HeliumSdk.didClickBanner += DidClickBanner;
}
void SetupDelegates() {
    //Helium Start Delegate
    HeliumSdk.didStart += didStart;
      
    //Helium Interstitial Ad Delegates
    HeliumSdk.didLoadInterstitial += DidLoadInterstitial;
    HeliumSdk.didShowInterstitial += DidShowInterstitial;
    HeliumSdk.didCloseInterstitial += DidCloseInterstitial;
    HeliumSdk.didWinBidInterstitial += DidWinBidInterstitial;
    HeliumSdk.didClickInterstitial += DidClickInterstitial;
      
    //Helium Rewarded Ad Delegates
    HeliumSdk.didLoadRewarded += DidLoadRewarded;
    HeliumSdk.didShowRewarded += DidShowRewarded;
    HeliumSdk.didCloseRewarded += DidCloseRewarded;
    HeliumSdk.didReceiveReward += DidReceiveReward;
    HeliumSdk.didWinBidRewarded += DidWinBidRewarded;
    HeliumSdk.didClickRewarded += DidClickRewarded;
      
    //Helium Banner Ad Delegates
    HeliumSdk.didLoadBanner += DidLoadBanner;
    HeliumSdk.didWinBidBanner += DidWinBidBanner;
    HeliumSdk.didClickBanner += DidClickBanner;
}

📘

Note

  • Don’t make cache or show calls inside a delegate indicating that an ad has just failed to load or the universe will implode.
  • Mediation banner ads do not have a didCloseBanner delegate.
  • Not all of the partner sdks have support for the didClick delegate.

You should also make sure to unsubscribe to those same events when appropriate:

void OnDisable() {
    // Remove event handlers
    HeliumSdk.didStart -= didStart;
    HeliumSdk.didLoadInterstitial -= DidLoadInterstitial;
    HeliumSdk.didShowInterstitial -= DidShowInterstitial;
    HeliumSdk.didCloseInterstitial -= DidCloseInterstitial;
    HeliumSdk.didWinBidInterstitial -= DidWinBidInterstitial;
    HeliumSdk.didClickInterstitial -= DidClickInterstitial;
    
  
    HeliumSdk.didLoadRewarded -= DidLoadRewarded;
    HeliumSdk.didShowRewarded -= DidShowRewarded;
    HeliumSdk.didCloseRewarded -= DidCloseRewarded;
    HeliumSdk.didReceiveReward -= DidReceiveReward;
    HeliumSdk.didWinBidRewarded -= DidWinBidRewarded;
    HeliumSdk.didClickRewarded -= DidClickRewarded;
  
    //Helium Banner Ad Delegates
    HeliumSdk.didLoadBanner -= DidLoadBanner;
    HeliumSdk.didWinBidBanner -= DidWinBidBanner;
    HeliumSdk.didClickBanner -= DidClickBanner;
}
void OnDisable() {
    // Remove event handlers
    HeliumSdk.didStart -= didStart;
    HeliumSdk.didLoadInterstitial -= DidLoadInterstitial;
    HeliumSdk.didShowInterstitial -= DidShowInterstitial;
    HeliumSdk.didCloseInterstitial -= DidCloseInterstitial;
    HeliumSdk.didWinBidInterstitial -= DidWinBidInterstitial;
    HeliumSdk.didClickInterstitial -= DidClickInterstitial;
    
  
    HeliumSdk.didLoadRewarded -= DidLoadRewarded;
    HeliumSdk.didShowRewarded -= DidShowRewarded;
    HeliumSdk.didCloseRewarded -= DidCloseRewarded;
    HeliumSdk.didReceiveReward -= DidReceiveReward;
    HeliumSdk.didWinBidRewarded -= DidWinBidRewarded;
    HeliumSdk.didClickRewarded -= DidClickRewarded;
  
    //Helium Banner Ad Delegates
    HeliumSdk.didLoadBanner -= DidLoadBanner;
    HeliumSdk.didShowBanner -= DidShowBanner;
    HeliumSdk.didWinBidBanner -= DidWinBidBanner;
    HeliumSdk.didClickBanner -= DidClickBanner;
}

Delegate Methods

// Helium Start Delegate
void didStart(HeliumError error) {
    Debug.Log(string.Format("didStart with error: {0}", error));
}
  
/**
  Helium Interstitial Delegates
*/
void DidLoadInterstitial(string placementName, HeliumError error) {
    Debug.Log(string.Format("didLoadInterstitial {0}: {1}", placementName, error));
}
  
void DidShowInterstitial(string placementName, HeliumError error) {
    Debug.Log(string.Format("didShowInterstitial {0}: {1}", placementName, error));
}
  
void DidCloseInterstitial(string placementName, HeliumError error) {
    Debug.Log(string.Format("didCloseInterstitial {0}: {1}", placementName, error));
}
  
void DidWinBidInterstitial(string placementName, HeliumBidInfo info) {
    AddLog(string.Format("didWinBidInterstitial {0}: ${1:0.####}", placementName, info.Price));
}
  
void DidClickInterstitial(string placementName, HeliumError error)
{
    Log(string.Format("didClickInterstitial {0}: {1}", placementName, error));
}
  
/**
  Helium Rewarded Delegates
*/
void DidLoadRewarded(string placementName, HeliumError error) {
    Debug.Log(string.Format("didLoadRewarded {0}: {1}", placementName, error));
}
  
void DidShowRewarded(string placementName, HeliumError error) {
    Debug.Log(string.Format("didShowRewarded {0}: {1}", placementName, error));
}
  
void DidCloseRewarded(string placementName, HeliumError error) {
    Debug.Log(string.Format("didCloseRewarded {0}: {1}", placementName, error));
}
  
void DidReceiveReward(string reward) {
    Debug.Log(string.Format("didReceiveReward {0}", reward));
}
  
void DidWinBidRewarded(string placementName, HeliumBidInfo info) {
    AddLog(string.Format("didWinBidRewarded {0}: ${1:0.####}", placementName, info.Price));
}
  
void DidClickRewarded(string placementName, HeliumError error)
{
    Log(string.Format("didClickRewarded {0}: {1}", placementName, error));
}
  
/**
  Helium Banner Delegates
*/
void DidLoadBanner(string placementName, HeliumError error)
{
    Debug.Log(string.Format("didLoadBanner {0}: {1}", placementName, error));
}
  
void DidWinBidBanner(string placementName, HeliumBidInfo info)
{
    Debug.Log(string.Format("didWinBidBanner {0}: ${1:0.####}", placementName, info.Price));
}
  
void DidClickBanner(string placementName, HeliumError error)
{
    Log(string.Format("didClickBanner {0}: {1}", placementName, error));
// Helium Start Delegate
void didStart(HeliumError error) {
    Debug.Log(string.Format("didStart with error: {0}", error));
}
  
/**
  Helium Interstitial Delegates
*/
void DidLoadInterstitial(string placementName, HeliumError error) {
    Debug.Log(string.Format("didLoadInterstitial {0}: {1}", placementName, error));
}
  
void DidShowInterstitial(string placementName, HeliumError error) {
    Debug.Log(string.Format("didShowInterstitial {0}: {1}", placementName, error));
}
  
void DidCloseInterstitial(string placementName, HeliumError error) {
    Debug.Log(string.Format("didCloseInterstitial {0}: {1}", placementName, error));
}
  
void DidWinBidInterstitial(string placementName, HeliumBidInfo info) {
    AddLog(string.Format("didWinBidInterstitial {0}: ${1:0.####}", placementName, info.Price));
}
  
void DidClickInterstitial(string placementName, HeliumError error)
{
    Log(string.Format("didClickInterstitial {0}: {1}", placementName, error));
}
  
/**
  Helium Rewarded Delegates
*/
void DidLoadRewarded(string placementName, HeliumError error) {
    Debug.Log(string.Format("didLoadRewarded {0}: {1}", placementName, error));
}
  
void DidShowRewarded(string placementName, HeliumError error) {
    Debug.Log(string.Format("didShowRewarded {0}: {1}", placementName, error));
}
  
void DidCloseRewarded(string placementName, HeliumError error) {
    Debug.Log(string.Format("didCloseRewarded {0}: {1}", placementName, error));
}
  
void DidReceiveReward(string reward) {
    Debug.Log(string.Format("didReceiveReward {0}", reward));
}
  
void DidWinBidRewarded(string placementName, HeliumBidInfo info) {
    AddLog(string.Format("didWinBidRewarded {0}: ${1:0.####}", placementName, info.Price));
}
  
void DidClickRewarded(string placementName, HeliumError error)
{
    Log(string.Format("didClickRewarded {0}: {1}", placementName, error));
}
  
/**
  Helium Banner Delegates
*/
void DidLoadBanner(string placementName, HeliumError error)
{
    Debug.Log(string.Format("didLoadBanner {0}: {1}", placementName, error));
}
  
void DidShowBanner(string placementName, HeliumError error)
{
    Debug.Log(string.Format("didShowBanner {0}: {1}", placementName, error));
}
  
void DidWinBidBanner(string placementName, HeliumBidInfo info)
{
    Debug.Log(string.Format("didWinBidBanner {0}: ${1:0.####}", placementName, info.Price));
}
  
void DidClickBanner(string placementName, HeliumError error)
{
    Log(string.Format("didClickBanner {0}: {1}", placementName, error));