Using MCSDK, you can load multiple ad placements of mediation SDKs at the same time, and give priority to the ad slot with the highest price among these successfully loaded ad placements when the ad is displayed.
Note
-
In order to reduce access costs, the API of the SDK is provided based on Max, but there will still be differences. For details, please refer to the document description below.
-
You can use max ad units for loading and display, but you must add a global configuration JSON file to map max ad units, etc., so that the sdk can work properly.
1. Integration
Download the Unity Plugin
Please contact us to obtain sdk
Import the Plugin into Unity
Take the following steps to import the plugin you downloaded:
-
In Unity, select Assets > Import Package > Custom Package…
-
Choose the Unity Plugin file you downloaded.
-
In the Import Unity Package dialog, click Import.
Requirements
-
Either Unity 5.x.x, or Unity 2017.x.x or later. (For Admob, you need to use Unity 2022.3.x or later)
-
For Android builds, the plugin requires that you enable Jetifier. To enable Jetifier, take the following steps:
- In Unity, select Assets > External Dependency Manager > Android Resolver > Settings.
- In the Android Resolver Settings dialog that appears, check Use Jetifier.
- Click OK.
-
For Android builds, the plugin requires that you generate template gradle files. To generate files, take the following steps:
- In Unity, select Project Settings > Player > Publishing Settings.
- Find “Custom Main Gradle Template”、“Custom Gradle Setting Template”、“Custom Gradle Properties Template”, then check them
- select Assets > External Dependency Manager > Android Resolver > Force Resolve
- To access Admob, you must add Admob's APPLICATION_ID. Follow the steps below to add it.
-
- In Unity, select Project Settings > Player > Publishing Settings.
- Find “Custom Launcher Manifest”, then check it
- In the generated file, add the configuration as follows
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:label="@string/app_name"> <!--Admob APPLICATION_ID start--> <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="<your admob application id>" /> <!--Admob APPLICATION_ID end--> </application> </manifest>
-
Call all APIs on the main thread.
2. Add Global Configuration
2.1 Create MCGlobalConfig.json file
Note: mcRes.androidlib below is the name of the folder directory (must include the ".androidlib" suffix)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mcsdk.unity.res">
</manifest>
Create the MCGlobalConfig.json file in the Assets/Plugins/Android/mcRes.androidlib/assets/LocalConfig directory
2.1.2 Below Unity 2021.2
Create the MCGlobalConfig.json file in the Assets/Plugins/Android/assets/LocalConfig directory
2.2 Configure MCGlobalConfig.json
The configuration example of MCGlobalConfig.json is as follows:
{
"init_timeout": <init_timeout_ms>,
"init_params": {
"max": {
"sdk_key": <max_sdk_key>
},
"topon": {
"app_id": <topon_app_id>,
"app_key": <topon_app_key>
}
},
"pl_setting": {
"<max_ad_unit_id_1>": {
"cache_count": 1,
"request_count": -1,
"load_next_ad_interval": 10000,
"group": [
{
"max": <max_ad_unit_id_1>
},
{
"topon": <topon_placement_id_1>
},
{
"max": <max_ad_unit_id_2>
},
{
"topon": <topon_placement_id_2>
}
]
},
......
}
}
Key description in JSON:
| Key | Value | Description | Note |
|---|---|---|---|
| init_timeout | int | init timeout, unit: ms | (optional) default: 5000ms |
| init_params | json object | Each mediation SDK initialization parameters | (required) MCSDK initializes Max SDK and TopOn SDK according to this configuration |
|
|
|||
| pl_setting | json array | The mapping relationship between each advertising placement |
(required) MCSDK loads and displays ads from Max SDK and TopOn SDK based on this configuration. When there are multiple advertising slots, they need to be configured in this json array |
init_params:
| Key | Value | Description | Note |
|---|---|---|---|
| init_params.max.sdk_key | string | Max's sdk key | (required) |
| init_params.topon.app_id | string | TopOn's app id | (required) |
| init_params.topon.app_key | string | TopOn's app key | (required) |
pl_info:(Deprecated, no longer used since v1.1.0, please refer to pl_setting below)
| Key | Value | Description | Note |
|---|---|---|---|
| pl_info.max | string | Max's ad Unit Id | (required) |
| pl_info.topon | string | TopOn’s advertising placement ID | (optional) When TopOn advertising placements need to be loaded together, configuration is required for price comparison display. |
| pl_info.topon_adx | string | TopOn Adx’s advertising placementID | (optional) When TopOn Adx advertising placements need to be loaded together, configuration is required for price comparison display. |
| pl_info.format | - | ad format | (optional) The format is only used to identify this group of ad slots. MCSDK will not use this field. |
pl_setting:Configure the parameters of each max ad unit id's ad group
| Key | Value | Description | Note |
|---|---|---|---|
| <max_ad_unit_id_1> | string | Max's ad Unit Id | (required) |
<max_ad_unit_id_1>:
| Key | Value | Description | Note |
|---|---|---|---|
| cache_count | int | The number of ad placement cached in the ad group. When it is greater than 1, the ad slots will continue to be loaded. | (optional) Default: 1 |
| request_count | int | The number of parallel loads of aggregated ad slots when an ad group is loaded | (Optional) Default: -1 (i.e. all aggregated ad slots initiate loading) |
| load_next_ad_interval | int | If an aggregated ad slot has not returned a loading result after a certain period of time, the next aggregated ad slot will be loaded. | (Optional) Default: 10s |
| group | array | Aggregate ad slot id that needs to be loaded together | (required) |
group:
| Key | Value | Description | Note |
|---|---|---|---|
| max | string | Max's ad Unit Id | (required) |
| topon | string | TopOn’s advertising placement ID | (optional) When TopOn advertising placements need to be loaded together, configuration is required for price comparison display. |
| topon_adx | string | TopOn Adx’s advertising placementID | (optional) When TopOn Adx advertising placements need to be loaded together, configuration is required for price comparison display. |
Note: The order in which the ad slots are written will affect the order in which they are launched.
For example, the following configuration is serial loading. When calling MCSDK to load <max_ad_unit_id_1>, the loading initiation order is <max_ad_unit_id_1>, <topon_placement_id_1>, <topon_placement_id_2>, <max_ad_unit_id_2>
{
...
"pl_setting": {
<max_ad_unit_id_1>: {
"cache_count": 1,
...
"group": [
{
"max": <max_ad_unit_id_1>
},
{
"topon": <topon_placement_id_1>
},
{
"topon": <topon_placement_id_2>
},
{
"max": <max_ad_unit_id_2>
}
]
}
}
}
3. Initialize the SDK
Attach the OnSdkInitializedEventevent handler, then set the SDK key and initialize the SDK as soon as your app launches, as in the following code sample.
McSdkCallbacks.OnSdkInitializedEvent += (McSdkBase.SdkConfiguration sdkConfiguration) => {
// SDK is initialized, start loading ads
};
McSdk.SetUserId("USER_ID");
McSdk.InitializeSdk();
4. Rewarded Ad
Loading a Rewarded Ad
string adUnitId = "YOUR_MAX_AD_UNIT_ID";
int retryAttempt;
public void InitializeRewardedAds()
{
// Attach callbacks
McSdkCallbacks.Rewarded.OnAdLoadedEvent += OnRewardedAdLoadedEvent;
McSdkCallbacks.Rewarded.OnAdLoadFailedEvent += OnRewardedAdFailedEvent;
McSdkCallbacks.Rewarded.OnAdDisplayFailedEvent += OnRewardedAdFailedToDisplayEvent;
McSdkCallbacks.Rewarded.OnAdDisplayedEvent += OnRewardedAdDisplayedEvent;
McSdkCallbacks.Rewarded.OnAdClickedEvent += OnRewardedAdClickedEvent;
McSdkCallbacks.Rewarded.OnAdHiddenEvent += OnRewardedAdDismissedEvent;
McSdkCallbacks.Rewarded.OnAdReceivedRewardEvent += OnRewardedAdReceivedRewardEvent;
McSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnRewardedAdRevenuePaidEvent;
// Load the first rewarded ad
LoadRewardedAd();
}
private void LoadRewardedAd()
{
McSdk.LoadRewardedAd(adUnitId);
}
private void OnRewardedAdLoadedEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
// Rewarded ad is ready for you to show. McSdk.IsRewardedAdReady(adUnitId) now returns 'true'.
// Reset retry attempt
retryAttempt = 0;
}
private void OnRewardedAdLoadFailedEvent(string adUnitId, McSdkBase.ErrorInfo errorInfo)
{
// Rewarded ad failed to load
// recommends that you retry with exponentially higher delays, up to a maximum delay (in this case 64 seconds).
retryAttempt++;
double retryDelay = Math.Pow(2, Math.Min(6, retryAttempt));
Invoke("LoadRewardedAd", (float) retryDelay);
}
private void OnRewardedAdDisplayedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
private void OnRewardedAdFailedToDisplayEvent(string adUnitId, McSdkBase.ErrorInfo errorInfo, McSdkBase.AdInfo adInfo)
{
// Rewarded ad failed to display. Recommends that you load the next ad.
LoadRewardedAd();
}
private void OnRewardedAdClickedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
private void OnRewardedAdHiddenEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
// Rewarded ad is hidden. Pre-load the next ad
LoadRewardedAd();
}
private void OnRewardedAdReceivedRewardEvent(string adUnitId, McSdk.Reward reward, McSdkBase.AdInfo adInfo)
{
// The rewarded ad displayed and the user should receive the reward.
}
private void OnRewardedAdRevenuePaidEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
// Ad revenue paid. Use this callback to track user revenue.
}
Showing a Rewarded Ad
To show a rewarded ad, call ShowRewardedAd():
if (McSdk.IsRewardedAdReady(adUnitId))
{
McSdk.ShowRewardedAd(adUnitId);
}
Accessing the Amount and Currency for a Rewarded Ad
To access the reward amount and currency, override the OnRewardedAdReceivedRewardEvent callback:
private void OnRewardedAdReceivedRewardEvent(string adUnitId, McSdk.Reward reward, McSdkBase.AdInfo adInfo)
{
print("Rewarded user: " + reward.Amount + " " + reward.Label);
}
5. Interstitial Ad
Loading an Interstitial Ad
The following code shows you how to attach listeners and load the first interstitial:
string adUnitId = "YOUR_MAX_AD_UNIT_ID";
public void InitializeInterstitialAds()
{
// Attach callback
McSdkCallbacks.Interstitial.OnAdLoadedEvent += OnInterstitialLoadedEvent;
McSdkCallbacks.Interstitial.OnAdLoadFailedEvent += OnInterstitialLoadFailedEvent;
McSdkCallbacks.Interstitial.OnAdDisplayedEvent += OnInterstitialDisplayedEvent;
McSdkCallbacks.Interstitial.OnAdClickedEvent += OnInterstitialClickedEvent;
McSdkCallbacks.Interstitial.OnAdHiddenEvent += OnInterstitialHiddenEvent;
McSdkCallbacks.Interstitial.OnAdDisplayFailedEvent += OnInterstitialAdFailedToDisplayEvent;
McSdkCallbacks.Interstitial.OnAdRevenuePaidEvent += OnInterstitialRevenuePaidEvent;
// Load the first interstitial
LoadInterstitial();
}
private void LoadInterstitial()
{
McSdk.LoadInterstitial(adUnitId);
}
private void OnInterstitialLoadedEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
// Interstitial ad is ready for you to show. McSdk.IsInterstitialReady(adUnitId) now returns 'true'
// Reset retry attempt
retryAttempt = 0;
}
private void OnInterstitialLoadFailedEvent(string adUnitId, McSdkBase.ErrorInfo errorInfo)
{
// Interstitial ad failed to load
// Recommends that you retry with exponentially higher delays, up to a maximum delay (in this case 64 seconds)
retryAttempt++;
double retryDelay = Math.Pow(2, Math.Min(6, retryAttempt));
Invoke("LoadInterstitial", (float) retryDelay);
}
private void OnInterstitialDisplayedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
private void OnInterstitialAdFailedToDisplayEvent(string adUnitId, McSdkBase.ErrorInfo errorInfo, McSdkBase.AdInfo adInfo)
{
// Interstitial ad failed to display. Recommends that you load the next ad.
LoadInterstitial();
}
private void OnInterstitialClickedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
private void OnInterstitialHiddenEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
// Interstitial ad is hidden. Pre-load the next ad.
LoadInterstitial();
}
private void OnInterstitialRevenuePaidEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
// Ad revenue paid. Use this callback to track user revenue.
}
Showing an Interstitial Ad
To show an interstitial ad, call ShowInterstitial():
if ( McSdk.IsInterstitialReady(adUnitId) )
{
McSdk.ShowInterstitial(adUnitId);
}
6. AppOpen Ad
Loading an App Open Ad
The following code shows you how to attach listeners and load the first app open ad:
string adUnitId = "YOUR_MAX_AD_UNIT_ID";
private void InitializeAppOpenAds()
{
// Attach callbacks
McSdkCallbacks.AppOpen.OnAdLoadedEvent += OnAppOpenAdLoadedEvent;
McSdkCallbacks.AppOpen.OnAdLoadFailedEvent += OnAppOpenAdFailedEvent;
McSdkCallbacks.AppOpen.OnAdDisplayFailedEvent += OnAppOpenAdFailedToDisplayEvent;
McSdkCallbacks.AppOpen.OnAdDisplayedEvent += OnAppOpenAdDisplayedEvent;
McSdkCallbacks.AppOpen.OnAdClickedEvent += OnAppOpenAdClickedEvent;
McSdkCallbacks.AppOpen.OnAdHiddenEvent += OnAppOpenAdDismissedEvent;
McSdkCallbacks.AppOpen.OnAdRevenuePaidEvent += OnAppOpenAdRevenuePaidEvent;
// Load the first AppOpenAd
LoadAppOpenAd();
}
private void LoadAppOpenAd()
{
McSdk.LoadAppOpenAd(adUnitId);
}
private void OnAppOpenAdLoadedEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
// App open ad is ready to be shown. McSdk.IsAppOpenAdReady(AppOpenAdUnitId) will now return 'true'
}
private void OnAppOpenAdFailedEvent(string adUnitId, McSdkBase.ErrorInfo errorInfo)
{
// App open ad failed to load.
}
private void OnAppOpenAdFailedToDisplayEvent(string adUnitId, McSdkBase.ErrorInfo errorInfo, McSdkBase.AdInfo adInfo)
{
// App open ad failed to display.
}
private void OnAppOpenAdDisplayedEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
}
private void OnAppOpenAdClickedEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
}
private void OnAppOpenAdDismissedEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
// App open ad is hidden.
}
private void OnAppOpenAdRevenuePaidEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
// App open ad revenue paid. Use this callback to track user revenue.
}
Showing an App Open Ad
To show an app open ad, call ShowAppOpenAd():
if ( McSdk.IsAppOpenAdReady(adUnitId) )
{
McSdk.ShowAppOpenAd(adUnitId);
}
7. Banner Ad
Loading a Banner
To load a banner, call the following using your Ad Unit ID and desired banner position:
string bannerAdUnitId = "YOUR_MAX_AD_UNIT_ID"; // Retrieve the ID from your account
public void InitializeBannerAds()
{
// Banners are automatically sized to 320×50 on phones and 728×90 on tablets
// You may call the utility method McSdkUtils.isTablet() to help with view sizing adjustments
McSdk.CreateBanner(bannerAdUnitId, McSdkBase.BannerPosition.BottomCenter);
// Set background or background color for banners to be fully functional
McSdk.SetBannerBackgroundColor(bannerAdUnitId, );
McSdkCallbacks.Banner.OnAdLoadedEvent += OnBannerAdLoadedEvent;
McSdkCallbacks.Banner.OnAdLoadFailedEvent += OnBannerAdLoadFailedEvent;
McSdkCallbacks.Banner.OnAdClickedEvent += OnBannerAdClickedEvent;
McSdkCallbacks.Banner.OnAdRevenuePaidEvent += OnBannerAdRevenuePaidEvent;
McSdkCallbacks.Banner.OnAdDisplayedEvent += OnBannerAdDisplayedEvent;
McSdkCallbacks.Banner.OnAdExpandedEvent += OnBannerAdExpandedEvent;
McSdkCallbacks.Banner.OnAdCollapsedEvent += OnBannerAdCollapsedEvent;
}
private void OnBannerAdLoadedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
private void OnBannerAdLoadFailedEvent(string adUnitId, McSdkBase.ErrorInfo errorInfo) {}
private void OnBannerAdClickedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
private void OnBannerAdRevenuePaidEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
private void OnBannerAdDisplayedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
private void OnBannerAdExpandedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
private void OnBannerAdCollapsedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
Set your banner background color to a #-prefixed hexadecimal RGB string, for example '#000000' (black) or '#fff200' (yellow).:The above example creates a banner at the bottom-center of the display (BottomCenter). The complete list of position options are:
-
TopLeft -
TopCenter -
TopRight -
Centered -
CenterLeft -
CenterRight -
BottomLeft -
BottomCenter -
BottomRight
You can also position a banner ad at a specific (x, y) coordinate on the screen by calling McSdk.CreateBanner(ad-unit-ID, x, y);. This sets the position of the top-left corner of the ad. The coordinate system represents the safe area bounds of the screen. Make sure to account for the width and height of the ad when you set these coordinates. The position (0, 0) is equivalent to TopLeft; the bottom-right corner of the safe area is (safeAreaWidth, safeAreaHeight). Note that Unity might have a different screen size or safe area size than Android or iOS. To convert between Unity’s screen size and the sizes used in Android, use code like the following:
var density = McSdkUtils.GetScreenDensity();
var dp = pixels / density;
Showing a Banner
To show a banner, call ShowBanner():
McSdk.ShowBanner(bannerAdUnitId);
Hiding a Banner
To hide a banner, call HideBanner():
McSdk.HideBanner(bannerAdUnitId);
Destroying Banners
After you are no longer using a banner instance (for example, if the user purchased ad removal), call the DestroyBanner() method to free resources. Do not call DestroyBanner() if you use multiple banner instances with the same Ad Unit ID.
McSdk.DestroyBanner(bannerAdUnitId);
Getting Banner Position
To get the banner’s position and size, call GetBannerLayout(). This uses the same Unity coordinate system as explained in Loading a Banner.
Rect bannerLayout = McSdk.GetBannerLayout(bannerAdUnitId);
Setting Banner Width
To manually set the banner’s width, call SetBannerWidth(). Be sure to set the banner width to a size larger than the minimum value (320 on phones, 728 on tablets). Banners under this width may not be considered viewable by the advertiser, and this will affect your revenue:
McSdk.SetBannerWidth(bannerAdUnitId, width);
Stopping and Starting Auto-Refresh
MCSDK does not support automatic refresh of banners. It is recommended that developers call the following code after a certain interval of time after the banner is displayed and reinitiate load. If it is not reinitiated, the banner will always display ads for a certain Mediation.
McSdk.StopBannerAutoRefresh(bannerAdUnitId);
McSdk.LoadBanner(bannerAdUnitId);
Note:
- It is recommended to turn off the automatic refresh of Mediation SDK and manually call McSdk.LoadBanner() at a certain interval to reload the banner.
- The methods below to enable and stop automatic refresh are only valid for Max's adUnitId and not for TopOn's ad placement. If TopOn needs to enable automatic refresh, please set it in the TopOn background (TopOn background-Mediation-setting-Auto Refresh)
There may be cases when you would like to stop auto-refresh, for instance, if you want to manually refresh banner ads. To stop auto-refresh for a banner ad, use the following code:
McSdk.StopBannerAutoRefresh(bannerAdUnitId);
Start auto-refresh for a banner ad with the following code:
McSdk.StartBannerAutoRefresh(bannerAdUnitId);
8. MRECs
Loading an MREC
To load an MREC, call CreateMRec(), passing in your ad unit ID and desired adview position:
string mrecAdUnitId = "YOUR_MAX_AD_UNIT_ID"; // Retrieve the ID from your account
public void InitializeMRecAds()
{
// MRECs are sized to 300x250 on phones and tablets
McSdk.CreateMRec(mrecAdUnitId, McSdkBase.AdViewPosition.Centered);
McSdkCallbacks.MRec.OnAdLoadedEvent += OnMRecAdLoadedEvent;
McSdkCallbacks.MRec.OnAdLoadFailedEvent += OnMRecAdLoadFailedEvent;
McSdkCallbacks.MRec.OnAdClickedEvent += OnMRecAdClickedEvent;
McSdkCallbacks.MRec.OnAdRevenuePaidEvent += OnMRecAdRevenuePaidEvent;
McSdkCallbacks.MRec.OnAdDisplayedEvent += OnMRecAdDisplayedEvent;
McSdkCallbacks.MRec.OnAdExpandedEvent += OnMRecAdExpandedEvent;
McSdkCallbacks.MRec.OnAdCollapsedEvent += OnMRecAdCollapsedEvent;
}
public void OnMRecAdLoadedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
public void OnMRecAdLoadFailedEvent(string adUnitId, McSdkBase.ErrorInfo error) {}
public void OnMRecAdClickedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
public void OnMRecAdRevenuePaidEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
public void OnMRecAdDisplayedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
public void OnMRecAdExpandedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
public void OnMRecAdCollapsedEvent(string adUnitId, McSdkBase.AdInfo adInfo) {}
The above example creates an MREC centered on the display ( Centered ). The complete list of position options are:
-
TopLeft -
TopCenter -
TopRight -
CenterLeft -
Centered -
CenterRight -
BottomLeft -
BottomCenter -
BottomRight
You can also position an MREC at a specific (x, y) coordinate on the screen by calling McSdk.CreateMRec(ad-unit-ID, x, y);. This sets the position of the top-left corner of the ad. The coordinate system represents the safe area bounds of the screen. Make sure to account for the width and height of the ad when you set these coordinates. The position (0, 0) is equivalent to TopLeft; the bottom-right corner of the safe area is (safeAreaWidth, safeAreaHeight). Note that Unity might have a different screen size or safe area size than Android or iOS. To convert between Unity’s screen size and the sizes used in Android, use code like the following:
var density = McSdkUtils.GetScreenDensity();
var dp = pixels / density;
Hiding and Showing an MREC
To show an MREC ad, call ShowMRec():
McSdk.ShowMRec(mrecAdUnitId);
To hide an MREC ad, call HideMRec():
McSdk.HideMRec(mrecAdUnitId);
Destroying MREC Ads
After you are no longer using the MREC instance (for example, if the user purchased ad removal), call the DestroyMRec() method to free resources. Do not call DestroyMRec() if you use multiple MREC instances with the same Ad Unit ID.
McSdk.DestroyMRec(mrecAdUnitId);
Stopping and Starting Auto-Refresh
MCSDK does not support automatic refresh of mrecs. It is recommended that developers call the following code after a certain interval of time after the MREC ad is displayed and reinitiate load. If it is not reinitiated, the MREC ad will always display ads for a certain Mediation.
Note:
- It is recommended to turn off the automatic refresh of Mediation SDK and manually call McSdk.LoadMRec() at a certain interval to reload the MREC ad.
- The methods below to enable and stop automatic refresh are only valid for Max's adUnitId and not for TopOn's ad placement. If TopOn needs to enable automatic refresh, please set it in the TopOn background (TopOn background-Mediation-setting-Auto Refresh)
There may be cases when you would like to stop auto-refresh, for instance, if you want to manually refresh MREC ads. To stop auto-refresh for an MREC ad, use the following code:
McSdk.StopMRecAutoRefresh(mrecAdUnitId);
Start auto-refresh for an MREC ad with the following code:
McSdk.StartMRecAutoRefresh(mrecAdUnitId);
9. Test Ads
Turn on the log switch of MCSDK
McSdk.SetVerboseLogging(true);
In Android Studio's Logcat, you can view related logs through this TAG: mcsdk|Unity
After initializing MCSDK, you can choose to call the following code to open the Max or TopOn Mediation Debugger respectively.
Max Mediation Debugger:
McSdk.ShowMediationDebugger(McSdkBase.MediationId.Max);
For more information, please refer to: Max Mediation Debugger
TopOn Mediation Debugger:
McSdk.ShowMediationDebugger(McSdkBase.MediationId.TopOn);
For more information, please refer to: TopOn Mediation Debugger
10. Error handling
Your ad display delegate or callback interface will receive a call if an ad failed to load or failed to display. This call will be accompanied by an error code. This page describes the error codes you may see.
MCSDK Error Object
The error that you receive in your callback is a first-class error object that implements ErrorInfo. This object has the following APIs:
- Code - The error code, which you can find in the table below.
- Message - A human-readable message that describes the error.
- MediationErrors - Error messages for each Mediation. The error information for each mediation can be obtained through MediationErrorInfo
MediationErrorInfo Object
- MediationId - Used to distinguish between different Mediations, such as Max and TopOn
- MediationPlacementId - Mediation's placement id
- Code - Meidation 's error code.
- Message - Meidation 's error message.
- MediatedNetworkErrorCode - The mediated network’s error code for the error.
- MediatedNetworkErrorMessage - The mediated network’s error message for the error.
- WaterfallInfo - (Only for Max) Allows you to see the information about the current waterfall for an ad that has loaded or failed to load. The network responses provide the ad load state, latency, credentials, and mediated network information for each ad in the waterfall. If an ad in the waterfall fails to load, the network response provides error information. You can find out more about this API here.here
MCSDK Error Codes
|
Code
|
Enum
|
Description
|
Load / Display
|
|---|---|---|---|
|
−1
|
McSdkBase.ErrorCode.Unspecified
|
The system is in an unexpected state. This error code represents an error that could not be categorized into one of the other defined errors. See the message field in the error object for more details.
|
L/D
|
|
-5202
|
McSdkBase.ErrorCode.InvalidConfiguration
|
The parameters passed in to sdk are invalid and need to be checked.
|
L
|
|
−5001
|
McSdkBase.ErrorCode.AdLoadFailed
|
The ad failed to load due to no networks being able to fill. MCSDK returned eligible ads from mediated networks, but all ads failed to load. See the adLoadFailureInfo field in the error object for more details.
|
L
|
|
−5601
|
McSdkBase.ErrorCode.NoActivity
|
The SDK failed to load an ad because it could not find the top Activity.
|
L
|
Error Codes from Various Mediations
11. Privacy
11.1 GDPR
If the user consents to interest-based advertising, set the user consent flag to true by calling SetHasUserConsent, and start requesting ads through the AppLovin SDK. After you set the consent value to true for a particular user, AppLovin will continue to respect that value for the lifetime of your application or until the user revokes consent to interest-based advertising.
McSdk.SetHasUserConsent(true);
If the user does not consent to interest-based advertising, set the user consent flag to false by calling SetHasUserConsent for a particular user, and start requesting ads through the AppLovin SDK. After you set the consent value to false, AppLovin will continue to respect that value for the lifetime of your application or until the user consents to interest-based advertising.
McSdk.SetHasUserConsent(false);
11.2 COPPA
Note: The following API is not valid for topon. For topon, please go to App page ,then click "edit" button to set up
If you know that the user falls within an age-restricted category (i.e., under the age of 16, or as otherwise defined by applicable laws), you must set the age-restricted user flag to true.
McSdk.SetIsAgeRestrictedUser(true);
If you know that the user does not fall within an age-restricted category (i.e., age 16 or older, or as otherwise defined by applicable laws), you must set the age-restricted user flag to false.
McSdk.SetIsAgeRestrictedUser(false);
11.3 CCPA
Note: The following API is not valid for topon. For topon, please go to App page ,then click "edit" button to set up
State laws in the United States may require you to display a “Do Not Sell or Share My Personal Information” link or provide other options to users located in those states to opt out of interest-based advertising. You must set a flag that indicates whether users in the relevant states opt out of interest-based advertising or the sale or share of personal information for interest-based advertising.
If a user does not opt out in these ways, set the do-not-sell flag to false.
McSdk.SetDoNotSell(false);
If a user does opt out in these ways, set the do-not-sell flag to true.
McSdk.SetDoNotSell(true);
12. Impression-Level User Revenue API
The following example shows how to do this within the “ad revenue paid” callback:
// Attach callbacks based on the ad format(s) you are using
McSdkCallbacks.Interstitial.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
McSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
McSdkCallbacks.AppOpen.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
McSdkCallbacks.Banner.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
McSdkCallbacks.MRec.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
⋮
private void OnAdRevenuePaidEvent(string adUnitId, McSdkBase.AdInfo adInfo)
{
double revenue = adInfo.Revenue;
// Miscellaneous data
MediationId mediationId = adInfo.MediationId; // The mediation ID that showed the ad (1: "TopOn", 2: "Max")
string mediationPlacementId= adInfo.MediationPlacementId; // The placement ID from the mediation that showed the ad
string countryCode = adInfo.Country; // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD"
string networkName = adInfo.NetworkName; // Display name of the network that showed the ad (e.g. "AdColony")
string adUnitIdentifier = adInfo.AdUnitIdentifier; // The MAX Ad Unit ID - This only indicates that the current ad was loaded using this ad placement, and does not represent the ad placement of the mediation
string placement = adInfo.Placement; // The placement this ad's postbacks are tied to
string networkPlacement = adInfo.NetworkPlacement; // The placement ID from the network that showed the ad
}
You can also retrieve a precision evaluation for the revenue value, as shown in the following example:
string revenuePrecision = adInfo.RevenuePrecision;
This precision is one of the following values:
-
publisher_defined— revenue is the price assigned by the publisher -
exact— revenue is the resulting price of a real-time auction -
estimated— the revenue amount is based on Auto CPM or FB Bidding estimates -
undefined— no revenue amount is defined and there is not enough data to estimate -
an empty string, if revenue and precision are not valid (for example, in test mode)
13. Query ad status information
The following example shows how to query status information for an ad: