Fix GA4 consent mode to grant analytics for non-EU/UK visitors#46464
Fix GA4 consent mode to grant analytics for non-EU/UK visitors#46464johnjeremiah wants to merge 3 commits into
Conversation
…itors Previously, the GA4 consent defaults denied analytics_storage for all visitors globally and set wait_for_update: 2000, meaning GA4 would wait up to 2 seconds for CookieYes to resolve geolocation before firing. For visitors on slower connections (mobile, slower CPUs) CookieYes often didn't respond in time, causing GA4 to drop the session entirely and record no pageview. Since ~95% of fleetdm.com's audience is outside the EU/UK and never sees the CookieYes consent banner, this wait was unnecessary for the vast majority of visitors. Replaces the single global consent default with two region-scoped calls: - All visitors: analytics_storage granted immediately (no wait_for_update) - EU/EEA/UK/Switzerland only: analytics_storage denied, wait_for_update: 2000 This matches how CookieYes Advanced Consent Mode is intended to work — the consent banner and its associated wait only apply where legally required (GDPR/UK GDPR). Also fixes the internal referrer check in the Salesforce attribution helper, which was using strict equality against 'https://fleetdm.com/' and missing any visitor whose last internal page was /pricing, /blog, etc. Changed to startsWith so any fleetdm.com referrer is correctly classified as direct traffic.
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR updates two areas: (1) the Salesforce helper now parses marketingAttributionCookie.referrer and treats a referrer as Fleet-origin when the hostname equals fleetdm.com or ends with .fleetdm.com (case-insensitive), and it no longer forces "Direct traffic" for unparseable referrers; (2) the site layout adds two gtag("consent","default",...) calls to apply immediate analytics/functionality consent for non-EU/UK visitors and deny analytics/functionality (with wait_for_update: 2000) for EU/EEA/UK/Switzerland. Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@website/api/helpers/salesforce/update-or-create-contact-and-account.js`:
- Around line 281-282: The referrer check that uses
marketingAttributionCookie.referrer.startsWith('https://fleetdm.com') can be
spoofed by domains like fleetdm.com.evil.com; replace the string prefix check in
the block that sets direct/internal referrer logic with proper URL hostname
parsing: use the URL constructor in a try/catch to extract referrerHostname from
marketingAttributionCookie.referrer, then treat it as internal if
referrerHostname === 'fleetdm.com' or referrerHostname.endsWith('.fleetdm.com');
ensure you still handle missing/invalid referrer values the same way (the same
branch that currently checks marketingAttributionCookie.referrer and startsWith
should be updated to use this hostname-based test).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 76a2876a-f24a-4764-9537-6aeffa270b45
📒 Files selected for processing (2)
website/api/helpers/salesforce/update-or-create-contact-and-account.jswebsite/views/layouts/layout.ejs
Previously, the GA4 consent defaults denied analytics_storage for all visitors globally and set wait_for_update: 2000, meaning GA4 would wait up to 2 seconds for CookieYes to resolve geolocation before firing. For visitors on slower connections (mobile, slower CPUs) CookieYes often didn't respond in time, causing GA4 to drop the session entirely and record no pageview. Since ~95% of fleetdm.com's audience is outside the EU/UK and never sees the CookieYes consent banner, this wait was unnecessary for the vast majority of visitors.
Replaces the single global consent default with two region-scoped calls:
This matches how CookieYes Advanced Consent Mode is intended to work — the consent banner and its associated wait only apply where legally required (GDPR/UK GDPR).
Also fixes the internal referrer check in the Salesforce attribution helper, which was using strict equality against 'https://fleetdm.com/' and missing any visitor whose last internal page was /pricing, /blog, etc. Changed to startsWith so any fleetdm.com referrer is correctly classified as direct traffic.
Summary by CodeRabbit