c15t 2.0.4 → 2.1.0
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/CHANGELOG.md +36 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist-types/index.d.ts +1 -1
- package/dist-types/version.d.ts +1 -1
- package/docs/integrations/ahrefs-analytics.md +224 -0
- package/docs/integrations/cloudflare-web-analytics.md +194 -0
- package/docs/integrations/crisp.md +214 -0
- package/docs/integrations/databuddy.md +136 -65
- package/docs/integrations/fathom-analytics.md +221 -0
- package/docs/integrations/google-tag-manager.md +84 -15
- package/docs/integrations/google-tag.md +89 -8
- package/docs/integrations/hotjar.md +211 -0
- package/docs/integrations/intercom.md +214 -0
- package/docs/integrations/linkedin-insights.md +130 -11
- package/docs/integrations/matomo-analytics.md +246 -0
- package/docs/integrations/meta-pixel.md +377 -24
- package/docs/integrations/microsoft-clarity.md +241 -0
- package/docs/integrations/microsoft-uet.md +120 -9
- package/docs/integrations/mixpanel-analytics.md +198 -0
- package/docs/integrations/overview.md +69 -74
- package/docs/integrations/plausible-analytics.md +237 -0
- package/docs/integrations/posthog.md +172 -41
- package/docs/integrations/promptwatch.md +187 -0
- package/docs/integrations/reddit-pixel.md +336 -0
- package/docs/integrations/rybbit-analytics.md +222 -0
- package/docs/integrations/segment.md +213 -0
- package/docs/integrations/snapchat-pixel.md +244 -0
- package/docs/integrations/tiktok-pixel.md +88 -10
- package/docs/integrations/umami-analytics.md +220 -0
- package/docs/integrations/vercel-analytics.md +213 -0
- package/docs/integrations/x-pixel.md +99 -10
- package/docs/script-loader.md +168 -51
- package/package.json +3 -3
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Segment
|
|
3
|
+
description: Load Segment Analytics.js with c15t and gate it behind measurement consent.
|
|
4
|
+
lastModified: 2026-05-10
|
|
5
|
+
icon: segment
|
|
6
|
+
---
|
|
7
|
+
Segment lets you collect analytics events in one place and forward them to downstream destinations. The `segment()` helper creates Segment's standard `window.analytics` queue, optionally queues the initial `page()` call, and loads Analytics.js when `measurement` consent is available.
|
|
8
|
+
|
|
9
|
+
## Integrate with c15t
|
|
10
|
+
|
|
11
|
+
**React**
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { type ReactNode } from 'react';
|
|
15
|
+
import { ConsentManagerProvider } from '@c15t/react';
|
|
16
|
+
import { segment } from '@c15t/scripts/segment';
|
|
17
|
+
|
|
18
|
+
const scripts = [segment({ writeKey: 'abc123xyz456' })];
|
|
19
|
+
|
|
20
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
21
|
+
return (
|
|
22
|
+
<ConsentManagerProvider
|
|
23
|
+
options={{
|
|
24
|
+
mode: 'hosted',
|
|
25
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
26
|
+
scripts,
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</ConsentManagerProvider>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Next.js**
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
'use client';
|
|
39
|
+
|
|
40
|
+
import { type ReactNode } from 'react';
|
|
41
|
+
import { ConsentManagerProvider } from '@c15t/nextjs';
|
|
42
|
+
import { segment } from '@c15t/scripts/segment';
|
|
43
|
+
|
|
44
|
+
const scripts = [segment({ writeKey: 'abc123xyz456' })];
|
|
45
|
+
|
|
46
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
47
|
+
return (
|
|
48
|
+
<ConsentManagerProvider
|
|
49
|
+
options={{
|
|
50
|
+
mode: 'hosted',
|
|
51
|
+
backendURL: '/api/c15t',
|
|
52
|
+
scripts,
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{children}
|
|
56
|
+
</ConsentManagerProvider>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**JavaScript**
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
65
|
+
import { segment } from '@c15t/scripts/segment';
|
|
66
|
+
|
|
67
|
+
getOrCreateConsentRuntime({
|
|
68
|
+
mode: 'hosted',
|
|
69
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
70
|
+
scripts: [segment({ writeKey: 'abc123xyz456' })],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## How c15t loads it
|
|
75
|
+
|
|
76
|
+
* **Category:** `measurement` (Analytics)
|
|
77
|
+
* **Loads when:** measurement consent is granted
|
|
78
|
+
* **On revocation:** unloaded - c15t removes the script from the DOM and clears Segment globals until consent is granted again.
|
|
79
|
+
|
|
80
|
+
## Configure the integration
|
|
81
|
+
|
|
82
|
+
By default the helper queues `analytics.page()` before the vendor bundle loads. If you want to handle page views yourself, set `trackPageView` to `false`.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { segment } from '@c15t/scripts/segment';
|
|
86
|
+
|
|
87
|
+
segment({
|
|
88
|
+
writeKey: 'abc123xyz456',
|
|
89
|
+
trackPageView: false,
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Tracking events in your app
|
|
94
|
+
|
|
95
|
+
c15t gates the Segment script from loading until `measurement` consent is granted. Your application code that calls Segment's runtime API (`window.analytics.track`, `identify`, etc.) is **not** automatically gated - `window.analytics` does not exist until the script is loaded, so unguarded calls before consent throw.
|
|
96
|
+
|
|
97
|
+
Guard event calls by checking consent state. From React:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { useCallback } from 'react';
|
|
101
|
+
import { useConsentManager } from '@c15t/react';
|
|
102
|
+
|
|
103
|
+
function SignupExample() {
|
|
104
|
+
const { has } = useConsentManager();
|
|
105
|
+
|
|
106
|
+
const trackSignup = useCallback(() => {
|
|
107
|
+
if (has('measurement')) {
|
|
108
|
+
window.analytics?.track('Signup Completed', { plan: 'pro' });
|
|
109
|
+
}
|
|
110
|
+
}, [has]);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
From plain JavaScript:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
118
|
+
|
|
119
|
+
const { consentStore } = getOrCreateConsentRuntime();
|
|
120
|
+
|
|
121
|
+
if (consentStore.getState().has('measurement')) {
|
|
122
|
+
window.analytics?.track('Signup Completed', { plan: 'pro' });
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Types
|
|
127
|
+
|
|
128
|
+
### SegmentOptions
|
|
129
|
+
|
|
130
|
+
|Property|Type|Description|Default|Required|
|
|
131
|
+
|:--|:--|:--|:--|:--:|
|
|
132
|
+
|writeKey|string|Your Segment write key.|-|✅ Required|
|
|
133
|
+
|trackPageView|boolean \|undefined|Queue the initial \`analytics.page()\` call during setup.|-|Optional|
|
|
134
|
+
|scriptUrl|string \|undefined|Optional full loader URL override.|-|Optional|
|
|
135
|
+
|
|
136
|
+
### Script
|
|
137
|
+
|
|
138
|
+
|Property|Type|Description|Default|Required|
|
|
139
|
+
|:--|:--|:--|:--|:--:|
|
|
140
|
+
|id|string|Unique identifier for the script|-|✅ Required|
|
|
141
|
+
|src|string \|undefined|URL of the script to load|-|Optional|
|
|
142
|
+
|textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
|
|
143
|
+
|category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
|
|
144
|
+
|callbackOnly|boolean \|undefined|Whether this is a callback-only script that doesn't need to load an external resource. When true, no script tag will be added to the DOM, only callbacks will be executed.|false|Optional|
|
|
145
|
+
|persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
|
|
146
|
+
|alwaysLoad|boolean \|undefined|Whether the script should always load regardless of consent state. This is useful for scripts like Google Tag Manager or PostHog that manage their own consent state internally. The script will load immediately and never be unloaded based on consent changes. Note: When using this option, you are responsible for ensuring the script itself respects user consent preferences through its own consent management.|false|Optional|
|
|
147
|
+
|fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
|
|
148
|
+
|attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
|
|
149
|
+
|async|boolean \|undefined|Whether to use async loading|-|Optional|
|
|
150
|
+
|defer|boolean \|undefined|Whether to defer script loading|-|Optional|
|
|
151
|
+
|nonce|string \|undefined|Content Security Policy nonce|-|Optional|
|
|
152
|
+
|anonymizeId|boolean \|undefined|Whether to use an anonymized ID for the script element, this helps ensure the script is not blocked by ad blockers|true|Optional|
|
|
153
|
+
|target|"head" \|"body" \|undefined|Where to inject the script element in the DOM. Options: \`'head'\`: Scripts are appended to \`\<head>\` (default); \`'body'\`: Scripts are appended to \`\<body>\`|'head'|Optional|
|
|
154
|
+
|onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
|
|
155
|
+
|onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
|
|
156
|
+
|onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
|
|
157
|
+
|onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
|
|
158
|
+
|vendorId|string \|number \|undefined|IAB TCF vendor ID - links script to a registered vendor. When in IAB mode, the script will only load if this vendor has consent. Takes precedence over \`category\` when in IAB mode. Use custom vendor IDs (string or number) to gate non-IAB vendors too.|-|Optional|
|
|
159
|
+
|iabPurposes|number\[] \|undefined|IAB TCF purpose IDs this script requires consent for. When in IAB mode and no vendorId is set, the script will only load if ALL specified purposes have consent.|-|Optional|
|
|
160
|
+
|iabLegIntPurposes|number\[] \|undefined|IAB TCF legitimate interest purpose IDs. These purposes can operate under legitimate interest instead of consent. The script loads if all iabPurposes have consent OR all iabLegIntPurposes have legitimate interest established.|-|Optional|
|
|
161
|
+
|iabSpecialFeatures|number\[] \|undefined|IAB TCF special feature IDs this script requires. Options: 1: Use precise geolocation data; 2: Actively scan device characteristics for identification|-|Optional|
|
|
162
|
+
|
|
163
|
+
#### `onBeforeLoad`
|
|
164
|
+
|
|
165
|
+
Callback executed before the script is loaded
|
|
166
|
+
|
|
167
|
+
|Property|Type|Description|Default|Required|
|
|
168
|
+
|:--|:--|:--|:--|:--:|
|
|
169
|
+
|id|string|The original script ID|-|✅ Required|
|
|
170
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
171
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
172
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
173
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
174
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
175
|
+
|
|
176
|
+
#### `onLoad`
|
|
177
|
+
|
|
178
|
+
Callback executed when the script loads successfully
|
|
179
|
+
|
|
180
|
+
|Property|Type|Description|Default|Required|
|
|
181
|
+
|:--|:--|:--|:--|:--:|
|
|
182
|
+
|id|string|The original script ID|-|✅ Required|
|
|
183
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
184
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
185
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
186
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
187
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
188
|
+
|
|
189
|
+
#### `onError`
|
|
190
|
+
|
|
191
|
+
Callback executed if the script fails to load
|
|
192
|
+
|
|
193
|
+
|Property|Type|Description|Default|Required|
|
|
194
|
+
|:--|:--|:--|:--|:--:|
|
|
195
|
+
|id|string|The original script ID|-|✅ Required|
|
|
196
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
197
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
198
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
199
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
200
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
201
|
+
|
|
202
|
+
#### `onConsentChange`
|
|
203
|
+
|
|
204
|
+
Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.
|
|
205
|
+
|
|
206
|
+
|Property|Type|Description|Default|Required|
|
|
207
|
+
|:--|:--|:--|:--|:--:|
|
|
208
|
+
|id|string|The original script ID|-|✅ Required|
|
|
209
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
210
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
211
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
212
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
213
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Snapchat Pixel
|
|
3
|
+
description: Measure Snapchat ad performance and build remarketing audiences with a prebuilt pixel helper.
|
|
4
|
+
lastModified: 2026-05-10
|
|
5
|
+
icon: snapchat
|
|
6
|
+
---
|
|
7
|
+
Snapchat Pixel is Snapchat's website conversion tracking and audience-building tool. The `snapchatPixel()` helper seeds the `snaptr` queue, initializes your pixel, and by default tracks a `PAGE_VIEW` event as soon as `marketing` consent is available.
|
|
8
|
+
|
|
9
|
+
## Integrate with c15t
|
|
10
|
+
|
|
11
|
+
**React**
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { type ReactNode } from 'react';
|
|
15
|
+
import { ConsentManagerProvider } from '@c15t/react';
|
|
16
|
+
import { snapchatPixel } from '@c15t/scripts/snapchat-pixel';
|
|
17
|
+
|
|
18
|
+
const scripts = [snapchatPixel({ pixelId: '123456789012345' })];
|
|
19
|
+
|
|
20
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
21
|
+
return (
|
|
22
|
+
<ConsentManagerProvider
|
|
23
|
+
options={{
|
|
24
|
+
mode: 'hosted',
|
|
25
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
26
|
+
scripts,
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</ConsentManagerProvider>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Next.js**
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
'use client';
|
|
39
|
+
|
|
40
|
+
import { type ReactNode } from 'react';
|
|
41
|
+
import { ConsentManagerProvider } from '@c15t/nextjs';
|
|
42
|
+
import { snapchatPixel } from '@c15t/scripts/snapchat-pixel';
|
|
43
|
+
|
|
44
|
+
const scripts = [snapchatPixel({ pixelId: '123456789012345' })];
|
|
45
|
+
|
|
46
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
47
|
+
return (
|
|
48
|
+
<ConsentManagerProvider
|
|
49
|
+
options={{
|
|
50
|
+
mode: 'hosted',
|
|
51
|
+
backendURL: '/api/c15t',
|
|
52
|
+
scripts,
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{children}
|
|
56
|
+
</ConsentManagerProvider>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**JavaScript**
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
65
|
+
import { snapchatPixel } from '@c15t/scripts/snapchat-pixel';
|
|
66
|
+
|
|
67
|
+
getOrCreateConsentRuntime({
|
|
68
|
+
mode: 'hosted',
|
|
69
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
70
|
+
scripts: [snapchatPixel({ pixelId: '123456789012345' })],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## How c15t loads it
|
|
75
|
+
|
|
76
|
+
* **Category:** `marketing` (Ads & Pixels)
|
|
77
|
+
* **Loads when:** marketing consent is granted
|
|
78
|
+
* **On revocation:** unloaded - c15t removes the script from the DOM, so app code should guard `snaptr(...)` calls until consent is granted again.
|
|
79
|
+
|
|
80
|
+
You can pass extra init payload and disable the default page-view event when you need finer control:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
snapchatPixel({
|
|
84
|
+
pixelId: '123456789012345',
|
|
85
|
+
initOptions: {
|
|
86
|
+
user_email: 'hello@example.com',
|
|
87
|
+
},
|
|
88
|
+
trackPageView: false,
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Tracking events in your app
|
|
93
|
+
|
|
94
|
+
c15t gates the Snapchat Pixel script from loading until `marketing` consent is granted. Your application code that calls Snapchat's runtime API (`window.snaptr(...)`) is **not** automatically gated - `window.snaptr` does not exist until the script is loaded, so unguarded calls before consent throw.
|
|
95
|
+
|
|
96
|
+
Use `snapchatPixelEvent()` for typed standard and custom event tracking. Guard
|
|
97
|
+
event calls by checking consent state. From React:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { useCallback } from 'react';
|
|
101
|
+
import { useConsentManager } from '@c15t/react';
|
|
102
|
+
import { snapchatPixelEvent } from '@c15t/scripts/snapchat-pixel';
|
|
103
|
+
|
|
104
|
+
function CheckoutExample() {
|
|
105
|
+
const { has } = useConsentManager();
|
|
106
|
+
|
|
107
|
+
const trackPurchase = useCallback(() => {
|
|
108
|
+
if (has('marketing')) {
|
|
109
|
+
snapchatPixelEvent('PURCHASE', {
|
|
110
|
+
price: 99,
|
|
111
|
+
currency: 'USD',
|
|
112
|
+
transaction_id: 'order-123',
|
|
113
|
+
client_dedup_id: 'event-123',
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}, [has]);
|
|
117
|
+
|
|
118
|
+
// Call trackPurchase() from your conversion success path.
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
From plain JavaScript:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
126
|
+
import { snapchatPixelEvent } from '@c15t/scripts/snapchat-pixel';
|
|
127
|
+
|
|
128
|
+
const { consentStore } = getOrCreateConsentRuntime();
|
|
129
|
+
|
|
130
|
+
if (consentStore.getState().has('marketing')) {
|
|
131
|
+
snapchatPixelEvent('PURCHASE', { price: 99, currency: 'USD' });
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Types
|
|
136
|
+
|
|
137
|
+
### SnapchatPixelOptions
|
|
138
|
+
|
|
139
|
+
|Property|Type|Description|Default|Required|
|
|
140
|
+
|:--|:--|:--|:--|:--:|
|
|
141
|
+
|pixelId|string|Your Snapchat Pixel ID.|-|✅ Required|
|
|
142
|
+
|initOptions|Record\<string, unknown> \|undefined|Optional init payload passed to \`snaptr('init', ...)\`.|-|Optional|
|
|
143
|
+
|trackPageView|boolean \|undefined|Queue the default \`PAGE\_VIEW\` event during setup.|true|Optional|
|
|
144
|
+
|scriptUrl|string \|undefined|Snapchat Pixel loader URL.|-|Optional|
|
|
145
|
+
|
|
146
|
+
### SnapchatPixelEventProperties
|
|
147
|
+
|
|
148
|
+
|Property|Type|Description|Default|Required|
|
|
149
|
+
|:--|:--|:--|:--|:--:|
|
|
150
|
+
|price|number \|undefined|Total monetary value for commerce events such as \`PURCHASE\`.|-|Optional|
|
|
151
|
+
|client\_dedup\_id|string \|undefined|Event identifier used to deduplicate browser Pixel events against server-side Conversions API events.|-|Optional|
|
|
152
|
+
|currency|string \|undefined|ISO 4217 currency code, for example \`USD\`.|-|Optional|
|
|
153
|
+
|transaction\_id|string \|undefined|Transaction/order identifier for purchase events.|-|Optional|
|
|
154
|
+
|item\_ids|string\[] \|undefined|Product, SKU, or content identifiers associated with the event.|-|Optional|
|
|
155
|
+
|item\_category|string \|undefined|Product or content category associated with the event.|-|Optional|
|
|
156
|
+
|description|string \|undefined|Free-form description for the event.|-|Optional|
|
|
157
|
+
|search\_string|string \|undefined|Query text for \`SEARCH\` events.|-|Optional|
|
|
158
|
+
|number\_items|number \|undefined|Number of items represented by the event.|-|Optional|
|
|
159
|
+
|payment\_info\_available|0 \|1 \|undefined|Whether payment information was available, represented as \`0\` or \`1\`.|-|Optional|
|
|
160
|
+
|sign\_up\_method|string \|undefined|Signup method for \`SIGN\_UP\` events.|-|Optional|
|
|
161
|
+
|success|0 \|1 \|undefined|Whether the action succeeded, represented as \`0\` or \`1\`.|-|Optional|
|
|
162
|
+
|brands|string\[] \|undefined|Brand names associated with the event contents.|-|Optional|
|
|
163
|
+
|delivery\_method|"in\_store" \|"curbside" \|"delivery" \|undefined|Fulfillment method for commerce events.|-|Optional|
|
|
164
|
+
|customer\_status|"new" \|"returning" \|"reactivated" \|undefined|Customer lifecycle status associated with the event.|-|Optional|
|
|
165
|
+
|event\_tag|string \|undefined|Optional custom tag for event segmentation in Snapchat.|-|Optional|
|
|
166
|
+
|
|
167
|
+
### Script
|
|
168
|
+
|
|
169
|
+
|Property|Type|Description|Default|Required|
|
|
170
|
+
|:--|:--|:--|:--|:--:|
|
|
171
|
+
|id|string|Unique identifier for the script|-|✅ Required|
|
|
172
|
+
|src|string \|undefined|URL of the script to load|-|Optional|
|
|
173
|
+
|textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
|
|
174
|
+
|category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
|
|
175
|
+
|callbackOnly|boolean \|undefined|Whether this is a callback-only script that doesn't need to load an external resource. When true, no script tag will be added to the DOM, only callbacks will be executed.|false|Optional|
|
|
176
|
+
|persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
|
|
177
|
+
|alwaysLoad|boolean \|undefined|Whether the script should always load regardless of consent state. This is useful for scripts like Google Tag Manager or PostHog that manage their own consent state internally. The script will load immediately and never be unloaded based on consent changes. Note: When using this option, you are responsible for ensuring the script itself respects user consent preferences through its own consent management.|false|Optional|
|
|
178
|
+
|fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
|
|
179
|
+
|attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
|
|
180
|
+
|async|boolean \|undefined|Whether to use async loading|-|Optional|
|
|
181
|
+
|defer|boolean \|undefined|Whether to defer script loading|-|Optional|
|
|
182
|
+
|nonce|string \|undefined|Content Security Policy nonce|-|Optional|
|
|
183
|
+
|anonymizeId|boolean \|undefined|Whether to use an anonymized ID for the script element, this helps ensure the script is not blocked by ad blockers|true|Optional|
|
|
184
|
+
|target|"head" \|"body" \|undefined|Where to inject the script element in the DOM. Options: \`'head'\`: Scripts are appended to \`\<head>\` (default); \`'body'\`: Scripts are appended to \`\<body>\`|'head'|Optional|
|
|
185
|
+
|onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
|
|
186
|
+
|onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
|
|
187
|
+
|onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
|
|
188
|
+
|onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
|
|
189
|
+
|vendorId|string \|number \|undefined|IAB TCF vendor ID - links script to a registered vendor. When in IAB mode, the script will only load if this vendor has consent. Takes precedence over \`category\` when in IAB mode. Use custom vendor IDs (string or number) to gate non-IAB vendors too.|-|Optional|
|
|
190
|
+
|iabPurposes|number\[] \|undefined|IAB TCF purpose IDs this script requires consent for. When in IAB mode and no vendorId is set, the script will only load if ALL specified purposes have consent.|-|Optional|
|
|
191
|
+
|iabLegIntPurposes|number\[] \|undefined|IAB TCF legitimate interest purpose IDs. These purposes can operate under legitimate interest instead of consent. The script loads if all iabPurposes have consent OR all iabLegIntPurposes have legitimate interest established.|-|Optional|
|
|
192
|
+
|iabSpecialFeatures|number\[] \|undefined|IAB TCF special feature IDs this script requires. Options: 1: Use precise geolocation data; 2: Actively scan device characteristics for identification|-|Optional|
|
|
193
|
+
|
|
194
|
+
#### `onBeforeLoad`
|
|
195
|
+
|
|
196
|
+
Callback executed before the script is loaded
|
|
197
|
+
|
|
198
|
+
|Property|Type|Description|Default|Required|
|
|
199
|
+
|:--|:--|:--|:--|:--:|
|
|
200
|
+
|id|string|The original script ID|-|✅ Required|
|
|
201
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
202
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
203
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
204
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
205
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
206
|
+
|
|
207
|
+
#### `onLoad`
|
|
208
|
+
|
|
209
|
+
Callback executed when the script loads successfully
|
|
210
|
+
|
|
211
|
+
|Property|Type|Description|Default|Required|
|
|
212
|
+
|:--|:--|:--|:--|:--:|
|
|
213
|
+
|id|string|The original script ID|-|✅ Required|
|
|
214
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
215
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
216
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
217
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
218
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
219
|
+
|
|
220
|
+
#### `onError`
|
|
221
|
+
|
|
222
|
+
Callback executed if the script fails to load
|
|
223
|
+
|
|
224
|
+
|Property|Type|Description|Default|Required|
|
|
225
|
+
|:--|:--|:--|:--|:--:|
|
|
226
|
+
|id|string|The original script ID|-|✅ Required|
|
|
227
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
228
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
229
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
230
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
231
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
232
|
+
|
|
233
|
+
#### `onConsentChange`
|
|
234
|
+
|
|
235
|
+
Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.
|
|
236
|
+
|
|
237
|
+
|Property|Type|Description|Default|Required|
|
|
238
|
+
|:--|:--|:--|:--|:--:|
|
|
239
|
+
|id|string|The original script ID|-|✅ Required|
|
|
240
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
241
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
242
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
243
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
244
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
@@ -2,26 +2,104 @@
|
|
|
2
2
|
title: TikTok Pixel
|
|
3
3
|
description: Measure ad performance and build audiences for TikTok advertising campaigns.
|
|
4
4
|
lastModified: 2025-09-24
|
|
5
|
-
|
|
6
5
|
icon: tiktok
|
|
7
6
|
---
|
|
8
|
-
TikTok Pixel is TikTok's conversion tracking and audience targeting tool. It measures ad effectiveness, tracks user actions, and helps optimize your TikTok advertising campaigns.
|
|
7
|
+
TikTok Pixel is TikTok's conversion tracking and audience targeting tool. It measures ad effectiveness, tracks user actions, and helps optimize your TikTok advertising campaigns.
|
|
8
|
+
|
|
9
|
+
## Integrate with c15t
|
|
10
|
+
|
|
11
|
+
**React**
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { type ReactNode } from 'react';
|
|
15
|
+
import { ConsentManagerProvider } from '@c15t/react';
|
|
16
|
+
import { tiktokPixel } from '@c15t/scripts/tiktok-pixel';
|
|
9
17
|
|
|
10
|
-
|
|
18
|
+
const scripts = [tiktokPixel({ pixelId: '123456789012345' })];
|
|
19
|
+
|
|
20
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
21
|
+
return (
|
|
22
|
+
<ConsentManagerProvider
|
|
23
|
+
options={{
|
|
24
|
+
mode: 'hosted',
|
|
25
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
26
|
+
scripts,
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</ConsentManagerProvider>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Next.js**
|
|
11
36
|
|
|
12
|
-
|
|
37
|
+
```tsx
|
|
38
|
+
'use client';
|
|
13
39
|
|
|
14
|
-
|
|
40
|
+
import { type ReactNode } from 'react';
|
|
41
|
+
import { ConsentManagerProvider } from '@c15t/nextjs';
|
|
42
|
+
import { tiktokPixel } from '@c15t/scripts/tiktok-pixel';
|
|
43
|
+
|
|
44
|
+
const scripts = [tiktokPixel({ pixelId: '123456789012345' })];
|
|
45
|
+
|
|
46
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
47
|
+
return (
|
|
48
|
+
<ConsentManagerProvider
|
|
49
|
+
options={{
|
|
50
|
+
mode: 'hosted',
|
|
51
|
+
backendURL: '/api/c15t',
|
|
52
|
+
scripts,
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{children}
|
|
56
|
+
</ConsentManagerProvider>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
15
60
|
|
|
16
|
-
|
|
17
|
-
> See the integration overview for how to pass scripts to your framework (JavaScript, React, or Next.js).
|
|
61
|
+
**JavaScript**
|
|
18
62
|
|
|
19
63
|
```ts
|
|
64
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
20
65
|
import { tiktokPixel } from '@c15t/scripts/tiktok-pixel';
|
|
21
66
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
67
|
+
getOrCreateConsentRuntime({
|
|
68
|
+
mode: 'hosted',
|
|
69
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
70
|
+
scripts: [tiktokPixel({ pixelId: '123456789012345' })],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## How c15t loads it
|
|
75
|
+
|
|
76
|
+
* **Category:** `marketing` (Ads & Pixels)
|
|
77
|
+
* **Loads when:** marketing consent is granted
|
|
78
|
+
* **On revocation:** [persists](/docs/frameworks/react/script-loader#persist-after-revocation) — c15t pushes the new consent state to `ttq` so TikTok stops tracking without removing the script
|
|
79
|
+
|
|
80
|
+
## Tracking events in your app
|
|
81
|
+
|
|
82
|
+
c15t gates the TikTok Pixel script from loading until `marketing` consent is granted. After consent is granted the script stays in the DOM, and c15t pushes the new consent state to `ttq` if consent is later revoked.
|
|
83
|
+
|
|
84
|
+
This means `window.ttq` is only defined after the user has granted marketing consent at least once. Before that, unguarded calls throw. After that, calls are safe — TikTok's own consent state suppresses tracking when revoked.
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { useCallback } from 'react';
|
|
88
|
+
import { useConsentManager } from '@c15t/react';
|
|
89
|
+
|
|
90
|
+
function useTrackPurchase() {
|
|
91
|
+
const { has } = useConsentManager();
|
|
92
|
+
return useCallback(() => {
|
|
93
|
+
if (has('marketing')) {
|
|
94
|
+
window.ttq?.track('CompletePayment', { value: 10.0, currency: 'USD' });
|
|
95
|
+
}
|
|
96
|
+
}, [has]);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function PurchaseButton() {
|
|
100
|
+
const trackPurchase = useTrackPurchase();
|
|
101
|
+
return <button onClick={trackPurchase}>Complete purchase</button>;
|
|
102
|
+
}
|
|
25
103
|
```
|
|
26
104
|
|
|
27
105
|
## Types
|