Use consent management solutions to respect site visitor privacy in Webflow Analyze & Optimize.
Disclaimer
The content presented here is provided only for informational purposes and is not meant to serve as legal advice. You might consider working with professional legal counsel to determine how privacy laws like the General Data Protection Regulation (GDPR) and the California Consumer Privacy Act (CCPA) may or may not apply to you. Visit our privacy FAQs to learn more.
To address potential privacy law compliance issues when using Webflow Analyze and/or Optimize, you might consider implementing a consent management solution and a consent banner that allows site visitors to opt in or out of tracking. You can use a third-party consent management platform (CMP) App or integration, integrate an existing CMP provider via Webflow’s APIs, or design a consent banner and manage site tracking consent yourself via custom code.
Before you get started
Set up
Analyze
and/or
Optimize
and set your tracking default to
Let visitors opt out or
Don’t track by default.
Manage site tracking consent with a CMP App or integration
You can use consent management platform (CMPs) Apps and integrations to address potential privacy law compliance issues when using Webflow Analyze and/or Optimize.
Manage site consent with DataGrail
DataGrail Consent is an integrated CMP that integrates directly with Google Tag Manager. DataGrail adjusts your Analyze and/or Optimize tracking default settings based on the location of the site visitor (and what consent policy applies to them) and their consent choice (through the banner notice that appears on your site or a universal opt-out signal). Learn more about integrating DataGrail for consent management.
Manage site consent with Finsweet
The Finsweet Components App integrates directly with Webflow and provides a solution to manage consent tracking and give site visitors the option to opt in or out of site tracking. Learn more about using the Finsweet Components App for consent management.
Integrate an existing consent management platform
If you already use a consent management platform, you can use custom code to connect it to Webflow via Webflow’s APIs.
Note
Our support team is unable to provide direct help with custom code
setup or troubleshooting, as these topics fall outside the scope
of our
customer support policy.
If you run into issues with custom code, please let us know on the
Webflow Forum,
where the entire Webflow community (staff included) can provide additional
help and resources.
Webflow offers APIs to send OptIn
and OptOut
signals, as well as check the current state of the flag for a given users:
// Ensure Webflow APIs have initialized
Webflow.push(() => {
// First, detect the current state
const isOptedOut = Webflow.analytics.getIsOptedOut();
if (isOptedOut) {
//
// Your CMP logic to detect an optIn signal goes here
//
// Then you call Webflow to let us know there's been an optIn
Webflow.analytics.optIn();
}
else {
//
// Your CMP logic to detect an optOut signal goes here
//
// Then you call Webflow to let us know there's been an optOut
Webflow.analytics.optOut();
}
});
Integrate OneTrust
If you use OneTrust, the following code sample can help your team get started. It checks the OneTrust consent cookie and calls the Webflow OptIn
/OptOut
APIs accordingly.
Note
This code sample is provided as-is and is not supported by Webflow.
Your team should customize it for your deployment of OneTrust, including
which OneTrust group you check per your policy.
Webflow.push(() => {
// Function to opt in or out based on consent preferences
const handleWebflowAnalyticsConsent = () => {
try {
// Logic to check consent groups from the OneTrust cookie
const otCookieKey = 'OptanonConsent=';
const otCookie = document.cookie.split('; ').find(row => row.startsWith(otCookieKey));
if (!otCookie) {
throw new Error('OneTrust cookie not found.');
}
const otGroupsKey = 'groups=';
const otGroups = decodeURIComponent(otCookie.split('&').find(row => row.startsWith(otGroupsKey)).split('=')[1]);
// OneTrust groups: 1 = necessary, 2 = performance, 3 = functional, 4 = targeting
const OT_FUNCTIONAL_CONSENT = '3:1'; // Ensure this matches your expected consent group
// Check for functional cookies group
const hasOptedIn = otGroups.indexOf(OT_FUNCTIONAL_CONSENT) !== -1;
// Adjust Webflow Analytics opt-in/out based on consent
if (hasOptedIn) {
Webflow.analytics.optIn();
} else {
Webflow.analytics.optOut();
}
} catch (e) {
console.error('Error handling OneTrust consent:', e);
}
};
// Set up the OneTrust consent change listener to check when preferences change
if (typeof OneTrust !== 'undefined' && OneTrust.OnConsentChanged) {
OneTrust.OnConsentChanged(() => {
handleWebflowAnalyticsConsent();
});
}
// Initial check when the page loads
handleWebflowAnalyticsConsent();
});
Integrate TrustArc
If you use TrustArc, the following code sample can help your team get started. It checks the TrustArc consent preferences and calls the Webflow OptIn
/OptOut
APIs accordingly.
Note
This code sample is provided as-is and is not supported by Webflow.
Your
team should customize it for your deployment of TrustArc, including
which
TrustArc level you check per your policy.
Webflow.push(() => {
try {
// Logic to check consent preferences from TrustArc
const ta_gdpr_prefs = JSON.parse(localStorage.getItem('truste.cookie.notice_gdpr_prefs')).value;
// TrustArc levels: 0 = required, 1 = functional, 2 = advertising
const TA_FUNCTIONAL = 1; // Ensure this matches your expected consent group
// Check for functional cookies group
const hasOptedIn = ta_gdpr_prefs.indexOf(TA_FUNCTIONAL) >= 0;
// Adjust Webflow Analytics opt-in/out based on consent
if (hasOptedIn) {
Webflow.analytics.optIn();
} else {
Webflow.analytics.optOut();
}
} catch (e) {
console.error('Error handling TrustArc consent:', e);
}
});
Manage site tracking consent via custom code
Design the consent banner
To design your consent banner:
- Create and design a banner however you like, including the consent notification message
- Give your banner an ID (e.g., consentPopup)
- Add an “Accept” button
- Give your button a class (e.g., consentButton)
- Give your button an ID of optIn
- Add a “Decline” or “Close” button
- Give your button the same class as the “Accept” button
- Give your button an ID of optOut
- (Optional) Include a “Learn more” link to link site visitors to your privacy policy page
- Drag the banner inside of a div to serve as your popup wrapper
- Give the div a class (e.g., popupWrapper)
- Set the popup wrapper’s position to fixed
- Choose a preset position (e.g., bottom) or manually adjust the position of the popup wrapper
- Make the popup wrapper a component
- Add the component to all of your site pages
Animate the consent banner
First, create an interaction that hides the consent banner when a site visitor opts in to tracking:
- Select the “Accept” button on the canvas
- Go to Interactions panel > Element trigger
- Click the “plus” icon to create a new element trigger
- Choose Mouse click (tap)
- Go to Trigger settings and click Class
- Go to On 1st click and click Select an action
- Choose Start an animation
- Click the “plus” icon to create a custom animation
- Give your custom animation a name (e.g., “Close the consent popup”)
- Select the popup wrapper on the canvas
- Click the “plus” icon next to Actions to add an action to your animation
- Go to Miscellaneous and choose Hide/show
- Go to Hide/show and set the display to none
- Click Save
Then, create a similar interaction to hide the consent banner when a site visitor opts out of tracking:
- Select the “Decline” button on the canvas
- Click the Mouse click (tap) element trigger you just created
- Go to On 1st click and click the radio button next to your “Close the consent popup” custom animation
- Click Done
Next, create an interaction to show the consent banner when the page loads:
- Go to Interactions panel > Page trigger
- Click the “plus” icon to create a new page trigger
- Choose Page load
- Go to When page starts loading and click Select an action
- Choose Start an animation
- Click the “plus” icon to create a custom animation
- Give your custom animation a name (e.g., “Show the consent popup”)
- Select the popup wrapper on the canvas
- Click the “plus” icon next to Actions to add an action to your animation
- Go to Hide/show and set the display to whichever display setting you want (except none)
- Check Set as initial state
- Click Save
Finally, if your site has more than one page, make sure the consent banner loads on each of your pages:
- Open another page on your site
- Go to Interactions panel > Page trigger
- Click the “plus” icon to create a new page trigger
- Choose Page load
- Go to When page starts loading and click Select an action
- Choose Start an animation
- Choose your “Show the consent popup” custom animation
- Repeat the above steps for all pages on your site
Important
Make sure that you select the popup wrapper when you add actions
to your animations. If you apply the actions to the banner itself,
the custom code may not function properly.
Embed custom code
To make the consent banner work, go to Site settings > Custom code > Footer code and embed the following script:
<script>
Webflow.push(() => {
const isOptedOut = Webflow.analytics.getIsOptedOut();
const optOutButton = document.querySelector('#optOut');
const optInButton = document.querySelector('#optIn');
if (isOptedOut) {
optInButton.addEventListener("click", function () {
Webflow.analytics.optIn();
});
} else {
optOutButton.addEventListener("click", function () {
Webflow.analytics.optOut();
});
}
});
</script>
Note
Site visitors’ ad blockers may prevent site tracking even if they
opt in.