-
-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathConsentManager.tsx
More file actions
71 lines (65 loc) · 1.63 KB
/
Copy pathConsentManager.tsx
File metadata and controls
71 lines (65 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as React from 'react'
import type { ReactNode } from 'react'
import {
ConsentBanner,
ConsentDialog,
ConsentManagerProvider,
type ConsentManagerOptions,
} from '@c15t/react'
import { gtag } from '@c15t/scripts/google-tag'
const C15T_BACKEND_URL = 'https://eager-kayak-phobos-tanstack-com.inth.app'
const GOOGLE_ANALYTICS_ID = 'G-JMT1Z50SPS'
const LEGAL_LINKS: Array<'privacyPolicy' | 'termsOfService'> = [
'privacyPolicy',
'termsOfService',
]
const consentManagerOptions = {
mode: 'hosted',
backendURL: C15T_BACKEND_URL,
consentCategories: ['necessary', 'measurement'],
overrides: import.meta.env.DEV ? { country: 'DE' } : undefined,
legalLinks: {
privacyPolicy: {
href: '/privacy',
target: '_self',
},
termsOfService: {
href: '/terms',
target: '_self',
},
},
scripts: [
gtag({
id: GOOGLE_ANALYTICS_ID,
category: 'measurement',
}),
],
} satisfies ConsentManagerOptions
export function ConsentManager({
children,
showControls = true,
}: {
children: ReactNode
showControls?: boolean
}) {
const [hasMounted, setHasMounted] = React.useState(false)
React.useEffect(() => {
setHasMounted(true)
}, [])
// c15t injects runtime theme styles; mount after hydration so Start's SSR
// markup stays byte-stable.
if (!hasMounted) {
return <>{children}</>
}
return (
<ConsentManagerProvider options={consentManagerOptions}>
{showControls ? (
<>
<ConsentBanner legalLinks={LEGAL_LINKS} />
<ConsentDialog legalLinks={LEGAL_LINKS} />
</>
) : null}
{children}
</ConsentManagerProvider>
)
}