Skip to main content

Track consent and GDPR on web

Track user consent preferences selection events using the Enhanced Consent plugin.

Enhanced consent events must be manually tracked.

Install plugin

Tracker DistributionIncluded
sp.js
sp.lite.js

Download:

Download from GitHub Releases (Recommended)Github Releases (plugins.umd.zip)
Available on jsDelivrjsDelivr (latest)
Available on unpkgunpkg (latest)
javascript
window.snowplow(
'addPlugin',
'https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-enhanced-consent@latest/dist/index.umd.min.js',
['snowplowEnhancedConsentTracking', 'EnhancedConsentPlugin']
);
note

The plugin is available since version 3.8 of the tracker.

Events

APITo track
trackConsentAllowAcceptance of user consent
trackConsentSelectedA specific selection of consented scopes
trackConsentPendingThe unconfirmed selection about user consent
trackConsentImplicitThe implicit consent on user consent preferences
trackConsentDenyA denial of user consent
trackConsentExpiredThe expiration of a consent selection
trackConsentWithdrawnThe withdrawal of user consent
trackCmpVisibleThe render time of a consent management platform banner

With the exception of the CMP visible event, these methods use the same consent_preferences event schema.

To track the complete acceptance of a user consent prompt, you can use the trackConsentAllow method with the following attributes:

js
window.snowplow("trackConsentAllow:{trackerName}", {
consentScopes: ["necessary", "marketing", "personalization"],
basisForProcessing: "consent",
consentUrl: "https://www.example.com/",
consentVersion: "1.0",
domainsApplied: ["https://www.example.com/"],
gdprApplies: true
});

To track the specific selection of scopes of a user consent preferences, you can use the trackConsentSelected method with the following attributes:

js
window.snowplow("trackConsentSelected:{trackerName}", {
consentScopes: ["necessary", "marketing", "personalization"],
basisForProcessing: "consent",
consentUrl: "https://www.example.com/",
consentVersion: "1.0",
domainsApplied: ["https://www.example.com/"],
gdprApplies: true
});

Some consent management platform installations, allow the user to take website actions or/and navigating to other pages without accepting the consent prompt. To track the unconfirmed selection of user consent, you can use the trackConsentPending method with the following attributes:

js
window.snowplow("trackConsentPending:{trackerName}", {
consentScopes: ["necessary", "marketing", "personalization"],
basisForProcessing: "consent",
consentUrl: "https://www.example.com/",
consentVersion: "1.0",
domainsApplied: ["https://www.example.com/"],
gdprApplies: true
});

Some consent management platforms have a configuration which allows the setting of consent implicitly after a set of user interactions like clicks, scroll etc. To track the implicit selection of a user consent, you can use the trackConsentImplicit method with the following attributes:

js
window.snowplow("trackConsentImplicit:{trackerName}", {
consentScopes: ["necessary", "marketing", "personalization"],
basisForProcessing: "consent",
consentUrl: "https://www.example.com/",
consentVersion: "1.0",
domainsApplied: ["https://www.example.com/"],
gdprApplies: true
});

To track the complete denial of a user consent, you can use the trackConsentDeny method with the following attributes:

js
window.snowplow("trackConsentDeny:{trackerName}", {
consentScopes: ["necessary"],
basisForProcessing: "consent",
consentUrl: "https://www.example.com/",
consentVersion: "1.0",
domainsApplied: ["https://www.example.com/"],
gdprApplies: true
});

To track the expiration of a user consent, you can use the trackConsentExpired method with the following attributes:

js
window.snowplow("trackConsentExpired:{trackerName}", {
consentScopes: ["necessary", "marketing", "personalization"],
basisForProcessing: "consent",
consentUrl: "https://www.example.com/",
consentVersion: "1.0",
domainsApplied: ["https://www.example.com/"],
gdprApplies: true
});

To track the withdrawal of a user consent, you can use the trackConsentWithdrawn method with the following attributes:

js
window.snowplow("trackConsentWithdrawn:{trackerName}", {
consentScopes: ["necessary", "marketing", "personalization"],
basisForProcessing: "consent",
consentUrl: "https://www.example.com/",
consentVersion: "1.0",
domainsApplied: ["https://www.example.com/"],
gdprApplies: true
});

CMP visible

Consent management platform banners are an important part of a website’s first impression and performance. Snowplow provides a way to track what we call elapsedTime, which is the timestamp of the consent management platform banner becoming visible on the user’s screen.

js
window.snowplow("trackCmpVisible:{trackerName}", {
/* Using the performance.now API to retrieve the elapsed time from the page navigation. */
elapsedTime: performance.now(),
});

The CMP visible event uses this schema.