Skip to content

Initialize CAS

Str4tos edited this page Mar 8, 2024 · 13 revisions

⚡ Before you start
Make sure you have correctly configure SDK.

Implementation by UnityEditor | Script C#


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 IManagerBuilder implementation.
The IManagerBuilder is unique for each supported runtime platform and can be created and modified using the editor Assets > CleverAdsSolutions > Platform Settings menu.
Also you can change any properties of the asset using CAS.MobileAds.BuildManager().

Here's an example of how to call Build() within the Start() method of a script attached to a GameObject:

Warning

Do not initialize mediated advertising SDKs (CAS does that for you).
Not following this step will result in noticeable integration issues.

using CAS;

class CleverAdsSolutionsDemoScript : MonoBehaviour
{
    public void Start()
    {
        IMediationManager manager = GetAdManager();
    }
    
    public static IMediationManager GetAdManager()
    {
        // Configure MobileAds.settings before initialize
        return MobileAds.BuildManager()
           // Optional initialize listener
           .WithCompletionListener((config) => {
              string initErrorOrNull = config.error;
              string userCountryISO2OrNull = config.countryCode;
              bool protectionApplied = config.isConsentRequired;
              IMediationManager manager = config.manager;
           })
           .Build();
    }
}

Note

If you are using Assembly Definition for scripts and see the following
error CS0103: The name 'MobileAds' does not exist in the current context
then add Assembly Definition Reference to our assembly with name CleverAdsSolutions.

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.SetEnableAd(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.

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();

🔗 Done! What’s Next?