initialize static method

Future<InitializationStatus> initialize({
  1. required String casId,
  2. Audience targetAudience = Audience.undefined,
  3. bool showConsentFormIfRequired = true,
  4. bool forceTestAds = false,
  5. List<String>? testDeviceIds,
  6. PrivacyGeography debugPrivacyGeography = PrivacyGeography.europeanEconomicArea,
  7. Map<String, String>? mediationExtras,
})

Initializes the CAS Mobile Ads SDK.

Call this method as early as possible after the app launches to reduce latency on the session's first ad load.

If this method is not called, the first ad load automatically initializes the CAS Mobile Ads SDK with CAS Id defined in ad load arguments.

Note: This Future may take an unexpectedly long time to complete, as it will only resolve once the SDK has either successfully initialized or failed with an error.

If an error occurs, the SDK will attempt automatic reinitialization internally. However, this Future will not be updated with subsequent InitializationStatus. For the most up-to-date InitializationStatus, call this method again at a later time.

casId

The unique identifier for the CAS content registered for your app on each platform. You can use the value demo to force test ads mode on all devices if you haven't registered a casId yet.

targetAudience

Indicates the target Audience of the app for regulatory and content purposes. This may affect how the SDK handles data collection, personalization, and content rendering, especially for audiences such as children.

showConsentFormIfRequired

Shows the consent form only if it is required and the user has not responded previously. If the consent status is required, the SDK loads a form and immediately presents it.

forceTestAds

Enable test ads mode that will always return test ads for all devices. Attention Don't forget to set it to False after the tests are completed.

testDeviceIds

Add a test device ID corresponding to test devices which will always request test ads. List of test devices should be defined before first MediationManager initialized.

  1. Run an app with the CAS SDK initialize() call.
  2. Check the console or logcat output for a message that looks like this: "To get test ads on this device, set ... "
  3. Copy your alphanumeric test device ID to your clipboard.
  4. Add the test device ID to the testDeviceIds list.

debugPrivacyGeography

Sets the debug geography for testing purposes.

This setting only works during test sessions enabled via forceTestAds or testDeviceIds.

mediationExtras

Additional mediation settings.

Implementation

static Future<InitializationStatus> initialize({
  required String casId,
  Audience targetAudience = Audience.undefined,
  bool showConsentFormIfRequired = true,
  bool forceTestAds = false,
  List<String>? testDeviceIds,
  PrivacyGeography debugPrivacyGeography =
      PrivacyGeography.europeanEconomicArea,
  Map<String, String>? mediationExtras,
}) {
  return casInternalBridge.initializeSDK(
    casId: casId,
    targetAudience: targetAudience.index,
    showConsentFlow: showConsentFormIfRequired,
    forceTestAds: forceTestAds,
    testDeviceIds: testDeviceIds,
    debugGeography: debugPrivacyGeography,
    mediationExtras: mediationExtras,
  );
}