Handling Active Consent

The SDK provides explicit control over user consent, allowing it to operate in either consented or non-consented mode.

Configuration inputs

Active consent behavior is controlled by two parameters:

  • activeConsentIntegration
    Enables or disables active consent logic in the SDK.

  • activeConsentAccepted
    Represents the user’s consent state:

    • true → consent granted (consented mode)
    • false → consent denied (non-consented mode)
    • null → no explicit consent state provided

Important:
The SDK does not persist consent across app launches. The application must provide the current activeConsentAccepted value on every SDK initialization.

Runtime updates

Consent can be updated during an active session using:

setActiveConsentAccepted(value)

  • Applies immediately within the current session
  • Only effective when activeConsentIntegration = true

Behavior summary

Active consent enabled (activeConsentIntegration = true)

  • SDK operates based on the provided activeConsentAccepted value.
  • Consent can be updated at runtime via setActiveConsentAccepted(...).
  • When activeConsentAccepted = false:
    • The SDK operates in non-consented mode.
    • Consent-based tracking is disabled.
    • Non-personalized campaigns can still be delivered.

Active consent disabled (activeConsentIntegration = false)

  • Active consent logic is ignored.
  • The SDK always operates in consented mode.
  • Full tracking is enabled regardless of activeConsentAccepted.
  • Any provided consent value is ignored.

Sample flows

User has not yet given consent

Initialize the SDK with activeConsentAccepted = false. The SDK does not perform consented tracking, but the user can still be served with non-personalized campaigns.

User grants consent during session

Call setActiveConsentAccepted(true) to switch the SDK to consented mode immediately.

User withdraws consent during session

Call setActiveConsentAccepted(false) to switch the SDK to non-consented mode immediately.

Active consent is disabled

If activeConsentIntegration = false, the SDK ignores all consent values and always behaves as if consent was given.

Sample code

Initialize the SDK with the current consent value, and update it during runtime if the user changes their consent choice.

func initWithActiveConsentAccepted() async { 

    DYSdk.initialize( 

        apiKey: "your_api_key", 

        dataCenter: .eu, 

        channel: .app, 

        activeConsentIntegration: true, 

        activeConsentAccepted: true 

    ) 

 

    // User grants consent 

    await DYSdk.shared().setActiveConsentAccepted(true) 

 

    // User withdraws consent 

    await DYSdk.shared().setActiveConsentAccepted(false) 

} 

Notes:

  • Set activeConsentAccepted during initialization based on the current consent state.
  • Use setActiveConsentAccepted(...) to update consent during the same session.
  • Upon the next app launch, the app must provide the consent value again during initialization.