Initialize CAS - cleveradssolutions/CAS-Unreal GitHub Wiki

To display ads, you must initialize the Mobile Ads once, ideally at app launch.

#include "CASMobileAds.h"

UCASMobileAds::OnAdsInitialized.AddLambda([this](const FCASInitialConfig &Config) {
    if (Config.Error.IsEmpty()) {
        // Ads initialization completed
    } else {
        // Ads initialization failed with Config.Error
    }
    // The CAS SDK initializes if the error IsEmpty()
    FString InitErrorOrEmpty = Config.getError;
    FString UserCountryISO2OrEmpty = Config.CountryCode;
    
    // The user completes the consent flow
    ECASConsentFlowStatus ConsentFlowStatus = Config.ConsentFlowStatus; 
});

UCASMobileAds::InitializeMobileAds();

The OnAdsInitialized event may be called with an error. In this case, the SDK will attempt to reinitialize and the listener will be called again until the error is resolved.

Check initialized ads

You can also check whenever CAS was initialized. Use IsInitializedAds if you are unsure before using ad interfaces or want to do additional checks.

UCASMobileAds::IsInitializedAds();

Retrieve the Version Number

To programmatically retrieve the SDK version number at runtime, the plugin provides the following method:

UCASMobileAds::GetMobileAdsVersion();

(Optional) Trial ad-free interval

Set the time interval during which users can enjoy an ad-free experience while retaining access to Rewarded Ads and App Open Ads formats. This interval is defined from the moment of the initial app installation, in seconds. Within this interval, users enjoy privileged access to the application's features without intrusive advertisements.

int SecondsIn7Days = 604800;
UCASMobileAds::SetTrialAdFreeInterval(secondsIn7Days);

๐Ÿ”— Done! Whatโ€™s Next?