Skip to content

Commit 9d5eabd

Browse files
committed
Use proper storage for users with consent
1 parent 346b4de commit 9d5eabd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

apps/web-roo-code/src/components/providers/posthog-provider.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { usePathname, useSearchParams } from "next/navigation"
44
import posthog from "posthog-js"
55
import { PostHogProvider as OriginalPostHogProvider } from "posthog-js/react"
66
import { useEffect, Suspense } from "react"
7+
import { hasConsent } from "@/lib/analytics/consent-manager"
78

89
function PageViewTracker() {
910
const pathname = usePathname()
@@ -49,7 +50,10 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
4950
)
5051
}
5152

52-
// Initialize PostHog with cookieless mode support
53+
// Check if user has already consented to cookies
54+
const userHasConsented = hasConsent()
55+
56+
// Initialize PostHog with appropriate persistence based on consent
5357
posthog.init(posthogKey, {
5458
api_host: posthogHost || "https://us.i.posthog.com",
5559
capture_pageview: false, // We handle pageview tracking manually
@@ -61,7 +65,7 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
6165
save_referrer: true, // Save referrer information
6266
save_campaign_params: true, // Save UTM parameters
6367
respect_dnt: true, // Respect Do Not Track
64-
persistence: "memory", // Default persistence with cookies
68+
persistence: userHasConsented ? "localStorage+cookie" : "memory", // Use localStorage if consented, otherwise memory-only
6569
opt_out_capturing_by_default: false, // Start tracking immediately
6670
})
6771
}

apps/web-roo-code/src/lib/analytics/consent-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function onConsentChange(callback: (consented: boolean) => void): () => v
5353
*/
5454
export function handleConsentAccept(): void {
5555
if (typeof window !== "undefined" && posthog.__loaded) {
56-
// User accepted - ensure cookie tracking is enabled
56+
// User accepted - ensure localStorage+cookie persistence is enabled
5757
posthog.opt_in_capturing()
5858
posthog.set_config({
5959
persistence: "localStorage+cookie",

0 commit comments

Comments
 (0)