Skip to content

Initialize CAS

d.eshenko edited this page Oct 25, 2022 · 15 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 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
           })
           .Initialize();
    }
}

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

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

Targeting options

You can now easily tailor the way you serve your ads to fit a specific audience!
You’ll need to inform our servers of the users’ details so the SDK will know to serve ads according to the segment the user belongs to.

Set user gender using the following method:

CAS.MobileAds.targetingOptions.gender = CAS.Gender.Male;

Set user age with limitation 1-99 and 0 is 'unknown' using the following method:

CAS.MobileAds.targetingOptions.age = 12;

What’s Next?

Clone this wiki locally