Initialize CAS SDK
Before loading ads, initialize the CAS Mobile Ads SDK by calling CASMobileAds.initialize(casId, options?). The call returns a Promise<InitializationStatus> that resolves when initialization completes.
The casId is a unique identifier for CAS content on each platform. You can use demo to force test-ads mode if you haven't registered a casId yet.
import { Platform } from 'react-native';
import CASMobileAds, { InitializationStatus, Audience, PrivacyGeography, ConsentFlowStatus } from 'react-native-cas';
function initCAS() {
const casId = Platform.select({ ios: 'YOUR_CAS_ID_IOS', android: 'YOUR_CAS_ID_ANDROID' });
CASMobileAds.initialize(casId, {
...
}).then((status: InitializationStatus) => {
if (status.error) {
console.log(`CAS initialization failed: ${status.error}`);
} else {
console.log(`CAS initialized`);
}
});
}
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.
Do not initialize mediated ad SDKs yourself — CAS does that for you.
Ignoring this will cause integration issues.
Initialization Status
errorstringoptionalInitialization error or null if success.
countryCodestringoptionalUser Country code ISO 2 or null if not allowed.
isConsentRequiredbooleanIndicates the privacy options button is required.
consentFlowStatusConsentFlowStatusConsent 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.
CASMobileAds.initialize(casId, {
showConsentFormIfRequired: true,
debugGeography: PrivacyGeography.EUROPEAN_ECONOMIC_AREA
}).then((status) => {
if (status.consentFlowStatus === 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.
CASMobileAds.initialize(casId, {
forceTestAds: __DEV__,
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:
CASMobileAds.initialize(casId, {
targetAudience: Audience.NOT_CHILDREN,
});
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 CASMobileAds.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;
CASMobileAds.setTrialAdFreeInterval(secondsIn7Days);