Lifecycle and Consent
The SDK lifecycle controls when data collection begins relative to user consent and identification.
States Recap
| State | Characteristics | Data Collection | Network Activity |
|---|---|---|---|
| Initialized | Context loaded, dependencies wired | None | None (except internal health) |
| Enabled | Tracking & features active | Yes (events, push registration) | Yes |
Transition Rules
- Calling
enablewhen already enabled returns an error that is safe to ignore. - Calling
disablestops future requests. Previously queued data is retained until the SDK is re-enabled.
Recommended Consent Flow
- The SDK initializes automatically.
- Present the consent UI to the user.
- Register the push token.
- After the user accepts, build an
EngagementCloudConfigurationand callenable. - Link the contact if available. Without a linked contact, events are attributed to an anonymous contact.
Consent and Linking Strategies
| Method | Pros | Cons |
|---|---|---|
| Enable early, then link later | Fast first event capture | Some events might be anonymous |
| Link before enabling | All events attributed | Slightly more complex gating |
| Delay both until consent | Maximum privacy compliance | Fewer early engagement signals |
Pausing In-App Tracking During Sensitive Flows
During sensitive flows like payment or data entry, displaying in-app messages can be disruptive. Use pause and resume to control when overlays can appear:
- Android
- Kotlin Multiplatform
- iOS
- Web
EngagementCloud.inApp.pause()
// ...
EngagementCloud.inApp.resume()
EngagementCloud.inApp.pause()
// ...
EngagementCloud.inApp.resume()
await EngagementCloud.shared.inApp.pause()
// ...
await EngagementCloud.shared.inApp.resume()
This feature is not supported on Web.
Detecting Enabled State
Use EngagementCloud.setup.isEnabled() to check if tracking is enabled.
Re-Enable After Disable
Call enable again with the same or updated configuration. Since disable() automatically calls unlink(), you must call link() again to re-identify the contact. Language settings and the push token are preserved.
Error Handling Strategy
Wrap calls to handle failures gracefully:
- Android
- Kotlin Multiplatform
- iOS
- Web
EngagementCloud.setup.enable(config)
.onFailure { throwable -> log("Enable failed: $throwable") }
EngagementCloud.setup.enable(config)
.onFailure { throwable -> log("Enable failed: $throwable") }
do { try await EngagementCloud.shared.setup.enable(config) } catch { print(error) }
try { await window.EngagementCloud.setup.enable(config); } catch(e) { console.error(e); }
Handling Consent Revocation
- Call
disable(). - The SDK automatically calls
unlink()if a contact is linked. When callingenable()again, calllink()to re-identify the contact. - Clear your app's local caches separately. The SDK does not manage them.
OpenID Rotation
If the token has expired:
- Acquire a new token.
- Call
linkAuthenticated(newToken). You do not need to callunlink()first.