You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3c69aae
Browse filesBrowse the repository at this point in the historyBrowse files
1.**Build**: Downloads script, rewrites hardcoded URLs via AST using domain-to-proxy mappings derived from `proxy-configs.ts``domains[]`, applies SDK-specific `postProcess` patches
9
9
2.**Client**: Intercept plugin wraps `fetch`/`sendBeacon`/`XHR`/`Image.src` via `__nuxtScripts` — any non-same-origin URL is automatically proxied through `/_scripts/p/<host><path>`
10
10
3.**Server**: Nitro handler at `/_scripts/p/**` extracts the domain from the path, reconstructs the upstream URL, and proxies with privacy transforms
1.**Build**: `autoInject` on the PostHog proxy config sets `apiHost` → `/_scripts/p/us.i.posthog.com`
14
14
2.**Client**: SDK natively uses the injected endpoint — no interception needed
15
15
3.**Server**: Same Nitro proxy handler
16
16
17
-
PostHog is the only true Path B script — it uses npm mode (`src: false`, no script to download/rewrite).
17
+
PostHog uses npm mode, with no loader to download or rewrite.
18
+
Google Analytics keeps its visitor-specific loader remote.
19
+
The module provides a collection endpoint for its initial `gtag` configuration through `transport_url`.
20
+
Per-script `proxy: false` and static output disable that endpoint.
21
+
22
+
TikTok Pixel keeps its loader and collection requests direct to preserve visitor IDs and vendor cookies.
23
+
It has no collection proxy or proxy anonymization.
24
+
Google Tag Manager also keeps its visitor-specific loader remote and has no collection proxy.
18
25
19
26
### How runtime interception works
20
27
The AST rewriter transforms API calls in downloaded third-party scripts:
@@ -51,7 +58,7 @@ Some SDKs have quirks that require targeted regex patches after AST rewriting. T
51
58
-**Rybbit**: SDK derives API host from `document.currentScript.src.split("/script.js")[0]` — breaks when bundled to `/_scripts/assets/<hash>.js`. Regex replaces the split expression with the proxy path.
52
59
-**Fathom**: SDK checks `src.indexOf("cdn.usefathom.com") < 0` to detect self-hosted mode and overrides the tracker URL. Regex neutralizes this check.
53
60
54
-
Note: Google Analytics previously needed `postProcess` regex patches for dynamically constructed collect URLs. This is no longer needed since the runtime intercept plugin catches all non-same-origin URLs at the `sendBeacon`/`fetch` call site.
61
+
Google Analytics uses its configured collection endpoint instead of AST rewriting or native network interception.
55
62
56
63
## Path aliases (`proxy.alias`)
57
64
@@ -127,19 +134,20 @@ Four presets in `proxy-configs.ts` cover all proxy-enabled scripts:
127
134
| Preset | Flags | Used by |
128
135
|---|---|---|
129
136
|`PRIVACY_NONE`| all false | (not currently assigned to any script) |
@@ -182,8 +190,10 @@ Note: GTM, Segment, Crisp, Mixpanel, Bing UET, SpeedCurve, Pulse, and Statable h
182
190
### Domain-based proxy routing
183
191
Each proxy config declares `domains[]` — the list of third-party domains that script communicates with. The transform plugin derives rewrite rules at build time as `{ from: domain, to: proxyPrefix/domain }`. The server handler extracts the domain from the proxy path and forwards to the upstream.
184
192
185
-
### Runtime intercept: no rules needed
186
-
The intercept plugin proxies any non-same-origin URL. No domain allowlist or rule matching is required because `__nuxtScripts` wrappers are only injected into AST-rewritten third-party scripts. Regular app code uses native `fetch`/`sendBeacon` and is unaffected.
193
+
### Runtime interception
194
+
Bundled SDKs call `__nuxtScripts` wrappers after AST rewriting.
195
+
Google Analytics uses its configured collection endpoint.
196
+
Native application requests retain their original URLs.
187
197
188
198
The server handler extracts the target domain directly from the proxy path (`/_scripts/p/<host>/<path>`) and looks up privacy config by domain. Unrecognized domains default to full anonymization (fail-closed).
Copy file name to clipboardExpand all lines: docs/content/docs/1.guides/2.first-party.md
+15-10Lines changed: 15 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,10 +30,11 @@ The initial request no longer reaches the original host or pays its [DNS and con
30
30
31
31
### Reverse Proxy
32
32
33
-
Runtime requests (analytics beacons, pixel fires, tracking calls) are intercepted and forwarded through Nitro server routes at `/_scripts/p/`. The module rewrites URLs at two levels:
33
+
Runtime requests (analytics beacons, pixel fires, tracking calls) are intercepted and forwarded through Nitro server routes at `/_scripts/p/`. The module routes requests through source rewriting, runtime wrappers, or SDK endpoint configuration:
34
34
35
35
1.**AST rewriting** at build time: third-party domains in the bundled script source are replaced with your proxy path
36
-
2.**Runtime wrappers** on the client: the AST transform redirects `fetch`, `sendBeacon`, `XMLHttpRequest`, and `Image` calls in supported bundled SDKs through Nuxt Scripts wrappers, which proxy dynamically constructed URLs
36
+
2.**Runtime wrappers** on the client: bundled SDKs use Nuxt Scripts wrappers for dynamically constructed URLs.
37
+
3.**SDK endpoint configuration**: Google Analytics and PostHog receive a collection endpoint on your server. Their SDKs send events there without source rewriting.
37
38
38
39
Supported script and collection requests use same-origin URLs, so cookies set on those responses are not [third-party cookies](https://developer.mozilla.org/en-US/docs/Web/Privacy/Guides/Third-party_cookies). Host-based blocking rules are less likely to match them, although path-based or behavioral rules can still block requests.
39
40
@@ -74,7 +75,7 @@ Each proxied script has a default privacy tier chosen around the data its SDK ne
74
75
75
76
| Tier | What's anonymized | Scripts |
76
77
|------|-------------------|---------|
77
-
|**Full**| IP, user agent, language, screen, timezone, hardware fingerprints | Meta Pixel, TikTok Pixel, X Pixel, Snapchat Pixel, Reddit Pixel, LinkedIn Insight Tag |
78
+
|**Full**| IP, user agent, language, screen, timezone, hardware fingerprints | Meta Pixel, X Pixel, Snapchat Pixel, Reddit Pixel, LinkedIn Insight Tag |
78
79
|**Heatmap-safe**| IP, language, hardware fingerprints (preserves screen and user agent for session replay) | Google Analytics, Google AdSense, Microsoft Clarity, Hotjar |
79
80
|**IP only**| IP addresses anonymized to subnet level | Plausible, PostHog, Umami, Cloudflare Web Analytics, Vercel Analytics, Rybbit, Databuddy, Matomo, Ahrefs Web Analytics, Intercom, YouTube, Vimeo, Gravatar, Calendly |
PostHog receives the proxy endpoint through SDK config, so it can proxy collection requests without bundling. Matomo does not: its normal main-thread loader remains direct unless you use the separate Partytown routing path described below.
235
+
PostHog receives its proxy endpoint through SDK config. Google Analytics receives its collection endpoint through SDK configuration. Both can proxy without bundling. Matomo does not: its normal main-thread loader remains direct unless you use the separate Partytown routing path described below.
235
236
::
236
237
237
238
### Static Hosting (SSG)
@@ -264,26 +265,28 @@ These scripts are downloaded at build time, served from your domain, and have th
264
265
265
266
| Category | Scripts |
266
267
|----------|---------|
267
-
|**Analytics**|[Google Analytics](/scripts/google-analytics), [Plausible](/scripts/plausible-analytics), [Cloudflare Web Analytics](/scripts/cloudflare-web-analytics), [Umami](/scripts/umami-analytics), [Rybbit](/scripts/rybbit-analytics), [Databuddy](/scripts/databuddy-analytics), [Ahrefs Web Analytics](/scripts/ahrefs-analytics), [Vercel Analytics](/scripts/vercel-analytics), [Microsoft Clarity](/scripts/clarity), [Hotjar](/scripts/hotjar)|
The module doesn't bundle PostHog's SDK because it comes from a package dependency, but it can still send collection requests through your server:
275
+
These integrations keep their SDK outside the build bundle and can send collection requests through your server:
275
276
276
277
| Script | How it works |
277
278
|--------|-------------|
279
+
|[Google Analytics](/scripts/google-analytics)| Visitor-specific loader stays remote. Collection requests use the proxy on the main thread and with Partytown. |
278
280
|[PostHog](/scripts/posthog)| SDK installed as [`posthog-js`](https://posthog.com/docs/libraries/js#option-2-install-via-package-manager). Proxy endpoint auto-injected via `apiHost` config. |
279
281
282
+
Google still receives direct loader and other SDK requests from the browser. Proxy privacy transforms apply only to collection requests.
283
+
280
284
### Bundled, with Third-Party Runtime Traffic
281
285
282
286
These integrations serve their main loader from your domain, but some runtime requests still go directly to third-party servers:
283
287
284
288
| Script | Remaining direct traffic |
285
289
|--------|--------------------------|
286
-
|[Google Tag Manager](/scripts/google-tag-manager)| GTM's core function is loading other scripts at runtime. Those runtime scripts bypass build-time rewriting. |
287
290
|[Fathom](/scripts/fathom-analytics)| Fathom's bot detection rejects beacons from the server's IP, so Nuxt Scripts bundles the SDK but leaves beacons direct. |
288
291
|[Pulse](/scripts/pulse-analytics)| Pulse identifies visitors from the connecting IP, so proxied beacons would merge everyone into one visitor. Nuxt Scripts bundles the tracker but leaves beacons direct. |
289
292
|[Statable](/scripts/statable-analytics)| Statable identifies visitors from the connecting IP and user agent, so proxied beacons would merge everyone into one visitor. Nuxt Scripts bundles the tracker but leaves beacons direct. |
@@ -303,6 +306,8 @@ These integrations load their SDKs and runtime traffic directly from their confi
303
306
304
307
| Script | Direct-loading behavior |
305
308
|--------|-------------------------|
309
+
|[TikTok Pixel](/scripts/tiktok-pixel)| Loader and collection requests stay direct to preserve visitor IDs and vendor cookies. Proxy anonymization does not apply. |
310
+
|[Google Tag Manager](/scripts/google-tag-manager)| Visitor-specific loader and scripts it loads remain direct. |
306
311
|**Stripe**|[Stripe requires Stripe.js to load directly from `js.stripe.com`](https://docs.stripe.com/payments/finalize-payments-on-the-server?platform=web&type=setup) for PCI compliance. |
307
312
|**PayPal**| Nuxt Scripts loads PayPal's v6 core from PayPal's documented [`/web-sdk/v6/core` URL](https://developer.paypal.com/upgrade/ec/guide/Web%20SDK%20v6/); the registry declares no bundle or collection proxy. |
308
313
|**Google reCAPTCHA**| Nuxt Scripts loads `api.js` or `enterprise.js` directly from Google, or from `recaptcha.net`; the registry declares no bundle or collection proxy. Google separately recommends loading reCAPTCHA early because [more page context improves its assessment](https://developers.google.com/recaptcha/docs/loading). |
Copy file name to clipboardExpand all lines: docs/content/scripts/tiktok-pixel.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,10 @@ Use [`useScriptTikTokPixel()`{lang="ts"}](/scripts/tiktok-pixel){lang="ts"} to l
18
18
::script-docs
19
19
::
20
20
21
+
The loader and collection requests go directly to TikTok to preserve visitor IDs and [vendor cookies](https://ads.tiktok.com/resources/help/article/using-cookies-with-tiktok-pixel?lang=en).
22
+
Nuxt Scripts does not bundle TikTok Pixel or apply collection proxying and IP anonymization.
23
+
Use a [consent trigger](/docs/guides/consent#binary-load-gate) to control when requests start.
24
+
21
25
## Disabling automatic page views
22
26
23
27
By default, TikTok Pixel tracks a page view during initialization. Disable it in the composable call:
0 commit comments