-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: add GDPR-compliant cookie consent banner #8022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9172003
feat: add GDPR-compliant cookie consent banners
roomote ede487f
chore: add gitignore for web-docs and remove build artifacts
roomote 1bdbe5a
chore: remove next-env.d.ts from git tracking
roomote c985d99
refactor: address PR feedback for cookie consent implementation
roomote 53fb082
Fixes Roo's work, makes the banner actually work
brunobergher 7568a61
Removes stray code
brunobergher 0c2afdc
Fixes tests, hope this is legit
brunobergher 1b7b71c
there are no tests in this app
brunobergher a989695
Generalzies cookie scope to *.roocode.com, exposts constants
brunobergher 668cc1c
Remove apps/web-docs
mrubens fd84022
Merge remote-tracking branch 'origin/main' into feat/gdpr-cookie-consent
mrubens 66a90e8
Update pnpm lock
mrubens 9162956
Update apps/web-roo-code/src/components/CookieConsent.tsx
mrubens 8bbafa3
Use tldts to get the domain
mrubens e4047f7
Cleanup
mrubens 9fc5f6c
Use shared types
mrubens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
apps/web-roo-code/src/components/CookieConsentWrapper.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| "use client" | ||
|
|
||
| import React, { useState, useEffect } from "react" | ||
| import ReactCookieConsent from "react-cookie-consent" | ||
| import { Cookie } from "lucide-react" | ||
| import { getDomain } from "tldts" | ||
| import { CONSENT_COOKIE_NAME } from "@roo-code/types" | ||
| import { dispatchConsentEvent } from "@/lib/analytics/consent-manager" | ||
|
|
||
| /** | ||
| * GDPR-compliant cookie consent banner component | ||
| * Handles both the UI and consent event dispatching | ||
| */ | ||
| export function CookieConsentWrapper() { | ||
| const [cookieDomain, setCookieDomain] = useState<string | null>(null) | ||
|
|
||
| useEffect(() => { | ||
| // Get the appropriate domain using tldts | ||
| if (typeof window !== "undefined") { | ||
| const domain = getDomain(window.location.hostname) | ||
| setCookieDomain(domain) | ||
| } | ||
| }, []) | ||
|
|
||
| const handleAccept = () => { | ||
| dispatchConsentEvent(true) | ||
| } | ||
|
|
||
| const handleDecline = () => { | ||
| dispatchConsentEvent(false) | ||
| } | ||
|
|
||
| const extraCookieOptions = cookieDomain | ||
| ? { | ||
| domain: cookieDomain, | ||
| } | ||
| : {} | ||
|
|
||
| const containerClasses = ` | ||
| fixed bottom-2 left-2 right-2 z-[999] | ||
| bg-black/95 dark:bg-white/95 | ||
| text-white dark:text-black | ||
| border-t-neutral-800 dark:border-t-gray-200 | ||
| backdrop-blur-xl | ||
| border-t | ||
| font-semibold | ||
| rounded-t-lg | ||
| px-4 py-4 md:px-8 md:py-4 | ||
| flex flex-wrap items-center justify-between gap-4 | ||
| text-sm font-sans | ||
| `.trim() | ||
|
|
||
| const buttonWrapperClasses = ` | ||
| flex | ||
| flex-row-reverse | ||
| items-center | ||
| gap-2 | ||
| `.trim() | ||
|
|
||
| const acceptButtonClasses = ` | ||
| bg-white text-black border-neutral-800 | ||
| dark:bg-black dark:text-white dark:border-gray-200 | ||
| hover:opacity-50 | ||
| transition-opacity | ||
| rounded-md | ||
| px-4 py-2 mr-2 | ||
| text-sm font-bold | ||
| cursor-pointer | ||
| focus:outline-none focus:ring-2 focus:ring-offset-2 | ||
| `.trim() | ||
|
|
||
| const declineButtonClasses = ` | ||
| dark:bg-white dark:text-black dark:border-gray-200 | ||
| bg-black text-white border-neutral-800 | ||
| hover:opacity-50 | ||
| border border-border | ||
| transition-opacity | ||
| rounded-md | ||
| px-4 py-2 | ||
| text-sm font-bold | ||
| cursor-pointer | ||
| focus:outline-none focus:ring-2 focus:ring-offset-2 | ||
| `.trim() | ||
|
|
||
| return ( | ||
| <div role="banner" aria-label="Cookie consent banner" aria-live="polite"> | ||
| <ReactCookieConsent | ||
| location="bottom" | ||
| buttonText="Accept" | ||
mrubens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| declineButtonText="Decline" | ||
| cookieName={CONSENT_COOKIE_NAME} | ||
| expires={365} | ||
| enableDeclineButton={true} | ||
| onAccept={handleAccept} | ||
| onDecline={handleDecline} | ||
| containerClasses={containerClasses} | ||
| buttonClasses={acceptButtonClasses} | ||
| buttonWrapperClasses={buttonWrapperClasses} | ||
| declineButtonClasses={declineButtonClasses} | ||
| extraCookieOptions={extraCookieOptions} | ||
| disableStyles={true} | ||
| ariaAcceptLabel={`Accept`} | ||
| ariaDeclineLabel={`Decline`}> | ||
| <div className="flex items-center gap-2"> | ||
| <Cookie className="size-5 hidden md:block" /> | ||
| <span>Like most of the internet, we use cookies. Are you OK with that?</span> | ||
| </div> | ||
| </ReactCookieConsent> | ||
| </div> | ||
| ) | ||
| } | ||
92 changes: 92 additions & 0 deletions
92
apps/web-roo-code/src/components/providers/google-analytics-provider.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| "use client" | ||
|
|
||
| import { useEffect, useState } from "react" | ||
| import Script from "next/script" | ||
| import { hasConsent, onConsentChange } from "@/lib/analytics/consent-manager" | ||
|
|
||
| // Google Tag Manager ID | ||
| const GTM_ID = "AW-17391954825" | ||
|
|
||
| /** | ||
| * Google Analytics Provider | ||
| * Only loads Google Tag Manager after user gives consent | ||
| */ | ||
| export function GoogleAnalyticsProvider({ children }: { children: React.ReactNode }) { | ||
| const [shouldLoad, setShouldLoad] = useState(false) | ||
|
|
||
| useEffect(() => { | ||
| // Check initial consent status | ||
| if (hasConsent()) { | ||
| setShouldLoad(true) | ||
| initializeGoogleAnalytics() | ||
| } | ||
|
|
||
| // Listen for consent changes | ||
| const unsubscribe = onConsentChange((consented) => { | ||
| if (consented && !shouldLoad) { | ||
| setShouldLoad(true) | ||
| initializeGoogleAnalytics() | ||
| } | ||
| }) | ||
|
|
||
| return unsubscribe | ||
| }, [shouldLoad]) | ||
|
|
||
| const initializeGoogleAnalytics = () => { | ||
| // Initialize the dataLayer and gtag function | ||
| if (typeof window !== "undefined") { | ||
| window.dataLayer = window.dataLayer || [] | ||
| window.gtag = function (...args: GtagArgs) { | ||
| window.dataLayer.push(args) | ||
| } | ||
| window.gtag("js", new Date()) | ||
| window.gtag("config", GTM_ID) | ||
| } | ||
| } | ||
|
|
||
| // Only render Google Analytics scripts if consent is given | ||
| if (!shouldLoad) { | ||
| return <>{children}</> | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {/* Google tag (gtag.js) - Only loads after consent */} | ||
| <Script | ||
| src={`https://www.googletagmanager.com/gtag/js?id=${GTM_ID}`} | ||
| strategy="afterInteractive" | ||
| onLoad={() => { | ||
| console.log("Google Analytics loaded with consent") | ||
| }} | ||
| /> | ||
| <Script id="google-analytics-init" strategy="afterInteractive"> | ||
| {` | ||
| window.dataLayer = window.dataLayer || []; | ||
| function gtag(){dataLayer.push(arguments);} | ||
| gtag('js', new Date()); | ||
| gtag('config', '${GTM_ID}'); | ||
| `} | ||
| </Script> | ||
| {children} | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| // Type definitions for Google Analytics | ||
| type GtagArgs = ["js", Date] | ["config", string, GtagConfig?] | ["event", string, GtagEventParameters?] | ||
|
|
||
| interface GtagConfig { | ||
| [key: string]: unknown | ||
| } | ||
|
|
||
| interface GtagEventParameters { | ||
| [key: string]: unknown | ||
| } | ||
|
|
||
| // Declare global types for TypeScript | ||
| declare global { | ||
| interface Window { | ||
| dataLayer: GtagArgs[] | ||
| gtag: (...args: GtagArgs) => void | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.