@c15t/scripts 2.1.0 → 2.2.0-canary-20260804162155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +62 -0
- package/README.md +32 -20
- package/dist/e2e-test-utils.cjs +51 -10
- package/dist/e2e-test-utils.js +37 -3
- package/dist/engine/compile.cjs +9 -5
- package/dist/engine/runtime.cjs +103 -17
- package/dist/engine/runtime.js +94 -12
- package/dist/registry.cjs +97 -12
- package/dist/registry.js +80 -0
- package/dist/resolve.cjs +9 -5
- package/dist/types.cjs +17 -13
- package/dist/vendors/_shared/attributes.cjs +13 -9
- package/dist/vendors/_shared/google-consent.cjs +14 -9
- package/dist/vendors/_shared/install-builders.cjs +12 -8
- package/dist/vendors/_shared/script-url.cjs +16 -12
- package/dist/vendors/ads-and-pixels/linkedin-insights.cjs +9 -5
- package/dist/vendors/ads-and-pixels/meta-pixel.cjs +13 -9
- package/dist/vendors/ads-and-pixels/microsoft-uet.cjs +11 -7
- package/dist/vendors/ads-and-pixels/reddit-pixel.cjs +9 -5
- package/dist/vendors/ads-and-pixels/snapchat-pixel.cjs +11 -7
- package/dist/vendors/ads-and-pixels/tiktok-pixel.cjs +9 -5
- package/dist/vendors/ads-and-pixels/x-pixel.cjs +9 -5
- package/dist/vendors/analytics/adobe-analytics.cjs +90 -0
- package/dist/vendors/analytics/adobe-analytics.js +49 -0
- package/dist/vendors/analytics/ahrefs-analytics.cjs +11 -7
- package/dist/vendors/analytics/amplitude.cjs +193 -0
- package/dist/vendors/analytics/amplitude.js +134 -0
- package/dist/vendors/analytics/clearbit.cjs +69 -0
- package/dist/vendors/analytics/clearbit.js +28 -0
- package/dist/vendors/analytics/cloudflare-web-analytics.cjs +11 -7
- package/dist/vendors/analytics/databuddy.cjs +11 -7
- package/dist/vendors/analytics/fathom-analytics.cjs +11 -7
- package/dist/vendors/analytics/google-tag.cjs +11 -7
- package/dist/vendors/analytics/heap.cjs +181 -0
- package/dist/vendors/analytics/heap.js +134 -0
- package/dist/vendors/analytics/hightouch.cjs +153 -0
- package/dist/vendors/analytics/hightouch.js +109 -0
- package/dist/vendors/analytics/hotjar.cjs +11 -7
- package/dist/vendors/analytics/logrocket.cjs +99 -0
- package/dist/vendors/analytics/logrocket.js +58 -0
- package/dist/vendors/analytics/matomo-analytics.cjs +9 -5
- package/dist/vendors/analytics/microsoft-clarity.cjs +75 -47
- package/dist/vendors/analytics/microsoft-clarity.js +64 -40
- package/dist/vendors/analytics/mixpanel-analytics.cjs +31 -16
- package/dist/vendors/analytics/mixpanel-analytics.js +22 -11
- package/dist/vendors/analytics/pirsch.cjs +108 -0
- package/dist/vendors/analytics/pirsch.js +67 -0
- package/dist/vendors/analytics/plausible-analytics.cjs +9 -5
- package/dist/vendors/analytics/posthog.cjs +63 -27
- package/dist/vendors/analytics/posthog.js +52 -20
- package/dist/vendors/analytics/promptwatch.cjs +11 -7
- package/dist/vendors/analytics/rudderstack.cjs +227 -0
- package/dist/vendors/analytics/rudderstack.js +183 -0
- package/dist/vendors/analytics/rybbit-analytics.cjs +9 -5
- package/dist/vendors/analytics/segment.cjs +9 -5
- package/dist/vendors/analytics/umami-analytics.cjs +9 -5
- package/dist/vendors/analytics/vercel-analytics.cjs +11 -7
- package/dist/vendors/functional/crisp.cjs +9 -5
- package/dist/vendors/functional/intercom.cjs +11 -7
- package/dist/vendors/tag-managers/google-tag-manager.cjs +11 -7
- package/dist-types/registry.d.ts +313 -241
- package/dist-types/types.d.ts +46 -4
- package/dist-types/vendors/ads-and-pixels/linkedin-insights.d.ts +18 -18
- package/dist-types/vendors/ads-and-pixels/meta-pixel.d.ts +21 -21
- package/dist-types/vendors/ads-and-pixels/microsoft-uet.d.ts +32 -32
- package/dist-types/vendors/ads-and-pixels/reddit-pixel.d.ts +19 -19
- package/dist-types/vendors/ads-and-pixels/snapchat-pixel.d.ts +16 -16
- package/dist-types/vendors/ads-and-pixels/tiktok-pixel.d.ts +28 -28
- package/dist-types/vendors/ads-and-pixels/x-pixel.d.ts +13 -13
- package/dist-types/vendors/analytics/adobe-analytics.d.ts +75 -0
- package/dist-types/vendors/analytics/ahrefs-analytics.d.ts +7 -7
- package/dist-types/vendors/analytics/amplitude.d.ts +234 -0
- package/dist-types/vendors/analytics/clearbit.d.ts +60 -0
- package/dist-types/vendors/analytics/cloudflare-web-analytics.d.ts +7 -7
- package/dist-types/vendors/analytics/databuddy.d.ts +25 -25
- package/dist-types/vendors/analytics/fathom-analytics.d.ts +11 -11
- package/dist-types/vendors/analytics/google-tag.d.ts +17 -17
- package/dist-types/vendors/analytics/heap.d.ts +316 -0
- package/dist-types/vendors/analytics/hightouch.d.ts +285 -0
- package/dist-types/vendors/analytics/hotjar.d.ts +14 -14
- package/dist-types/vendors/analytics/logrocket.d.ts +101 -0
- package/dist-types/vendors/analytics/microsoft-clarity.d.ts +42 -30
- package/dist-types/vendors/analytics/mixpanel-analytics.d.ts +40 -28
- package/dist-types/vendors/analytics/pirsch.d.ts +96 -0
- package/dist-types/vendors/analytics/plausible-analytics.d.ts +13 -13
- package/dist-types/vendors/analytics/posthog.d.ts +63 -45
- package/dist-types/vendors/analytics/promptwatch.d.ts +7 -7
- package/dist-types/vendors/analytics/rudderstack.d.ts +330 -0
- package/dist-types/vendors/analytics/rybbit-analytics.d.ts +18 -18
- package/dist-types/vendors/analytics/segment.d.ts +13 -13
- package/dist-types/vendors/analytics/umami-analytics.d.ts +12 -12
- package/dist-types/vendors/analytics/vercel-analytics.d.ts +16 -16
- package/dist-types/vendors/functional/crisp.d.ts +11 -11
- package/dist-types/vendors/functional/intercom.d.ts +16 -16
- package/dist-types/vendors/tag-managers/google-tag-manager.d.ts +18 -18
- package/docs/README.md +62 -0
- package/docs/frameworks/javascript/script-loader.md +356 -0
- package/docs/frameworks/next/script-loader.md +501 -0
- package/docs/frameworks/react/script-loader.md +555 -0
- package/docs/integrations/adobe-analytics.md +160 -0
- package/docs/integrations/ahrefs-analytics.md +157 -0
- package/docs/integrations/amplitude.md +230 -0
- package/docs/integrations/building-integrations.md +239 -0
- package/docs/integrations/clearbit.md +130 -0
- package/docs/integrations/cloudflare-web-analytics.md +126 -0
- package/docs/integrations/crisp.md +140 -0
- package/docs/integrations/databuddy.md +205 -0
- package/docs/integrations/fathom-analytics.md +150 -0
- package/docs/integrations/google-maps.md +263 -0
- package/docs/integrations/google-tag-manager.md +154 -0
- package/docs/integrations/google-tag.md +134 -0
- package/docs/integrations/heap.md +219 -0
- package/docs/integrations/hightouch.md +199 -0
- package/docs/integrations/hotjar.md +143 -0
- package/docs/integrations/intercom.md +144 -0
- package/docs/integrations/linkedin-insights.md +161 -0
- package/docs/integrations/logrocket.md +175 -0
- package/docs/integrations/matomo-analytics.md +171 -0
- package/docs/integrations/meta-pixel.md +412 -0
- package/docs/integrations/microsoft-clarity.md +173 -0
- package/docs/integrations/microsoft-uet.md +156 -0
- package/docs/integrations/mixpanel-analytics.md +130 -0
- package/docs/integrations/overview.md +149 -0
- package/docs/integrations/pirsch.md +142 -0
- package/docs/integrations/plausible-analytics.md +154 -0
- package/docs/integrations/posthog.md +258 -0
- package/docs/integrations/promptwatch.md +121 -0
- package/docs/integrations/reddit-pixel.md +241 -0
- package/docs/integrations/rudderstack.md +271 -0
- package/docs/integrations/rybbit-analytics.md +143 -0
- package/docs/integrations/segment.md +146 -0
- package/docs/integrations/snapchat-pixel.md +163 -0
- package/docs/integrations/tiktok-pixel.md +123 -0
- package/docs/integrations/umami-analytics.md +148 -0
- package/docs/integrations/vercel-analytics.md +141 -0
- package/docs/integrations/x-pixel.md +157 -0
- package/docs/integrations/youtube.md +193 -0
- package/docs/shared/react/guides/script-loader.md +311 -0
- package/package.json +61 -7
- package/readme.json +8 -4
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Databuddy
|
|
3
|
+
description: Databuddy is a privacy-focused analytics platform that helps you
|
|
4
|
+
understand user behavior and track events. It supports cookieless tracking and
|
|
5
|
+
manages consent automatically through c15t's consent state synchronization.
|
|
6
|
+
icon: databuddy
|
|
7
|
+
group: integrations
|
|
8
|
+
---
|
|
9
|
+
The Databuddy script automatically respects consent preferences by toggling tracking on and off based on the user's consent state.
|
|
10
|
+
|
|
11
|
+
## Integrate with c15t
|
|
12
|
+
|
|
13
|
+
**React**
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { type ReactNode } from 'react';
|
|
17
|
+
import { ConsentManagerProvider } from '@c15t/react';
|
|
18
|
+
import { databuddy } from '@c15t/scripts/databuddy';
|
|
19
|
+
|
|
20
|
+
const scripts = [
|
|
21
|
+
databuddy({
|
|
22
|
+
clientId: 'your-client-id',
|
|
23
|
+
scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
|
|
24
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
25
|
+
configWhenGranted: {
|
|
26
|
+
clientId: 'your-client-id',
|
|
27
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
28
|
+
disabled: false,
|
|
29
|
+
},
|
|
30
|
+
configWhenDenied: {
|
|
31
|
+
clientId: 'your-client-id',
|
|
32
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
33
|
+
disabled: true,
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
39
|
+
return (
|
|
40
|
+
<ConsentManagerProvider
|
|
41
|
+
options={{
|
|
42
|
+
mode: 'hosted',
|
|
43
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
44
|
+
scripts,
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
{children}
|
|
48
|
+
</ConsentManagerProvider>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Next.js**
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
'use client';
|
|
57
|
+
|
|
58
|
+
import { type ReactNode } from 'react';
|
|
59
|
+
import { ConsentManagerProvider } from '@c15t/nextjs';
|
|
60
|
+
import { databuddy } from '@c15t/scripts/databuddy';
|
|
61
|
+
|
|
62
|
+
const scripts = [
|
|
63
|
+
databuddy({
|
|
64
|
+
clientId: 'your-client-id',
|
|
65
|
+
scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
|
|
66
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
67
|
+
configWhenGranted: {
|
|
68
|
+
clientId: 'your-client-id',
|
|
69
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
70
|
+
disabled: false,
|
|
71
|
+
},
|
|
72
|
+
configWhenDenied: {
|
|
73
|
+
clientId: 'your-client-id',
|
|
74
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
75
|
+
disabled: true,
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
81
|
+
return (
|
|
82
|
+
<ConsentManagerProvider
|
|
83
|
+
options={{
|
|
84
|
+
mode: 'hosted',
|
|
85
|
+
backendURL: '/api/c15t',
|
|
86
|
+
scripts,
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{children}
|
|
90
|
+
</ConsentManagerProvider>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**JavaScript**
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
99
|
+
import { databuddy } from '@c15t/scripts/databuddy';
|
|
100
|
+
|
|
101
|
+
getOrCreateConsentRuntime({
|
|
102
|
+
mode: 'hosted',
|
|
103
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
104
|
+
scripts: [
|
|
105
|
+
databuddy({
|
|
106
|
+
clientId: 'your-client-id',
|
|
107
|
+
scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
|
|
108
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
109
|
+
configWhenGranted: {
|
|
110
|
+
clientId: 'your-client-id',
|
|
111
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
112
|
+
disabled: false,
|
|
113
|
+
},
|
|
114
|
+
configWhenDenied: {
|
|
115
|
+
clientId: 'your-client-id',
|
|
116
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
117
|
+
disabled: true,
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## How c15t loads it
|
|
125
|
+
|
|
126
|
+
* **Category:** `measurement` (Analytics)
|
|
127
|
+
* **Loads when:** [`alwaysLoad`](/docs/frameworks/react/script-loader#always-load) — runs on page start regardless of consent state
|
|
128
|
+
* **On consent change:** c15t toggles `window.databuddy.options.disabled` so tracking turns on or off without removing the script
|
|
129
|
+
|
|
130
|
+
## Configure the integration
|
|
131
|
+
|
|
132
|
+
The Databuddy manifest expects explicit initial config objects for the granted
|
|
133
|
+
and denied consent states:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
databuddy({
|
|
137
|
+
clientId: 'your-client-id',
|
|
138
|
+
scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
|
|
139
|
+
apiUrl: 'https://basket.databuddy.cc', // Optional, defaults to basket.databuddy.cc, change if self-hosting
|
|
140
|
+
configWhenGranted: {
|
|
141
|
+
clientId: 'your-client-id',
|
|
142
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
143
|
+
// Tracking options
|
|
144
|
+
trackScreenViews: true, // Automatically track page views
|
|
145
|
+
trackOutgoingLinks: true, // Track clicks on external links
|
|
146
|
+
trackAttributes: false, // Track data-track attributes on elements
|
|
147
|
+
trackErrors: false, // Track JavaScript errors
|
|
148
|
+
trackPerformance: true, // Track performance metrics
|
|
149
|
+
trackWebVitals: false, // Track Core Web Vitals
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
// Network options
|
|
153
|
+
enableBatching: false, // Batch events before sending
|
|
154
|
+
batchSize: 10, // Events per batch
|
|
155
|
+
batchTimeout: 2000, // Batch timeout in ms
|
|
156
|
+
samplingRate: 1.0, // Sample rate (0.0-1.0)
|
|
157
|
+
disabled: false,
|
|
158
|
+
},
|
|
159
|
+
configWhenDenied: {
|
|
160
|
+
clientId: 'your-client-id',
|
|
161
|
+
apiUrl: 'https://basket.databuddy.cc',
|
|
162
|
+
disabled: true,
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Tracking events in your app
|
|
168
|
+
|
|
169
|
+
Databuddy is `alwaysLoad: true`, so the script is in the DOM from page start regardless of consent. `window.databuddy` is therefore always defined and calls to `track`, `screenView`, or `setGlobalProperties` are safe to make at any time — when measurement consent is denied, c15t flips `window.databuddy.options.disabled = true` so the SDK becomes a no-op until consent is granted again.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
window.databuddy?.track('signup');
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
You do not need to guard these calls with `useConsentManager().has('measurement')`, but doing so does no harm if you prefer the symmetry with other vendors.
|
|
176
|
+
|
|
177
|
+
## Consent and privacy
|
|
178
|
+
|
|
179
|
+
The Databuddy integration automatically handles consent management:
|
|
180
|
+
|
|
181
|
+
1. **Before Script Load**: Sets `window.databuddyConfig.disabled` based on initial consent state
|
|
182
|
+
2. **On Consent Grant**: Enables tracking by setting `window.databuddy.options.disabled = false`
|
|
183
|
+
3. **On Consent Revoke**: Disables tracking by setting `window.databuddy.options.disabled = true`
|
|
184
|
+
|
|
185
|
+
This ensures that no tracking occurs without user consent, keeping your analytics privacy-compliant.
|
|
186
|
+
|
|
187
|
+
## Types
|
|
188
|
+
|
|
189
|
+
### DatabuddyConsentOptions
|
|
190
|
+
|
|
191
|
+
|Property|Value|
|
|
192
|
+
|:--|:--|
|
|
193
|
+
|Type Name|\`DatabuddyConsentOptions\`|
|
|
194
|
+
|Source Path|\`./packages/scripts/src/vendors/analytics/databuddy.ts\`|
|
|
195
|
+
|
|
196
|
+
\*ExtractedTypeTable: Could not extract "DatabuddyConsentOptions" from "./packages/scripts/src/vendors/analytics/databuddy.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
|
|
197
|
+
|
|
198
|
+
### Script
|
|
199
|
+
|
|
200
|
+
|Property|Value|
|
|
201
|
+
|:--|:--|
|
|
202
|
+
|Type Name|\`Script\`|
|
|
203
|
+
|Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
|
|
204
|
+
|
|
205
|
+
\*ExtractedTypeTable: Could not extract "Script" from "./packages/core/src/libs/script-loader/types.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Fathom Analytics
|
|
3
|
+
description: Privacy-friendly cookieless analytics with a prebuilt helper that
|
|
4
|
+
maps Fathom's data attributes into a c15t-managed script.
|
|
5
|
+
group: integrations
|
|
6
|
+
icon: fathom-analytics
|
|
7
|
+
---
|
|
8
|
+
Fathom Analytics is a lightweight, cookieless analytics product configured entirely through `data-*` attributes on its loader. The `fathomAnalytics()` helper serializes your site ID and tracking options into those attributes and hands the result to c15t's script loader.
|
|
9
|
+
|
|
10
|
+
## Integrate with c15t
|
|
11
|
+
|
|
12
|
+
**React**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { type ReactNode } from 'react';
|
|
16
|
+
import { ConsentManagerProvider } from '@c15t/react';
|
|
17
|
+
import { fathomAnalytics } from '@c15t/scripts/fathom-analytics';
|
|
18
|
+
|
|
19
|
+
const scripts = [fathomAnalytics({ site: 'SITE123' })];
|
|
20
|
+
|
|
21
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
22
|
+
return (
|
|
23
|
+
<ConsentManagerProvider
|
|
24
|
+
options={{
|
|
25
|
+
mode: 'hosted',
|
|
26
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
27
|
+
scripts,
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
{children}
|
|
31
|
+
</ConsentManagerProvider>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Next.js**
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
'use client';
|
|
40
|
+
|
|
41
|
+
import { type ReactNode } from 'react';
|
|
42
|
+
import { ConsentManagerProvider } from '@c15t/nextjs';
|
|
43
|
+
import { fathomAnalytics } from '@c15t/scripts/fathom-analytics';
|
|
44
|
+
|
|
45
|
+
const scripts = [fathomAnalytics({ site: 'SITE123' })];
|
|
46
|
+
|
|
47
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
48
|
+
return (
|
|
49
|
+
<ConsentManagerProvider
|
|
50
|
+
options={{
|
|
51
|
+
mode: 'hosted',
|
|
52
|
+
backendURL: '/api/c15t',
|
|
53
|
+
scripts,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{children}
|
|
57
|
+
</ConsentManagerProvider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**JavaScript**
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
66
|
+
import { fathomAnalytics } from '@c15t/scripts/fathom-analytics';
|
|
67
|
+
|
|
68
|
+
getOrCreateConsentRuntime({
|
|
69
|
+
mode: 'hosted',
|
|
70
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
71
|
+
scripts: [fathomAnalytics({ site: 'SITE123' })],
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## How c15t loads it
|
|
76
|
+
|
|
77
|
+
* **Category:** `measurement` (Analytics)
|
|
78
|
+
* **Loads when:** measurement consent is granted
|
|
79
|
+
* **On revocation:** unloaded — c15t removes the script element from the DOM. Fathom is cookieless, so no client-side state needs clearing.
|
|
80
|
+
|
|
81
|
+
If you need to tune SPA tracking, canonical URL tracking, or Do Not Track handling:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
fathomAnalytics({
|
|
85
|
+
site: 'SITE123',
|
|
86
|
+
spa: 'history',
|
|
87
|
+
canonical: true,
|
|
88
|
+
honorDnt: true,
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Each option is mapped to Fathom's published `data-*` attribute (`data-site`, `data-spa`, `data-auto`, `data-canonical`, `data-honor-dnt`) and the script uses `defer` so it matches Fathom's recommended embed pattern.
|
|
93
|
+
|
|
94
|
+
## Tracking events in your app
|
|
95
|
+
|
|
96
|
+
c15t gates the Fathom script from loading until `measurement` consent is granted. Your application code that calls Fathom's runtime API (`window.fathom.trackEvent`, `trackPageview`, `trackGoal`) is **not** automatically gated — `window.fathom` does not exist until the script is loaded, so unguarded calls before consent will throw errors.
|
|
97
|
+
|
|
98
|
+
Guard event calls by checking consent state. From React:
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
import { useConsentManager } from '@c15t/react';
|
|
102
|
+
|
|
103
|
+
function useTrackSignup() {
|
|
104
|
+
const { has } = useConsentManager();
|
|
105
|
+
|
|
106
|
+
return () => {
|
|
107
|
+
if (has('measurement')) {
|
|
108
|
+
window.fathom?.trackEvent('signup');
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function SignupButton() {
|
|
114
|
+
const trackSignup = useTrackSignup();
|
|
115
|
+
|
|
116
|
+
return <button onClick={trackSignup}>Sign up</button>;
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
From plain JavaScript:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
124
|
+
|
|
125
|
+
const { consentStore } = getOrCreateConsentRuntime();
|
|
126
|
+
|
|
127
|
+
if (consentStore.getState().has('measurement')) {
|
|
128
|
+
window.fathom?.trackEvent('signup');
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Types
|
|
133
|
+
|
|
134
|
+
### FathomAnalyticsOptions
|
|
135
|
+
|
|
136
|
+
|Property|Value|
|
|
137
|
+
|:--|:--|
|
|
138
|
+
|Type Name|\`FathomAnalyticsOptions\`|
|
|
139
|
+
|Source Path|\`./packages/scripts/src/vendors/analytics/fathom-analytics.ts\`|
|
|
140
|
+
|
|
141
|
+
\*ExtractedTypeTable: Could not extract "FathomAnalyticsOptions" from "./packages/scripts/src/vendors/analytics/fathom-analytics.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
|
|
142
|
+
|
|
143
|
+
### Script
|
|
144
|
+
|
|
145
|
+
|Property|Value|
|
|
146
|
+
|:--|:--|
|
|
147
|
+
|Type Name|\`Script\`|
|
|
148
|
+
|Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
|
|
149
|
+
|
|
150
|
+
\*ExtractedTypeTable: Could not extract "Script" from "./packages/core/src/libs/script-loader/types.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Google Maps
|
|
3
|
+
description: Render Google Maps only after consent with one shared Maps
|
|
4
|
+
JavaScript API loader and independently managed map instances.
|
|
5
|
+
icon: google-maps
|
|
6
|
+
group: integrations
|
|
7
|
+
---
|
|
8
|
+
`GoogleMap` is a renderable integration for React and Next.js. It keeps the
|
|
9
|
+
Google Maps JavaScript API off the page until the configured consent category is
|
|
10
|
+
allowed, then loads the SDK once and creates a map for each mounted component.
|
|
11
|
+
|
|
12
|
+
Unlike the helpers from `@c15t/scripts`, `GoogleMap` owns both the consent-aware
|
|
13
|
+
script lifecycle and the visible map container.
|
|
14
|
+
|
|
15
|
+
> ℹ️ **Info:**
|
|
16
|
+
> The browser must receive a Google Maps API key, so the key is visible to site visitors. Keep it out of source control, use a key created for browser use, and restrict it by website and API in Google Cloud.
|
|
17
|
+
|
|
18
|
+
## Integrate with c15t
|
|
19
|
+
|
|
20
|
+
`GoogleMap` must render inside a `ConsentManagerProvider`. Complete the
|
|
21
|
+
[React quickstart](/docs/frameworks/react/quickstart) or
|
|
22
|
+
[Next.js quickstart](/docs/frameworks/next/quickstart) first.
|
|
23
|
+
|
|
24
|
+
**React**
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { GoogleMap } from '@c15t/react';
|
|
28
|
+
|
|
29
|
+
const apiKey = import.meta.env.VITE_GOOGLE_MAPS_API_KEY;
|
|
30
|
+
|
|
31
|
+
export function StoreMap() {
|
|
32
|
+
if (!apiKey) {
|
|
33
|
+
return <p>Google Maps is not configured.</p>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<GoogleMap
|
|
38
|
+
apiKey={apiKey}
|
|
39
|
+
authReferrerPolicy="origin"
|
|
40
|
+
center={{ lat: 40.7128, lng: -74.006 }}
|
|
41
|
+
consentCategory="measurement"
|
|
42
|
+
style={{ height: 400 }}
|
|
43
|
+
zoom={12}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Next.js**
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
'use client';
|
|
53
|
+
|
|
54
|
+
import { GoogleMap } from '@c15t/nextjs';
|
|
55
|
+
|
|
56
|
+
const apiKey = process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY;
|
|
57
|
+
|
|
58
|
+
export function StoreMap() {
|
|
59
|
+
if (!apiKey) {
|
|
60
|
+
return <p>Google Maps is not configured.</p>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<GoogleMap
|
|
65
|
+
apiKey={apiKey}
|
|
66
|
+
authReferrerPolicy="origin"
|
|
67
|
+
center={{ lat: 40.7128, lng: -74.006 }}
|
|
68
|
+
consentCategory="measurement"
|
|
69
|
+
style={{ height: 400 }}
|
|
70
|
+
zoom={12}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`measurement` is a common choice for an interactive map, but the correct
|
|
77
|
+
category depends on why your application uses Google Maps and the policy shown
|
|
78
|
+
to your users.
|
|
79
|
+
|
|
80
|
+
## How c15t loads it
|
|
81
|
+
|
|
82
|
+
* **Before consent:** no Maps JavaScript API script is requested and no map
|
|
83
|
+
instance is created.
|
|
84
|
+
* **After consent:** c15t registers one shared SDK loader and waits for Google's
|
|
85
|
+
callback before constructing the map.
|
|
86
|
+
* **Multiple maps:** components with the same `scriptId` reuse the SDK while
|
|
87
|
+
keeping separate map instances.
|
|
88
|
+
* **On revocation or unmount:** the component clears the map instance and its
|
|
89
|
+
listeners. The page-level SDK registration is retained after its first load
|
|
90
|
+
because Google supports one loader per page.
|
|
91
|
+
* **Existing SDK:** if another part of the application already loaded a
|
|
92
|
+
compatible Google Maps global, the component adopts it instead of adding a
|
|
93
|
+
duplicate script.
|
|
94
|
+
* **Visible states:** the blocked, loading, and error states are accessible and
|
|
95
|
+
use the active c15t translations by default.
|
|
96
|
+
|
|
97
|
+
Keep one `scriptId` and one loader configuration across the page. Override the
|
|
98
|
+
default `scriptId` only to coordinate with a known c15t script registration, not
|
|
99
|
+
to load a second Maps SDK configuration. If two maps register conflicting
|
|
100
|
+
loader options, c15t reports the conflict and tells you to align the key,
|
|
101
|
+
language, region, libraries, and other loader options. A different `scriptId`
|
|
102
|
+
does not make a second Google loader safe.
|
|
103
|
+
|
|
104
|
+
## Configure the map
|
|
105
|
+
|
|
106
|
+
Pass `center`, `zoom`, `mapId`, and `options` as you would when constructing a
|
|
107
|
+
Google map:
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
<GoogleMap
|
|
111
|
+
apiKey={apiKey}
|
|
112
|
+
center={{ lat: 51.5072, lng: -0.1276 }}
|
|
113
|
+
consentCategory="measurement"
|
|
114
|
+
mapId="YOUR_MAP_ID"
|
|
115
|
+
options={{
|
|
116
|
+
disableDefaultUI: true,
|
|
117
|
+
gestureHandling: 'cooperative',
|
|
118
|
+
}}
|
|
119
|
+
zoom={11}
|
|
120
|
+
/>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Changes to `center`, `zoom`, and updateable `options` are applied to the existing
|
|
124
|
+
map. Changing `mapId` recreates it because Google treats that value as
|
|
125
|
+
construction-time configuration.
|
|
126
|
+
|
|
127
|
+
The component has a default height of `320px`. Override `style.height` or apply
|
|
128
|
+
a class with an explicit height when your layout needs another size.
|
|
129
|
+
|
|
130
|
+
### Loader options
|
|
131
|
+
|
|
132
|
+
The direct Maps JavaScript API loader options are available as component props:
|
|
133
|
+
|
|
134
|
+
* `libraries`
|
|
135
|
+
* `language`
|
|
136
|
+
* `region`
|
|
137
|
+
* `version`
|
|
138
|
+
* `authReferrerPolicy`
|
|
139
|
+
* `mapIds`
|
|
140
|
+
* `channel`
|
|
141
|
+
* `solutionChannel`
|
|
142
|
+
* `nonce`
|
|
143
|
+
|
|
144
|
+
`mapIds` preloads map ID configuration; `mapId` selects the map ID for the
|
|
145
|
+
component instance.
|
|
146
|
+
|
|
147
|
+
## Handle loading and errors
|
|
148
|
+
|
|
149
|
+
The built-in loading and error states use `frame.loading` and `frame.error` from
|
|
150
|
+
your c15t messages. The consent placeholder uses the localized consent-type
|
|
151
|
+
title in both its message and button—for example, an `Analytics` title produces
|
|
152
|
+
“Enable Analytics consent.”
|
|
153
|
+
|
|
154
|
+
Use the fallback props when you need integration-specific content and `onError`
|
|
155
|
+
for reporting:
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
import { Frame, GoogleMap } from '@c15t/react';
|
|
159
|
+
|
|
160
|
+
function reportMapError(error: Error) {
|
|
161
|
+
// Send the error to your observability provider.
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
<GoogleMap
|
|
165
|
+
apiKey={apiKey}
|
|
166
|
+
center={{ lat: 40.7128, lng: -74.006 }}
|
|
167
|
+
consentCategory="measurement"
|
|
168
|
+
loadingFallback={<p>Loading map…</p>}
|
|
169
|
+
errorFallback={<p>The map could not be loaded.</p>}
|
|
170
|
+
onError={reportMapError}
|
|
171
|
+
placeholder={
|
|
172
|
+
<Frame.Root>
|
|
173
|
+
<Frame.Title>Allow measurement consent to view this map.</Frame.Title>
|
|
174
|
+
<Frame.Button category="measurement" />
|
|
175
|
+
</Frame.Root>
|
|
176
|
+
}
|
|
177
|
+
/>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`onError` covers loader failures, timeouts, map-constructor failures, and
|
|
181
|
+
Google's global authentication failure callback. Authentication failures
|
|
182
|
+
usually indicate an invalid key, missing billing, a disabled API, or a referrer
|
|
183
|
+
that is not allowed.
|
|
184
|
+
|
|
185
|
+
If you provide a custom `placeholder`, include `Frame.Button` or another way to
|
|
186
|
+
reopen consent preferences or grant the required category.
|
|
187
|
+
|
|
188
|
+
### Retry a failed map
|
|
189
|
+
|
|
190
|
+
Increment `retryKey` to retry the same map after a loader, authentication, or
|
|
191
|
+
constructor failure:
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
import { GoogleMap } from '@c15t/react';
|
|
195
|
+
import { useState } from 'react';
|
|
196
|
+
|
|
197
|
+
function RetryableMap({ apiKey }: { apiKey: string }) {
|
|
198
|
+
const [retryKey, setRetryKey] = useState(0);
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<>
|
|
202
|
+
<GoogleMap
|
|
203
|
+
apiKey={apiKey}
|
|
204
|
+
center={{ lat: 40.7128, lng: -74.006 }}
|
|
205
|
+
retryKey={retryKey}
|
|
206
|
+
/>
|
|
207
|
+
|
|
208
|
+
<button type="button" onClick={() => setRetryKey((key) => key + 1)}>
|
|
209
|
+
Retry map
|
|
210
|
+
</button>
|
|
211
|
+
</>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Changing `retryKey` clears the failed attempt and retries with the same
|
|
217
|
+
`scriptId`. A successful page-level SDK registration remains shared and is not
|
|
218
|
+
loaded again.
|
|
219
|
+
|
|
220
|
+
## Secure the browser key
|
|
221
|
+
|
|
222
|
+
For production:
|
|
223
|
+
|
|
224
|
+
1. Create a key specifically for the browser application.
|
|
225
|
+
2. Apply a **Websites** application restriction for every allowed development
|
|
226
|
+
and production origin.
|
|
227
|
+
3. Restrict the key to the **Maps JavaScript API** and any additional APIs used
|
|
228
|
+
by requested libraries.
|
|
229
|
+
4. Keep the value in an untracked environment file and expose it through the
|
|
230
|
+
browser environment variable required by your framework.
|
|
231
|
+
5. Monitor key usage and rotate the key if you see unexpected traffic.
|
|
232
|
+
|
|
233
|
+
When `authReferrerPolicy="origin"` is set, configure origin-level website
|
|
234
|
+
restrictions without URL paths.
|
|
235
|
+
|
|
236
|
+
* [Google Maps Platform security guidance](https://developers.google.com/maps/api-security-best-practices)
|
|
237
|
+
* [Maps JavaScript API loader options](https://developers.google.com/maps/documentation/javascript/load-maps-js-api)
|
|
238
|
+
* [Maps Demo Key for local prototypes](https://developers.google.com/maps/documentation/javascript/demo-key)
|
|
239
|
+
|
|
240
|
+
## Verify setup
|
|
241
|
+
|
|
242
|
+
1. Clear saved consent and reload the page.
|
|
243
|
+
2. Confirm no request to `maps.googleapis.com/maps/api/js` occurs before the
|
|
244
|
+
configured category is allowed.
|
|
245
|
+
3. Grant consent and confirm the map reaches its ready state.
|
|
246
|
+
4. Render two maps with the same `scriptId` and confirm only one loader script is
|
|
247
|
+
added.
|
|
248
|
+
5. Revoke consent and confirm each map instance is removed.
|
|
249
|
+
6. Test a rejected key or referrer and confirm `errorFallback` and `onError`
|
|
250
|
+
receive the failure.
|
|
251
|
+
7. Fix the rejected configuration, change `retryKey`, and confirm the map can
|
|
252
|
+
recover without changing `scriptId`.
|
|
253
|
+
|
|
254
|
+
## Types
|
|
255
|
+
|
|
256
|
+
### GoogleMapProps
|
|
257
|
+
|
|
258
|
+
|Property|Value|
|
|
259
|
+
|:--|:--|
|
|
260
|
+
|Type Name|\`GoogleMapProps\`|
|
|
261
|
+
|Source Path|\`./packages/react/src/components/integrations/google-map.tsx\`|
|
|
262
|
+
|
|
263
|
+
\*ExtractedTypeTable: Could not extract "GoogleMapProps" from "./packages/react/src/components/integrations/google-map.tsx" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
|