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)
activeConsentIntegration = true)- SDK operates based on the provided
activeConsentAcceptedvalue. - 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)
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
Pass the current consent state during initialization, and use setActiveConsentAccepted(...) to update it dynamically during the session.
async function initializeActiveConsentAcceptedExample() {
initialize({
apiKey: 'your-api-key',
dataCenter: DataCenter.US,
deviceId: 'example-deviceId',
channel: Channel.APP,
ip: '1.2.3.4',
locale: 'en',
isImplicitPageview: true,
isImplicitImpressionMode: false,
activeConsentIntegration: true,
activeConsentAccepted: true,
})
.then(result => {
console.log('Initialized:', result);
})
.catch(error => {
console.error('Initialization failed:', error);
});
// User grants consent
DYPlugin.setActiveConsentAccepted(true)
.then(result => {
console.log('Active consent accepted set successfully:', result);
})
.catch(error => {
console.error('setActiveConsentAccepted failed:', error);
});
// User withdraws consent
DYPlugin.setActiveConsentAccepted(false)
.then(result => {
console.log('Active consent withdrawn successfully:', result);
})
.catch(error => {
console.error('setActiveConsentAccepted failed:', error);
});
} Notes:
- Set
activeConsentAcceptedduring initialization based on the current consent state. - Use
DYPlugin.setActiveConsentAccepted(...)to update consent during the same session. - The SDK does not persist consent across app launches, so the app must pass the current value again upon each initialization.
Updated about 3 hours ago