Initialize CAS SDK

Before loading ads, initialize the CAS Mobile Ads SDK by calling casai.initialize(options) from the cordova deviceready event. The call returns a Promise<InitializationStatus> that resolves when initialization completes.

function onDeviceReady() {
  document.removeEventListener('deviceready', onDeviceReady, false);

  casai.initialize({}).then((status) => {
    if (status.error) {
      console.log(`CAS initialization failed: ${status.error}`);
    } else {
      console.log(`CAS initialized`);
    }
  });
}

document.addEventListener("deviceready", onDeviceReady, false);

If an error occurs, the SDK attempts automatic re-initialization internally. However, the returned Promise is not updated with later status changes; call initialize() again for the latest InitializationStatus.

Initialization Status

errorstringoptional

Initialization error or null if success.

countryCodestringoptional

User Country code ISO 2 or null if not allowed.

isConsentRequiredboolean

Indicates the privacy options button is required.

consentFlowStatusConsentFlowStatus

Consent flow status code, check ConsentFlowStatus enum values.

Automatic user consent flow

To collect user consent for personal data, use the built-in Consent Flow. It shows a consent form automatically during initialization.

casai.initialize({
  showConsentFormIfRequired: true,
  debugGeography: 'eea'
}).then((status) => {
  if (status.consentFlowStatus == 'Obtained') {
    console.log('CAS obtained user consent');
  }
});

Wait for the consent flow to complete before initializing third-party SDKs (MMPs, analytics), otherwise they may not have access to required identifiers.

Read more about Debug geography on CAS User Consent Flow.

Always test with test ads

Enable test ads during development so you can interact with ads safely.

casai.initialize({
  forceTestAds: true,
  testDeviceIds: ['YOUR_TEST_DEVICE_ID'],
});

For more on test ads, see Enable test ads.

Prohibition on Personal Information from Children

Mark apps as child-directed or COPPA-applicable in the CAS UI. If you know specific users are COPPA-applicable, set the audience:

casai.initialize({
  targetAudience: 'children',
});
  • 'children' - Compliance with all applicable legal regulations and industry standards relating to advertising to children.
  • 'notchildren' - Audiences over the age of 13 NOT subject to the restrictions of child protection laws.
  • undefined - For app's target age groups include both children and older audiences, any ads that may be shown to children must comply with Google Play's Families Ads Program.

If your app targets both children and older users, implement a neutral age screen to ensure COPPA compliance.

(Optional) Retrieve the Version Number

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

const sdkVersion = await casai.getSDKVersion();

(Optional) Trial ad-free interval

Defines the time interval, in seconds, starting from the moment of the initial app installation, during which users can use the application without ads being displayed while still retaining access to the Rewarded Ads format. Within this interval, users enjoy privileged access to the application's features without intrusive advertisements.

const secondsIn7Days = 604800;
casai.setTrialAdFreeInterval(secondsIn7Days);

Complete example