---
title: 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.

```ts
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`.

<Error>
Do not initialize mediated ad SDKs yourself — CAS does that for you.  
Ignoring this will cause integration issues.
</Error>

### Initialization Status

<Property name="error" type="string" optional>
Initialization error or null if success.
</Property>

---

<Property name="countryCode" type="string" optional>
User Country code ISO 2 or null if not allowed.
</Property>

---

<Property name="isConsentRequired" type="boolean">
Indicates the privacy options button is required.
</Property>

---

<Property name="consentFlowStatus" type="ConsentFlowStatus">
Consent flow status code, check `ConsentFlowStatus` enum values.
</Property>

## 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.

```ts
CASMobileAds.initialize(casId, {
  showConsentFormIfRequired: true, // [!code highlight]
  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.

<Info>
Read more about **Debug geography** on [CAS User Consent Flow](ReactNative/User-Consent-Flow).
</Info>

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

```ts
CASMobileAds.initialize(casId, {
  forceTestAds: __DEV__, // [!code highlight]
  testDeviceIds: ['YOUR_TEST_DEVICE_ID'], // [!code highlight]
});
```

For more on test ads, see [Enable test ads](ReactNative/Enabling-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:

```ts
CASMobileAds.initialize(casId, {
  targetAudience: Audience.NOT_CHILDREN, // [!code highlight]
});
```

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:
```ts
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.  

```ts
const secondsIn7Days = 604800;
CASMobileAds.setTrialAdFreeInterval(secondsIn7Days);
```

## Complete example
- [Initialize CASMobileAds example](https://github.com/cleveradssolutions/CAS-ReactNative/blob/main/example/src/SetupScreen.tsx#L38)
