Skip to content

Add cookie consent banner and gate GTM and PostHog on consent - #7951

Open
adidavid014 wants to merge 3 commits into
mainfrom
devin/1795205109-cookie-consent-banner
Open

adidavid014 wants to merge 3 commits into
mainfrom
devin/1795205109-cookie-consent-banner

Conversation

@adidavid014

@adidavid014 adidavid014 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a cookie banner to buildwithfern.com/learn with Accept all, Reject all and Manage. Manage shows Analytics and Marketing toggles. This is a stopgap with no vendor; we can swap in Transcend later.

  • fern/cookie-consent.js loads with beforeInteractive. It shares the fern_cookie_consent=analytics:1|marketing:0 cookie on .buildwithfern.com with the marketing site (fern-api/marketing-site#582).
  • Analytics controls Fern's PostHog through settings.require-analytics-consent: true. The script sets window.fernAnalyticsConsent and dispatches fern-analytics-consent.
  • Marketing controls GTM. GTM is removed from analytics.gtm because Fern doesn't gate that on consent.
    • The script injects GTM-55W3VNDW after consent, with a Consent Mode default that sets analytics_storage from the Analytics choice.
    • It forwards fern-docs-track-analytics events to dataLayer, without email.
  • Revocation compares against what this page already turned on (active), not the previous cookie. Revoking a category clears its cookies and reloads the page. The cookie is re-read on focus, so changes from another tab or from the marketing site apply too.
  • The footer "Cookie Settings" link (data-fern-cookie-settings) reopens the banner with the toggles.

Verified with fern docs dev in Chrome:

  • First visit sends no GTM request, and fernAnalyticsConsent is false.
  • Analytics only sets fernAnalyticsConsent to true and loads no GTM.
  • The toggles show the saved choices.
  • Accept all loads gtm.js.
  • Reject all reloads the page.

Not verified locally: Fern's built-in PostHog, which doesn't load in local preview.

Manage

Link to Devin session: https://app.devin.ai/sessions/a28af354dc5b4d36a8c96f5a9731b5a8
Open in Devin Desktop: https://app.devin.ai/desktop/session/a28af354dc5b4d36a8c96f5a9731b5a8?variant=devin
Requested by: @adidavid014


🟢 Devin fixed all 2 findings · Follow Devin's work

Devin Review

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

Copy link
Copy Markdown
Contributor

🌿 Preview your docs: https://fern-preview-devin-1795205109-cookie-consent-banner.docs.buildwithfern.com/learn

adidavid014 and others added 2 commits November 20, 2026 20:23
…state

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 findings. Devin automatically fixed all 2 findings.

Fixed by Devin (2)
  • Analytics storage remains denied after consent — apply() now pushes a Consent Mode update (analytics_storage granted) when analytics is granted while GTM is already running.
  • Consent rejection leaves analytics running — Revocation now compares against in-page state (active), not the previous cookie, and the cookie is re-synced on focus, so blocked cookies or another tab's revoke still turn PostHog off and reload.

View findings in Devin Review · Follow Devin's work

Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant