Initialization

Before the Data Cloud Module for the Engagement Mobile SDK can be used to invoke web services using the API, the SDK must be configured. Use the CdpConfigBuilder for iOS or CdpConfig.Builder for Android helper class to build your SDK configuration by providing required settings appId and endpoint that can be obtained from your Mobile Connector. Optionally, configuration can be provided for the settings trackScreens, trackLifecycle, and sessionTimeoutInSeconds.
Setting Field Type Description
appId string Required. The appId setting uniquely identifies your mobile application to Data Cloud 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 is expired. 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 is continued. 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.

Set Up the Data Cloud Module

  1. (Optional) To capture debug information and track SDK initialization progress, set up logging before initializing the SDK. For iOS, use the setLogger method. For Android, use the setLogging method. For more information and example usage, see Logging and Debugging.
  2. Configure the Data Cloud Module.
  3. Initialize the Engagement Mobile SDK with the Data Cloud Module.

Configuration happens during the initialization routine of the Mobile application being instrumented.

iOS Example

1import Cdp
2import SFMCSDK
3
4...
5
6let appId = "{appIdFromMobileConnector}"
7let endpoint = "https://{endpointFromMobileConnector}"
8
9// 1. (Optional) Enable logging. In this example, the logger is set to show debug messages and higher.
10
11SFMCSdk.setLogger(LogLevel.debug)
12
13// 2. Configure the Data Cloud module
14      
15let cdpModuleConfig = CdpConfigBuilder(appId: appId, endpoint: endpoint)
16        .trackScreens(false)
17        .trackLifecycle(false)
18        .sessionTimeout(600)
19        .build()
20  
21// 3. Initialize the Engagement Mobile SDK 
22
23SFMCSdk.initializeSdk(ConfigBuilder().setCdp(config: cdpModuleConfig).build())

Android Example

1import com.salesforce.marketingcloud.cdp.CdpConfig
2import com.salesforce.marketingcloud.sfmcsdk.SFMCSdk
3import com.salesforce.marketingcloud.sfmcsdk.SFMCSdkModuleConfig
4
5// Optional, import SDK components needed to enable logging
6
7import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogLevel
8import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogListener.AndroidLogger
9
10...
11
12val appId = "{appIdFromMobileConnector}"
13val endpoint = "https://{endpointFromMobileConnector}"
14
15// 1. (Optional) Enable logging. In this example, the logger is set to show debug messages and higher.
16
17SFMCSdk.setLogging(LogLevel.DEBUG, AndroidLogger())
18
19// 2. Configure the Data Cloud module
20      
21val cdpModuleConfig = CdpConfig.Builder(this, appId, endpoint)
22      .trackScreens(false)
23      .trackLifecycle(false)
24      .sessionTimeout(600)
25      .build()
26
27// 3. Initialize the Engagement Mobile SDK
28
29SFMCSdk.configure(this, SFMCSdkModuleConfig.build {
30    this.cdpModuleConfig = cdpModuleConfig
31})