mirror of
https://github.com/langgenius/dify.git
synced 2026-07-26 14:18:35 +08:00
32 lines
792 B
TypeScript
32 lines
792 B
TypeScript
'use client'
|
|
|
|
import type { AmplitudeInitializationOptions } from './init'
|
|
import { useEffect } from 'react'
|
|
import { useAnalyticsConsent } from '@/app/components/base/analytics-consent/consent-store'
|
|
import { ensureAmplitudeInitialized, setAmplitudeOptOut } from './init'
|
|
|
|
export type IAmplitudeProps = AmplitudeInitializationOptions & {
|
|
active?: boolean
|
|
}
|
|
|
|
export function AmplitudeProvider({
|
|
active = true,
|
|
sessionReplaySampleRate = 0.5,
|
|
}: IAmplitudeProps) {
|
|
const consent = useAnalyticsConsent()
|
|
|
|
useEffect(() => {
|
|
if (!active || consent !== 'granted') {
|
|
setAmplitudeOptOut(true)
|
|
return
|
|
}
|
|
|
|
ensureAmplitudeInitialized({
|
|
sessionReplaySampleRate,
|
|
})
|
|
setAmplitudeOptOut(false)
|
|
}, [active, consent, sessionReplaySampleRate])
|
|
|
|
return null
|
|
}
|