Capture Behavior Data
Version 3.x
Version 2.x
Post Data from an Authenticated Server-to-Server Connection
Post Data from an Unauthenticated Server-to-Server Connection
Logging is an important SDK feature that lets you control the verbosity of the SDK’s output. By default, logging is disabled. You must enable it by defining a log level and output destination using the setLogger method for iOS or setLogging method for Android on the SFMCSdk instance. Once enabled, the SDK uses the native unified logging system to capture log output.
| Log Level | Description |
|---|---|
Error | Details unrecoverable errors that prevent key functionalities from working. |
Warn | Highlights potential problems or unexpected situations. These are typically recoverable issues that won’t stop the SDK from functioning but should be addressed. |
Debug | Provides detailed, low-level information about the SDK’s internal operations. Use this level for in-depth troubleshooting and diagnostics. |
Here’s how you can enable and use logging in your application.
1import SFMCSDK
2
3...
4
5// Set the logger to show debug messages and higher
6SFMCSdk.setLogger(logLevel: .debug)
7
8// Example usage
9let CATEGORY = LoggerCategory.module
10
11SFMCSdk.logger.d(category: CATEGORY, message: "Logs a debug message.")
12SFMCSdk.logger.w(category: CATEGORY, message: "Logs a warning message.")
13SFMCSdk.logger.e(category: CATEGORY, message: "Logs an error message.")1import com.salesforce.marketingcloud.sfmcsdk.SFMCSdk
2import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogLevel
3import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogListener.AndroidLogger
4
5...
6
7// Set the logger to show debug messages and higher
8SFMCSdk.setLogging(LogLevel.DEBUG, AndroidLogger())
9
10// Example usage
11val TAG = "Example Application"
12val ERROR = IllegalStateException("Example Failure")
13
14SFMCSdk.logger.d(TAG) { "Logs a debug message." }
15SFMCSdk.logger.d(TAG, ERROR) { "Logs a debug message along with the error." }
16
17SFMCSdk.logger.w(TAG) { "Logs a warning message." }
18SFMCSdk.logger.w(TAG, ERROR) { "Logs a warning message along with the error." }
19
20SFMCSdk.logger.e(TAG) { "Logs an error message." }
21SFMCSdk.logger.e(TAG, ERROR) { "Logs an error message along with the error." }The state property of the Data 360 Module returns operational information containing current configuration settings, session details, event queue size, and consent state. This information is critical for debugging and troubleshooting purposes.
There are two equivalent ways to access the Data 360 Module after initialization:
SFMCSdk.cdp — access via the unified SFMCSDK namespace (preferred for consistency with other modules)CdpModule.shared (iOS) / CdpSdk.requestSdk (Android) — direct singleton accessBoth refer to the same module instance.
1// Inspect full SDK state as a JSON string
2print(CdpModule.shared.state)
3
4// Or via the unified SDK accessor
5print(SFMCSdk.cdp.state)1CdpSdk.requestSdk { sdk ->
2 val state = sdk.state
3 Log.d("MyApp", sdk.state.toString(2))
4}Always inspect the SDK state during debugging to verify your configuration and understand the SDK’s current status.
1{
2 "name": "cdp",
3 "version": "3.0.1",
4 "User-Agent": "CDP-iOS/3.0.1 ...",
5 "config": {
6 "appId": "your-app-source-id",
7 "endpoint": "https://your-endpoint.salesforce.com/",
8 "sessionTimeout": 600,
9 "trackLifecycle": false,
10 "trackScreens": false
11 },
12 "consentManager": {
13 "consent": "optIn",
14 "deviceId": "A1B2C3D4-...",
15 "partyIdentificationUserId": ""
16 },
17 "sessionManager": {
18 "sessionId": "E5F6G7H8-..."
19 },
20 "eventManager": {
21 "queueSize": 0
22 },
23 "locationManager": {
24 "latitude": 37.7749,
25 "longitude": -122.4194,
26 "expiration": 1712345678
27 }
28}locationManager is an empty object {} when no location is set or it has expired.consentManager.partyIdentificationUserId is populated when the SFMCSDK push module has set a subscriber key.APP_SOURCE_UNKNOWN), the entire state string is "Deprovisioned" (not JSON).expiration in locationManager is a Unix timestamp (seconds since epoch).1{
2 "name": "CDP",
3 "moduleState": "READY",
4 "config": {
5 "appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
6 "endpoint": "https://your-endpoint.salesforce.com",
7 "sessionTimeout": 600,
8 "trackLifecycle": false,
9 "trackScreens": false
10 },
11 "consentManager": {
12 "consent": "OPT_IN",
13 "deviceId": "xxxxxxxx"
14 },
15 "sessionManager": {
16 "sessionId": "xxxxxxxx"
17 },
18 "eventManager": {
19 "queueSize": 3
20 },
21 "locationManager": {
22 "latitude": 37.7749,
23 "longitude": -122.4194,
24 "expiration": 1234567890
25 }
26}locationManager fields are omitted when no location is set.moduleState values are INITIALIZING, READY, and TENANT_DEPROVISIONED.