Initialize CAS - cleveradssolutions/CAS-ReactNative GitHub Wiki

:zap: Before you start
Make sure you have correctly Project setup.


Initialize MediationManager

In most cases, a casId is the same as your application package name / app store app ID.

  • package name uniquely identifies your app on the device and in the Google Play Store.
  • The package name value is case-sensitive and is often referred to as an APPLICATION_ID.
  • For android, find your app's package name in your module (app-level) Gradle file, usually android/app/build.gradle (example package name: com.yourcompany.yourproject).
  • For iOS, you could get your ID in App Store Connect portal.
  • 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.

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

import { AdType, CAS } from 'react-native-cas';
...
const { manager, result } = await CAS.buildManager(
    {
        consentFlow: {
          requestGDPR: true,
          requestATT: true,
          privacyPolicy: 'url',
        },
        testMode: false,
        userId: 'user_id',
        adTypes: [AdType.Interstitial, AdType.Banner],
        casId: '1234567890',
    },
    onConsentFlowReleasedCallback,
);

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.

List the AdTypes that will be used in your application:

const { manager, result } = await CAS.buildManager(
    {
        adTypes: [AdType.Interstitial, AdType.Banner],
    },
);

🌟 Your choice helps us configuring mediation in the most effective way for you, depending on the chosen ad formats.

Also, the state can be changed after initialisation using the following methods:

manager.setEnabled(AdType.Interstitial, false);
  • If processing is inactive then all calls to the selected ad type will fail with error AdError.CodeManagerIsDisabled.
  • The state will not be saved between sessions.
  • ⚠️ 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.

Retrieve the Version Number

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

const sdkVersion = await CAS.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 age. Limitation: 1-99 and 0 is 'unknown'

CAS.setTargetingOptions({
    age: 12,
});

Set user gender.

CAS.setTargetingOptions({
    gender: Gender.Male,
});

Set the user's current location. Location data is not used to CAS; however, it may be used by third party ad networks.

CAS.setTargetingOptions({
    location: userLocation,
});

Do not use Location just for advertising. Your app should have a valid use case for it as well.

Set a list of keywords, interests, or intents related to your application. Words or phrases describe the current activity of the user for targeting purposes.

CAS.setTargetingOptions({
    keywords: ['hello'],
});

Set the content URL for a website whose content matches the app's primary content. This website content is used for targeting and brand safety purposes. Limitation: max URL length 512.

CAS.setTargetingOptions({
    contentUrl: 'www.website.com',
});

🔗 Done! What’s Next?