VWO + DataGrail Consent
VWO provides native consent management features including custom CMP configuration, consent blocking modes, and anti-flicker capabilities. This guide shows you how to integrate VWO with DataGrail's consent banner.
Recommended Approach
VWO offers a Custom CMP option in its dashboard that allows you to configure JavaScript code to read DataGrail's consent state. This approach gives you centralized consent management in the VWO dashboard without requiring complex website code changes.
Dashboard Configuration
Configure Consent Settings
Navigate to your VWO dashboard:
- Go to Configurations > Websites and Apps
- Select your website and navigate to the Code tab
- Under Consent Management, select Custom from the CMP dropdown
- Choose your preferred blocking mode (see comparison below)
Add Consent Detection Code
In VWO's custom consent field, add this JavaScript function that reads DataGrail's consent state via the DG_BANNER_API:
function isConsentGiven() {
// Check if DataGrail banner API is available
if (window.DG_BANNER_API) {
if (window.DG_BANNER_API.categoryEnabled('performance')) {
return "1"; // Accepted
}
// If banner API exists but category not enabled, check if preferences were set
var prefs = window.DG_BANNER_API.getConsentPreferences();
if (prefs && prefs.cookieOptions) {
return "2"; // Rejected (preferences exist but performance not enabled)
}
}
return "3"; // Unknown (banner not yet resolved)
}
VWO calls this function to determine consent status:
"1"= Accepted — VWO runs and tracks"2"= Rejected — VWO stops/doesn't track"3"= Unknown — behavior depends on blocking mode
VWO Blocking Modes
VWO provides three blocking modes you can configure in the dashboard:
| Mode | Experiments Display? | Tracking Active? | Use Case |
|---|---|---|---|
| Completely Block VWO | No | No | Strictest compliance — nothing runs until consent |
| Partially Block VWO | Yes | No | Show variants without tracking (measurement gated) |
| Do Not Block VWO | Yes | Yes | Experiments run while consent pending |
Recommended: Use Partially Block VWO for the best balance — users see personalized experiences immediately, but measurement only starts after consent is granted.
SmartCode Placement
VWO's SmartCode should be placed in your page <head> before the DataGrail consent banner script:
<!DOCTYPE html>
<html>
<head>
<!-- VWO SmartCode (from VWO dashboard) -->
<script type='text/javascript' id='vwoCode'>
// Your VWO SmartCode here
</script>
<!-- DataGrail Consent Banner -->
<script src="https://cdn.datagrail.io/YOUR_TENANT_ID.js"></script>
</head>
<body>
<!-- Your content -->
</body>
</html>
VWO explicitly recommends against loading SmartCode via Google Tag Manager. GTM's async loading causes visible page flicker and timeout issues with A/B tests. Always load VWO SmartCode directly in the <head>.
Anti-Flicker Coordination
VWO includes a blur-based anti-flicker mechanism that can hide page content while consent is being collected. You can configure VWO's anti-flicker to exclude the DataGrail banner:
In VWO's anti-flicker settings:
- Filter selector:
.dg-banner(or your banner's CSS class) - Filter time:
"best"(waits for variant + consent) - Filter tolerance:
4000(timeout in ms)
This ensures the consent banner remains visible over a blurred/hidden page, then reveals the page with the correct variant after consent.
Cookie and Storage Patterns
Add these patterns as cookie rules in your DataGrail Consent dashboard under Cookie Management. For each pattern, select Add Rule, enter the match criteria, set the Category to Performance, and configure the appropriate retention:
| Match Criteria | Category | Retention | Purpose |
|---|---|---|---|
_vwo_uuid* | Performance | 400 days | Unique visitor ID |
_vwo_consent | Performance | 400 days | VWO consent status (1=granted, 0=denied) |
_vis_opt_exp_* | Performance | 400 days | Variation assignments and goal tracking |
_vis_opt_s | Performance | 400 days | Session count |
_vis_opt_out | Performance | 400 days | Visitor opt-out flag |
_vwo_ds | Performance | 400 days | Persistent visitor data |
_vwo_sn | Performance | Session | Session information |
_vwo | Performance | 400 days | Safari consolidated cookie |
Alternative: Using Callbacks
If you prefer to handle consent coordination in your website code instead of VWO's dashboard, you can use DataGrail's callback system:
<script>
window.dgEvent = window.dgEvent || [];
function handleVwoConsent(preferences) {
if (window.DG_BANNER_API.categoryEnabled('performance')) {
document.cookie = "_vwo_consent=1; path=/; max-age=31536000";
} else {
document.cookie = "_vwo_consent=0; path=/; max-age=31536000";
}
}
window.dgEvent.push({
event: "initial_preference_callback",
params: handleVwoConsent
});
window.dgEvent.push({
event: "preference_callback",
params: handleVwoConsent
});
</script>
Consent Mode Comparison
Here's how different configurations compare:
| Configuration | Setup Location | Variants Display? | Tracking | Maintenance |
|---|---|---|---|---|
| VWO Custom CMP (recommended) | VWO dashboard | Configurable | Gated | Centralized in VWO |
| Manual preference_callback | Website code | Depends on mode | Gated | Requires code changes |
| Custom Triggers | VWO dashboard (+ support request) | Yes | Trigger-gated | Requires VWO support setup |
Troubleshooting
VWO tracking isn't stopping after consent is rejected
Check that:
- Your
isConsentGiven()function returns"2"when consent is rejected - You've selected a blocking mode in VWO dashboard (not "Do Not Block VWO")
- The
_vwo_consentcookie is being set to0when consent is denied - You've cleared your browser cookies to test fresh visitor behavior
Page flickers when VWO loads
Flicker usually indicates:
- SmartCode is loading via GTM (use direct
<head>placement instead) - You're using "Completely Block VWO" mode with consent-gated loading
- Anti-flicker timeout is too short — increase filter tolerance
- SmartCode is placed too low in the
<head>— move it higher
Consent banner is blurred/hidden by VWO's anti-flicker
Configure VWO's anti-flicker Filter selector to exclude your banner:
- In VWO dashboard: set selector to
.dg-banner(or your banner's CSS class) - This tells VWO to keep the banner visible while blurring the rest of the page
VWO campaigns show but tracking never starts even with consent
If you're using "Partially Block VWO" mode:
- Verify your
isConsentGiven()function returns"1"after consent granted - Check browser console for VWO errors
- Ensure VWO's tracking scripts aren't blocked by other cookie blockers or ad blockers
- Test with VWO's Preview mode to verify campaign configuration
Related Resources
- VWO Consent Management Documentation
- DataGrail Consent Banner Documentation
- For questions, contact support@datagrail.io
Disclaimer: The information contained in this message does not constitute as legal advice. We would advise seeking professional counsel before acting on or interpreting any material.