---
schema_version: "1"
id: c1c57b562881ba8e99b672dfe99594bcc40e183aba14d6ca05b9e5329aada898
title: Initialization (Version 3.x)
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-engagement-mobile-sdk/guides/c360a-api-engagement-mobile-sdk-initialization-v3.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-engagement-mobile-sdk/guide/c360a-api-engagement-mobile-sdk-initialization-v3.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 2c6192c167630ac5e1e82d31ee0be3e689074c242c1a1312684c0fece90e86f0
products:
  - Data 360 Engagement Mobile SDK
  - Data 360 Developer Documentation
---
# Initialization (Version 3.x)

Configure the Data 360 Module for the Engagement Mobile SDK before using it to invoke web services using the API. Use the `CdpConfigBuilder` helper class for iOS or `CdpConfig.Builder` helper class for Android to build your SDK configuration by providing required settings `appId` and endpoint that can be obtained from your Mobile Connector. Optionally, configure the `trackScreens`, `trackLifecycle`, and `sessionTimeoutInSeconds` settings.

**note:** The `appId` configuration field and `appSourceId` in the API/network layer refer to the same value — the UUID from the Data 360 mobile app connector.

| Setting                   | Field Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `appId`                   | string         | Required. The `appId` setting uniquely identifies your mobile application to Data 360 and must be in a valid universally unique identifier (UUID) format. An invalid `appId` results in an error.                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `endpoint`                | string         | Required. The endpoint setting tells the SDK where to send the events being created and tracked.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `sessionTimeoutInSeconds` | integer        | The `sessionTimeoutInSeconds` setting represents the number of seconds the mobile application can remain in the background before the current session expires. When a customer launches the mobile application, the SDK starts a new session that is maintained while the app is in the foreground. If the customer sends the mobile application to the background, the SDK starts a timer to expire the current session. If the customer brings the mobile app back to the foreground before the session expiration, the timer is cleared and the session continues. Otherwise, the session expires. This field is set to `600` by default. |
| `trackLifecycle`          | boolean        | Enable `trackLifecycle` to automatically track `AppForegrounded`, `AppBackgrounded`, and `AppVersionChanged` behavior events. This field is set to `false` by default.                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `trackScreens`            | boolean        | Enable `trackScreens` to automatically track the mobile app `ScreenEntry` behavior event. This field is set to `false` by default.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `eventFlushRate` (iOS)    | EventFlushRate | Controls when queued events are flushed to the network. Accepts `EventFlushRateQuantity(quantity: n)` to flush after accumulating `n` events, or `EventFlushRateQuantityAndInterval(quantity: n, interval: seconds)` to flush after `n` events **or** after the specified interval in **seconds**, whichever comes first. This field is set to `EventFlushRateQuantity(quantity: 20)` by default. Only use `EventFlushRateQuantityAndInterval` when bounded latency is a requirement (for example, near-real-time analytics). Do not set the interval below 30 seconds. Available in version 3.0.2 and later.                                                                                                  |
| `eventFlushRate` (Android) | EventFlushRate | Controls when queued events are flushed to the network. Accepts `CdpConfig.EventFlushRate.Quantity(n)` to flush after accumulating `n` events, or `CdpConfig.EventFlushRate.QuantityAndInterval(n, ms)` to flush after `n` events **or** after `ms` **milliseconds**, whichever comes first. This field is set to `Quantity(20)` by default. Only use `QuantityAndInterval` when bounded latency is a requirement (for example, near-real-time analytics). Do not set the interval below 30 seconds (`30_000L`).                                                                                                                                                                                                  |

## Set Up the Data 360 Module

1.  (Optional) To capture debug information and track SDK initialization progress, set up logging before initializing the SDK. Use the `setLogger` method for iOS and the `setLogging` method for Android. For more information and example usage, see [Logging and Debugging](https://developer.salesforce.com/docs/data/data-cloud-engagement-mobile-sdk/guide/c360a-api-engagement-mobile-sdk-logging-and-debugging.md).
2.  Configure the Data 360 Module.
3.  Initialize the Engagement Mobile SDK with the Data 360 Module.

Configuration occurs during the initialization routine of the Mobile application being instrumented.

## iOS Example

```swift
import Cdp
import SFMCSDK

...

let appId = "{appIdFromMobileConnector}"
let endpoint = "https://{endpointFromMobileConnector}"

// 1. (Optional) Enable logging. In this example, the logger is set to show debug messages and higher.

SFMCSdk.setLogger(logLevel: .debug)

// 2. Configure the Data 360 Module

let cdpConfig = CdpConfigBuilder(
    appId: appId,
    endpoint: endpoint
)
    .trackScreens(false)
    .trackLifecycle(false)
    .sessionTimeout(600)
    .eventFlushRate(EventFlushRateQuantityAndInterval(quantity: 10, interval: 30.0)) // Optional (3.0.2+)
    .build()

// 3. Initialize the Engagement Mobile SDK with the Data 360 Module registered

let sdkConfig = ConfigBuilder().setCdp(config: cdpConfig).build()
SFMCSdk.initializeSdk(sdkConfig) { status in
    for moduleStatus in status where moduleStatus.moduleName == ModuleName.cdp {
        if moduleStatus.initStatus == .success {
            // SDK is ready
            print(CdpModule.shared.state)
        }
    }
}
```

The `SFMCSdk.initializeSdk(_:completionHandler:)` method calls the handler once per registered module with its initialization status. Filter by `moduleName == ModuleName.cdp` to act only on the Data 360 Module result. A status of `initStatus == .success` means the module is ready to use.

## Android Example

```kotlin
import com.salesforce.marketingcloud.cdp.CdpConfig
import com.salesforce.marketingcloud.cdp.CdpSdk
import com.salesforce.marketingcloud.cdp.consent.Consent
import com.salesforce.marketingcloud.sfmcsdk.SFMCSdk
import com.salesforce.marketingcloud.sfmcsdk.SFMCSdkModuleConfig
import com.salesforce.marketingcloud.sfmcsdk.InitializationStatus

// Optional, import SDK components needed to enable logging

import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogLevel
import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogListener.AndroidLogger

...

val appId = "{appIdFromMobileConnector}"
val endpoint = "https://{endpointFromMobileConnector}"

// 1. (Optional) Enable logging. In this example, the logger is set to show debug messages and higher.

SFMCSdk.setLogging(LogLevel.DEBUG, AndroidLogger())

// 2. Configure the Data 360 Module

val cdpModuleConfig = CdpConfig.Builder(this@MyApplication, appId, endpoint)
    .trackScreens(false)
    .trackLifecycle(false)
    .sessionTimeout(600)
    .eventFlushRate(CdpConfig.EventFlushRate.Quantity(20))
    .build()

// 3. Initialize the Engagement Mobile SDK

SFMCSdk.configure(this, SFMCSdkModuleConfig.build {
    this.cdpModuleConfig = cdpModuleConfig
}) { status ->
    if (status.status == InitializationStatus.SUCCESS) {
        CdpSdk.requestSdk { sdk ->
            sdk.consent = Consent.OPT_IN
        }
    }
}
```
