dify/web/app/components/base/analytics-consent/cookieyes-consent-bridge.tsx
Coding On Star 8d293023cc
feat: gate cloud analytics behind cookie consent (#39408)
Co-authored-by: CodingOnStar <hanxujiang@dify.com>
2026-07-23 02:40:54 +00:00

31 lines
838 B
TypeScript

'use client'
import { useEffect } from 'react'
import {
getAnalyticsConsentFromCookie,
getAnalyticsConsentFromEvent,
setAnalyticsConsent,
} from './consent-store'
export const COOKIEYES_CONSENT_UPDATE_EVENT = 'cookieyes_consent_update'
export function CookieYesConsentBridge() {
useEffect(() => {
setAnalyticsConsent(getAnalyticsConsentFromCookie(document.cookie))
const handleConsentUpdate = (event: Event) => {
if (!(event instanceof CustomEvent)) return
const nextConsent = getAnalyticsConsentFromEvent(event.detail)
if (nextConsent) setAnalyticsConsent(nextConsent)
}
document.addEventListener(COOKIEYES_CONSENT_UPDATE_EVENT, handleConsentUpdate)
return () => {
document.removeEventListener(COOKIEYES_CONSENT_UPDATE_EVENT, handleConsentUpdate)
}
}, [])
return null
}