Initialize SDK - cleveradssolutions/CAS-Unity Wiki
:zap: Before you start
Make sure you have correctly configure SDK.
Implementation by UnityEditor | Script C#
- Initialize MediationManager
- Always test with test ads
- Subscribe to Ad Loading response
- Ads processing
- Get the manager
- Retrieve the Version Number
Initialize MediationManager
To display ads, you must initialize the mediation manager with a unique managerID
.
This needs to be done only once for each manager, ideally at app launch.
If you haven't created an CAS account and registered an app yet, now's a great time to do so at cleveradssolutions.com. In a real app, it is important that you use your actual CAS manager ID.
The settings for initializing the mediation manager are contained in a CASInitSettings
asset.
The CASInitSettings is unique for each supported runtime platform and can be created and modified using the editor Assets > CleverAdsSolutions > Settings
menu.
Also you can change any properties of the asset using CAS.MobileAds.BuildManager()
.
Here's an example of how to call Initialize()
within the Start()
method of a script attached to a GameObject:
using CAS;
class CleverAdsSolutionsDemoScript : MonoBehaviour
{
IMediationManager manager;
void Start()
{
// Configure MobileAds.settings before initialize
manager = MobileAds.BuildManager()
// Select first Manager Id from list in settings asset
.WithManagerIdAtIndex(0)
// Add initialize listener
.WithInitListener((success, error) => {
// CAS manager initialization done
})
// Call Initialize method in any case to get IMediationManager instance
.Initialize();
}
}
⚠️ Do not initialize mediated advertising SDKs (CAS does that for you).
Not following this step will result in noticeable integration issues.
Subscribe to Ad Loading response
The CAS Unity Plugin fires several events to inform you of ad availability and states.
manager.OnLoadedAd += (adType) => {
// Called when `AdType` load ad response
Debug.Log(adType.ToString() + " Loaded");
};
manager.OnFailedToLoadAd += (adType, error) => {
// Called when <see cref="AdType"/> failed to load ad response with error message
Debug.Log(adType.ToString() + " Failed to Load with error " + error);
};
⚠️ Please for
AdType.Banner
use new ad size api GetAdView(AdSize) instead with eventsOnLoaded
andOnFailed
.
Ads processing
CAS have functionality to limit the processing of specific AdType
.
This can be useful when you need to improve application performance by turning off unused formats.
Or if you have determined that the user will no longer need to be shown ads, for example after purchase.
The default ad type activity is selected in the settings window.
However, the state can be changed after initialization using the following methods:
manager.SetEnabledAd(AdType.Interstitial, false);
- If processing is inactive then all calls to the selected ad type will fail with error
AdError.ManagerIsDisabled
. - ⚠️ Turning off the processing leads to the complete destruction of the ready ads from memory. And reactivation after destruction requires a new load of ads to memory.
- The state will not be saved between sessions.
Get the manager
Feel free to call initialize again to get the manager when you've lost it:
IMediationManager manager =
CAS.MobileAds.BuildManager()
.WithManagerIdAtIndex(indexInList)
.Initialize();
Initialization will only occur if it is needed.
Static property
CAS.MobileAds.manager
can give you the first initialized manager or Null, but we do not recommend the property and it may be removed in future releases.
Retrieve the Version Number
To programmatically retrieve the Unity Plugin and the native SDK version number at runtime, CAS provides the following strings:
string pluginVersion = CAS.MobileAds.wrapperVersion;
string nativeSDKVersion = CAS.MobileAds.GetSDKVersion();
What’s Next?
- Follow our integration guides and implement our Ad Units:
- Please see the Privacy page to learn how to ensure that your application complies with privacy regulations.