@shware/analytics 16.3.3 → 16.3.5
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/dist/hooks/use-outbound-click-analytics.cjs +14 -6
- package/dist/hooks/use-outbound-click-analytics.cjs.map +1 -1
- package/dist/hooks/use-outbound-click-analytics.d.cts +3 -2
- package/dist/hooks/use-outbound-click-analytics.d.cts.map +1 -1
- package/dist/hooks/use-outbound-click-analytics.d.mts +3 -2
- package/dist/hooks/use-outbound-click-analytics.d.mts.map +1 -1
- package/dist/hooks/use-outbound-click-analytics.mjs +14 -6
- package/dist/hooks/use-outbound-click-analytics.mjs.map +1 -1
- package/dist/next/index.cjs +2 -1
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts.map +1 -1
- package/dist/next/index.d.mts.map +1 -1
- package/dist/next/index.mjs +2 -1
- package/dist/next/index.mjs.map +1 -1
- package/dist/third-parties/analytics-props.cjs +2 -1
- package/dist/third-parties/analytics-props.cjs.map +1 -1
- package/dist/third-parties/analytics-props.mjs +2 -1
- package/dist/third-parties/analytics-props.mjs.map +1 -1
- package/dist/third-parties/index.cjs +1 -0
- package/dist/third-parties/index.d.cts +2 -2
- package/dist/third-parties/index.d.mts +2 -2
- package/dist/third-parties/index.mjs +2 -2
- package/dist/third-parties/integration.cjs +31 -0
- package/dist/third-parties/integration.cjs.map +1 -1
- package/dist/third-parties/integration.d.cts +16 -0
- package/dist/third-parties/integration.d.cts.map +1 -1
- package/dist/third-parties/integration.d.mts +16 -0
- package/dist/third-parties/integration.d.mts.map +1 -1
- package/dist/third-parties/integration.mjs +29 -1
- package/dist/third-parties/integration.mjs.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.cjs +2 -2
- package/dist/third-parties/linkedin-insight-tag.cjs.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.d.cts.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.d.mts.map +1 -1
- package/dist/third-parties/linkedin-insight-tag.mjs +2 -2
- package/dist/third-parties/linkedin-insight-tag.mjs.map +1 -1
- package/dist/third-parties/meta-pixel.cjs +1 -2
- package/dist/third-parties/meta-pixel.cjs.map +1 -1
- package/dist/third-parties/meta-pixel.d.cts.map +1 -1
- package/dist/third-parties/meta-pixel.d.mts.map +1 -1
- package/dist/third-parties/meta-pixel.mjs +2 -3
- package/dist/third-parties/meta-pixel.mjs.map +1 -1
- package/dist/third-parties/microsoft-uet.cjs +2 -5
- package/dist/third-parties/microsoft-uet.cjs.map +1 -1
- package/dist/third-parties/microsoft-uet.d.cts.map +1 -1
- package/dist/third-parties/microsoft-uet.d.mts.map +1 -1
- package/dist/third-parties/microsoft-uet.mjs +3 -6
- package/dist/third-parties/microsoft-uet.mjs.map +1 -1
- package/dist/third-parties/openai-pixel.cjs +1 -2
- package/dist/third-parties/openai-pixel.cjs.map +1 -1
- package/dist/third-parties/openai-pixel.d.cts.map +1 -1
- package/dist/third-parties/openai-pixel.d.mts.map +1 -1
- package/dist/third-parties/openai-pixel.mjs +2 -3
- package/dist/third-parties/openai-pixel.mjs.map +1 -1
- package/dist/third-parties/posthog.cjs +2 -2
- package/dist/third-parties/posthog.cjs.map +1 -1
- package/dist/third-parties/posthog.d.cts.map +1 -1
- package/dist/third-parties/posthog.d.mts.map +1 -1
- package/dist/third-parties/posthog.mjs +2 -2
- package/dist/third-parties/posthog.mjs.map +1 -1
- package/dist/third-parties/reddit-pixel.cjs +1 -2
- package/dist/third-parties/reddit-pixel.cjs.map +1 -1
- package/dist/third-parties/reddit-pixel.d.cts.map +1 -1
- package/dist/third-parties/reddit-pixel.d.mts.map +1 -1
- package/dist/third-parties/reddit-pixel.mjs +2 -3
- package/dist/third-parties/reddit-pixel.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -6,8 +6,9 @@ let react = require("react");
|
|
|
6
6
|
* The registrable domain (eTLD+1) of `hostname`, found the way gtag's `cookie_domain: 'auto'`
|
|
7
7
|
* finds it: a cookie is tried on each suffix from the shortest up, and the first one the browser
|
|
8
8
|
* accepts is the domain — browsers refuse public suffixes (`com`, `co.uk`), so no suffix list is
|
|
9
|
-
* needed
|
|
10
|
-
*
|
|
9
|
+
* needed (gtag's `cookie_domain: 'auto'` walks the same list). A hostname without dots
|
|
10
|
+
* (`localhost`) or one no suffix accepts (an IP address) is its own domain, as a host-only cookie
|
|
11
|
+
* would be. `probe` tries one suffix and says whether the cookie stuck.
|
|
11
12
|
*/
|
|
12
13
|
function registrableDomain(hostname, probe = canSetCookieOn) {
|
|
13
14
|
const labels = hostname.split(".");
|
|
@@ -18,12 +19,19 @@ function registrableDomain(hostname, probe = canSetCookieOn) {
|
|
|
18
19
|
}
|
|
19
20
|
return hostname;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Whether the browser accepts a cookie for `domain`, read back by a value made for this one probe:
|
|
24
|
+
* a cookie of the same name the site already holds can then neither pass the check for a refused
|
|
25
|
+
* suffix nor hide the probe (gtag writes its real cookie this way and keeps it; this one is a
|
|
26
|
+
* throwaway, deleted at once).
|
|
27
|
+
*/
|
|
22
28
|
function canSetCookieOn(domain) {
|
|
29
|
+
const name = "_sa_d";
|
|
30
|
+
const value = Math.random().toString(36).slice(2);
|
|
23
31
|
try {
|
|
24
|
-
document.cookie = `${
|
|
25
|
-
const stuck = document.cookie.split("; ").includes(`${
|
|
26
|
-
if (stuck) document.cookie = `${
|
|
32
|
+
document.cookie = `${name}=${value}; domain=${domain}; path=/; SameSite=Lax`;
|
|
33
|
+
const stuck = document.cookie.split("; ").includes(`${name}=${value}`);
|
|
34
|
+
if (stuck) document.cookie = `${name}=; domain=${domain}; path=/; max-age=0; SameSite=Lax`;
|
|
27
35
|
return stuck;
|
|
28
36
|
} catch {
|
|
29
37
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-outbound-click-analytics.cjs","names":[],"sources":["../../src/hooks/use-outbound-click-analytics.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { track } from '../track/index';\n\n/**\n * The registrable domain (eTLD+1) of `hostname`, found the way gtag's `cookie_domain: 'auto'`\n * finds it: a cookie is tried on each suffix from the shortest up, and the first one the browser\n * accepts is the domain — browsers refuse public suffixes (`com`, `co.uk`), so no suffix list is\n * needed. A hostname without dots (`localhost`) or one no suffix accepts (an IP address) is its\n *
|
|
1
|
+
{"version":3,"file":"use-outbound-click-analytics.cjs","names":[],"sources":["../../src/hooks/use-outbound-click-analytics.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { track } from '../track/index';\n\n/**\n * The registrable domain (eTLD+1) of `hostname`, found the way gtag's `cookie_domain: 'auto'`\n * finds it: a cookie is tried on each suffix from the shortest up, and the first one the browser\n * accepts is the domain — browsers refuse public suffixes (`com`, `co.uk`), so no suffix list is\n * needed (gtag's `cookie_domain: 'auto'` walks the same list). A hostname without dots\n * (`localhost`) or one no suffix accepts (an IP address) is its own domain, as a host-only cookie\n * would be. `probe` tries one suffix and says whether the cookie stuck.\n */\nexport function registrableDomain(\n hostname: string,\n probe: (domain: string) => boolean = canSetCookieOn\n): string {\n const labels = hostname.split('.');\n if (labels.length < 2 || /^[\\d.]+$/.test(hostname)) return hostname;\n for (let i = labels.length - 2; i >= 0; i -= 1) {\n const candidate = labels.slice(i).join('.');\n if (probe(candidate)) return candidate;\n }\n return hostname;\n}\n\n/**\n * Whether the browser accepts a cookie for `domain`, read back by a value made for this one probe:\n * a cookie of the same name the site already holds can then neither pass the check for a refused\n * suffix nor hide the probe (gtag writes its real cookie this way and keeps it; this one is a\n * throwaway, deleted at once).\n */\nfunction canSetCookieOn(domain: string): boolean {\n const name = '_sa_d';\n const value = Math.random().toString(36).slice(2);\n try {\n document.cookie = `${name}=${value}; domain=${domain}; path=/; SameSite=Lax`;\n const stuck = document.cookie.split('; ').includes(`${name}=${value}`);\n if (stuck) document.cookie = `${name}=; domain=${domain}; path=/; max-age=0; SameSite=Lax`;\n return stuck;\n } catch {\n return false;\n }\n}\n\n/**\n * Whether a link leads away from the site, by GA4's definition of an outbound click: an http(s)\n * link to a host that is not the site's registrable domain or a subdomain of it. `mailto:`,\n * `tel:` and the like are not outbound clicks (GA4 never counts them), and `www.` → `app.` is\n * not leaving the site.\n */\nexport function isOutboundLink(url: URL, siteDomain: string): boolean {\n if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;\n const host = url.hostname;\n return host !== siteDomain && !host.endsWith(`.${siteDomain}`);\n}\n\n/**\n * Tracks outbound link clicks - when a user clicks a link that leads away from the site to\n * another website (see `isOutboundLink`).\n */\nexport function useOutboundClickAnalytics() {\n useEffect(() => {\n const siteDomain = registrableDomain(window.location.hostname);\n const onClick = (event: MouseEvent) => {\n // Find the closest anchor element from the clicked target\n const target = event.target as HTMLElement;\n const anchor = target.closest('a');\n if (!anchor?.href) return;\n\n try {\n const url = new URL(anchor.href, window.location.origin);\n if (!isOutboundLink(url, siteDomain)) return;\n track('click', {\n outbound: true,\n link_id: anchor.id || '',\n link_url: anchor.href,\n // An anchor can wrap a whole card, so its text runs to kilobytes of markup content\n // that no report ever looks at. GA4 keeps 100 characters of a text event parameter;\n // 512 leaves room for the whole label of a long button while staying well under the\n // transport limit.\n link_text: anchor.textContent.trim().slice(0, 512),\n link_domain: url.hostname,\n link_classes: anchor.className || '',\n });\n } catch {\n // Invalid URL, ignore\n }\n };\n\n document.addEventListener('click', onClick, { passive: true, capture: true });\n return () => document.removeEventListener('click', onClick, { capture: true });\n }, []);\n}\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,kBACd,UACA,QAAqC,gBAC7B;CACR,MAAM,SAAS,SAAS,MAAM,GAAG;CACjC,IAAI,OAAO,SAAS,KAAK,WAAW,KAAK,QAAQ,GAAG,OAAO;CAC3D,KAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;EAC9C,MAAM,YAAY,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG;EAC1C,IAAI,MAAM,SAAS,GAAG,OAAO;CAC/B;CACA,OAAO;AACT;;;;;;;AAQA,SAAS,eAAe,QAAyB;CAC/C,MAAM,OAAO;CACb,MAAM,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;CAChD,IAAI;EACF,SAAS,SAAS,GAAG,KAAK,GAAG,MAAM,WAAW,OAAO;EACrD,MAAM,QAAQ,SAAS,OAAO,MAAM,IAAI,CAAC,CAAC,SAAS,GAAG,KAAK,GAAG,OAAO;EACrE,IAAI,OAAO,SAAS,SAAS,GAAG,KAAK,YAAY,OAAO;EACxD,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;AAQA,SAAgB,eAAe,KAAU,YAA6B;CACpE,IAAI,IAAI,aAAa,WAAW,IAAI,aAAa,UAAU,OAAO;CAClE,MAAM,OAAO,IAAI;CACjB,OAAO,SAAS,cAAc,CAAC,KAAK,SAAS,IAAI,YAAY;AAC/D;;;;;AAMA,SAAgB,4BAA4B;CAC1C,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,aAAa,kBAAkB,OAAO,SAAS,QAAQ;EAC7D,MAAM,WAAW,UAAsB;GAGrC,MAAM,SADS,MAAM,OACC,QAAQ,GAAG;GACjC,IAAI,CAAC,QAAQ,MAAM;GAEnB,IAAI;IACF,MAAM,MAAM,IAAI,IAAI,OAAO,MAAM,OAAO,SAAS,MAAM;IACvD,IAAI,CAAC,eAAe,KAAK,UAAU,GAAG;IACtC,oBAAA,MAAM,SAAS;KACb,UAAU;KACV,SAAS,OAAO,MAAM;KACtB,UAAU,OAAO;KAKjB,WAAW,OAAO,YAAY,KAAK,CAAC,CAAC,MAAM,GAAG,GAAG;KACjD,aAAa,IAAI;KACjB,cAAc,OAAO,aAAa;IACpC,CAAC;GACH,QAAQ,CAER;EACF;EAEA,SAAS,iBAAiB,SAAS,SAAS;GAAE,SAAS;GAAM,SAAS;EAAK,CAAC;EAC5E,aAAa,SAAS,oBAAoB,SAAS,SAAS,EAAE,SAAS,KAAK,CAAC;CAC/E,GAAG,CAAC,CAAC;AACP"}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* The registrable domain (eTLD+1) of `hostname`, found the way gtag's `cookie_domain: 'auto'`
|
|
3
3
|
* finds it: a cookie is tried on each suffix from the shortest up, and the first one the browser
|
|
4
4
|
* accepts is the domain — browsers refuse public suffixes (`com`, `co.uk`), so no suffix list is
|
|
5
|
-
* needed
|
|
6
|
-
*
|
|
5
|
+
* needed (gtag's `cookie_domain: 'auto'` walks the same list). A hostname without dots
|
|
6
|
+
* (`localhost`) or one no suffix accepts (an IP address) is its own domain, as a host-only cookie
|
|
7
|
+
* would be. `probe` tries one suffix and says whether the cookie stuck.
|
|
7
8
|
*/
|
|
8
9
|
export declare function registrableDomain(hostname: string, probe?: (domain: string) => boolean): string;
|
|
9
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-outbound-click-analytics.d.cts","names":[],"sources":["../../src/hooks/use-outbound-click-analytics.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-outbound-click-analytics.d.cts","names":[],"sources":["../../src/hooks/use-outbound-click-analytics.ts"],"mappings":";;;;;;;;wBAWgB,kBACd,kBACA,SAAQ;;;;;;;wBAoCM,eAAe,KAAK,KAAK;;;;;wBAUzB"}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* The registrable domain (eTLD+1) of `hostname`, found the way gtag's `cookie_domain: 'auto'`
|
|
3
3
|
* finds it: a cookie is tried on each suffix from the shortest up, and the first one the browser
|
|
4
4
|
* accepts is the domain — browsers refuse public suffixes (`com`, `co.uk`), so no suffix list is
|
|
5
|
-
* needed
|
|
6
|
-
*
|
|
5
|
+
* needed (gtag's `cookie_domain: 'auto'` walks the same list). A hostname without dots
|
|
6
|
+
* (`localhost`) or one no suffix accepts (an IP address) is its own domain, as a host-only cookie
|
|
7
|
+
* would be. `probe` tries one suffix and says whether the cookie stuck.
|
|
7
8
|
*/
|
|
8
9
|
export declare function registrableDomain(hostname: string, probe?: (domain: string) => boolean): string;
|
|
9
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-outbound-click-analytics.d.mts","names":[],"sources":["../../src/hooks/use-outbound-click-analytics.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-outbound-click-analytics.d.mts","names":[],"sources":["../../src/hooks/use-outbound-click-analytics.ts"],"mappings":";;;;;;;;wBAWgB,kBACd,kBACA,SAAQ;;;;;;;wBAoCM,eAAe,KAAK,KAAK;;;;;wBAUzB"}
|
|
@@ -5,8 +5,9 @@ import { useEffect } from "react";
|
|
|
5
5
|
* The registrable domain (eTLD+1) of `hostname`, found the way gtag's `cookie_domain: 'auto'`
|
|
6
6
|
* finds it: a cookie is tried on each suffix from the shortest up, and the first one the browser
|
|
7
7
|
* accepts is the domain — browsers refuse public suffixes (`com`, `co.uk`), so no suffix list is
|
|
8
|
-
* needed
|
|
9
|
-
*
|
|
8
|
+
* needed (gtag's `cookie_domain: 'auto'` walks the same list). A hostname without dots
|
|
9
|
+
* (`localhost`) or one no suffix accepts (an IP address) is its own domain, as a host-only cookie
|
|
10
|
+
* would be. `probe` tries one suffix and says whether the cookie stuck.
|
|
10
11
|
*/
|
|
11
12
|
function registrableDomain(hostname, probe = canSetCookieOn) {
|
|
12
13
|
const labels = hostname.split(".");
|
|
@@ -17,12 +18,19 @@ function registrableDomain(hostname, probe = canSetCookieOn) {
|
|
|
17
18
|
}
|
|
18
19
|
return hostname;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Whether the browser accepts a cookie for `domain`, read back by a value made for this one probe:
|
|
23
|
+
* a cookie of the same name the site already holds can then neither pass the check for a refused
|
|
24
|
+
* suffix nor hide the probe (gtag writes its real cookie this way and keeps it; this one is a
|
|
25
|
+
* throwaway, deleted at once).
|
|
26
|
+
*/
|
|
21
27
|
function canSetCookieOn(domain) {
|
|
28
|
+
const name = "_sa_d";
|
|
29
|
+
const value = Math.random().toString(36).slice(2);
|
|
22
30
|
try {
|
|
23
|
-
document.cookie = `${
|
|
24
|
-
const stuck = document.cookie.split("; ").includes(`${
|
|
25
|
-
if (stuck) document.cookie = `${
|
|
31
|
+
document.cookie = `${name}=${value}; domain=${domain}; path=/; SameSite=Lax`;
|
|
32
|
+
const stuck = document.cookie.split("; ").includes(`${name}=${value}`);
|
|
33
|
+
if (stuck) document.cookie = `${name}=; domain=${domain}; path=/; max-age=0; SameSite=Lax`;
|
|
26
34
|
return stuck;
|
|
27
35
|
} catch {
|
|
28
36
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-outbound-click-analytics.mjs","names":[],"sources":["../../src/hooks/use-outbound-click-analytics.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { track } from '../track/index';\n\n/**\n * The registrable domain (eTLD+1) of `hostname`, found the way gtag's `cookie_domain: 'auto'`\n * finds it: a cookie is tried on each suffix from the shortest up, and the first one the browser\n * accepts is the domain — browsers refuse public suffixes (`com`, `co.uk`), so no suffix list is\n * needed. A hostname without dots (`localhost`) or one no suffix accepts (an IP address) is its\n *
|
|
1
|
+
{"version":3,"file":"use-outbound-click-analytics.mjs","names":[],"sources":["../../src/hooks/use-outbound-click-analytics.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { track } from '../track/index';\n\n/**\n * The registrable domain (eTLD+1) of `hostname`, found the way gtag's `cookie_domain: 'auto'`\n * finds it: a cookie is tried on each suffix from the shortest up, and the first one the browser\n * accepts is the domain — browsers refuse public suffixes (`com`, `co.uk`), so no suffix list is\n * needed (gtag's `cookie_domain: 'auto'` walks the same list). A hostname without dots\n * (`localhost`) or one no suffix accepts (an IP address) is its own domain, as a host-only cookie\n * would be. `probe` tries one suffix and says whether the cookie stuck.\n */\nexport function registrableDomain(\n hostname: string,\n probe: (domain: string) => boolean = canSetCookieOn\n): string {\n const labels = hostname.split('.');\n if (labels.length < 2 || /^[\\d.]+$/.test(hostname)) return hostname;\n for (let i = labels.length - 2; i >= 0; i -= 1) {\n const candidate = labels.slice(i).join('.');\n if (probe(candidate)) return candidate;\n }\n return hostname;\n}\n\n/**\n * Whether the browser accepts a cookie for `domain`, read back by a value made for this one probe:\n * a cookie of the same name the site already holds can then neither pass the check for a refused\n * suffix nor hide the probe (gtag writes its real cookie this way and keeps it; this one is a\n * throwaway, deleted at once).\n */\nfunction canSetCookieOn(domain: string): boolean {\n const name = '_sa_d';\n const value = Math.random().toString(36).slice(2);\n try {\n document.cookie = `${name}=${value}; domain=${domain}; path=/; SameSite=Lax`;\n const stuck = document.cookie.split('; ').includes(`${name}=${value}`);\n if (stuck) document.cookie = `${name}=; domain=${domain}; path=/; max-age=0; SameSite=Lax`;\n return stuck;\n } catch {\n return false;\n }\n}\n\n/**\n * Whether a link leads away from the site, by GA4's definition of an outbound click: an http(s)\n * link to a host that is not the site's registrable domain or a subdomain of it. `mailto:`,\n * `tel:` and the like are not outbound clicks (GA4 never counts them), and `www.` → `app.` is\n * not leaving the site.\n */\nexport function isOutboundLink(url: URL, siteDomain: string): boolean {\n if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;\n const host = url.hostname;\n return host !== siteDomain && !host.endsWith(`.${siteDomain}`);\n}\n\n/**\n * Tracks outbound link clicks - when a user clicks a link that leads away from the site to\n * another website (see `isOutboundLink`).\n */\nexport function useOutboundClickAnalytics() {\n useEffect(() => {\n const siteDomain = registrableDomain(window.location.hostname);\n const onClick = (event: MouseEvent) => {\n // Find the closest anchor element from the clicked target\n const target = event.target as HTMLElement;\n const anchor = target.closest('a');\n if (!anchor?.href) return;\n\n try {\n const url = new URL(anchor.href, window.location.origin);\n if (!isOutboundLink(url, siteDomain)) return;\n track('click', {\n outbound: true,\n link_id: anchor.id || '',\n link_url: anchor.href,\n // An anchor can wrap a whole card, so its text runs to kilobytes of markup content\n // that no report ever looks at. GA4 keeps 100 characters of a text event parameter;\n // 512 leaves room for the whole label of a long button while staying well under the\n // transport limit.\n link_text: anchor.textContent.trim().slice(0, 512),\n link_domain: url.hostname,\n link_classes: anchor.className || '',\n });\n } catch {\n // Invalid URL, ignore\n }\n };\n\n document.addEventListener('click', onClick, { passive: true, capture: true });\n return () => document.removeEventListener('click', onClick, { capture: true });\n }, []);\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,kBACd,UACA,QAAqC,gBAC7B;CACR,MAAM,SAAS,SAAS,MAAM,GAAG;CACjC,IAAI,OAAO,SAAS,KAAK,WAAW,KAAK,QAAQ,GAAG,OAAO;CAC3D,KAAK,IAAI,IAAI,OAAO,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;EAC9C,MAAM,YAAY,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG;EAC1C,IAAI,MAAM,SAAS,GAAG,OAAO;CAC/B;CACA,OAAO;AACT;;;;;;;AAQA,SAAS,eAAe,QAAyB;CAC/C,MAAM,OAAO;CACb,MAAM,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;CAChD,IAAI;EACF,SAAS,SAAS,GAAG,KAAK,GAAG,MAAM,WAAW,OAAO;EACrD,MAAM,QAAQ,SAAS,OAAO,MAAM,IAAI,CAAC,CAAC,SAAS,GAAG,KAAK,GAAG,OAAO;EACrE,IAAI,OAAO,SAAS,SAAS,GAAG,KAAK,YAAY,OAAO;EACxD,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;AAQA,SAAgB,eAAe,KAAU,YAA6B;CACpE,IAAI,IAAI,aAAa,WAAW,IAAI,aAAa,UAAU,OAAO;CAClE,MAAM,OAAO,IAAI;CACjB,OAAO,SAAS,cAAc,CAAC,KAAK,SAAS,IAAI,YAAY;AAC/D;;;;;AAMA,SAAgB,4BAA4B;CAC1C,gBAAgB;EACd,MAAM,aAAa,kBAAkB,OAAO,SAAS,QAAQ;EAC7D,MAAM,WAAW,UAAsB;GAGrC,MAAM,SADS,MAAM,OACC,QAAQ,GAAG;GACjC,IAAI,CAAC,QAAQ,MAAM;GAEnB,IAAI;IACF,MAAM,MAAM,IAAI,IAAI,OAAO,MAAM,OAAO,SAAS,MAAM;IACvD,IAAI,CAAC,eAAe,KAAK,UAAU,GAAG;IACtC,MAAM,SAAS;KACb,UAAU;KACV,SAAS,OAAO,MAAM;KACtB,UAAU,OAAO;KAKjB,WAAW,OAAO,YAAY,KAAK,CAAC,CAAC,MAAM,GAAG,GAAG;KACjD,aAAa,IAAI;KACjB,cAAc,OAAO,aAAa;IACpC,CAAC;GACH,QAAQ,CAER;EACF;EAEA,SAAS,iBAAiB,SAAS,SAAS;GAAE,SAAS;GAAM,SAAS;EAAK,CAAC;EAC5E,aAAa,SAAS,oBAAoB,SAAS,SAAS,EAAE,SAAS,KAAK,CAAC;CAC/E,GAAG,CAAC,CAAC;AACP"}
|
package/dist/next/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
4
4
|
const require_track_index = require("../track/index.cjs");
|
|
5
5
|
const require_hooks_use_outbound_click_analytics = require("../hooks/use-outbound-click-analytics.cjs");
|
|
6
|
+
const require_third_parties_integration = require("../third-parties/integration.cjs");
|
|
6
7
|
const require_third_parties_microsoft_uet = require("../third-parties/microsoft-uet.cjs");
|
|
7
8
|
const require_hooks_use_uet_id_sync = require("../hooks/use-uet-id-sync.cjs");
|
|
8
9
|
const require_hooks_use_web_analytics = require("../hooks/use-web-analytics.cjs");
|
|
@@ -51,7 +52,7 @@ function Analytics({ integrations = [], facebookAppId, nonce, reportWebVitals =
|
|
|
51
52
|
property: "fb:app_id",
|
|
52
53
|
content: facebookAppId
|
|
53
54
|
}),
|
|
54
|
-
|
|
55
|
+
require_third_parties_integration.integrationScripts(integrations).map((script) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(next_script.default, {
|
|
55
56
|
id: script.id,
|
|
56
57
|
nonce,
|
|
57
58
|
strategy: script.strategy ?? "afterInteractive",
|
package/dist/next/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["usePathname","useSearchParams","uetCustomerIdOf","Suspense","Script"],"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { Suspense } from 'react';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useUETIdSync } from '../hooks/use-uet-id-sync';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { type AnalyticsProps, preconnectIntegrations } from '../third-parties/analytics-props';\nimport { uetCustomerIdOf } from '../third-parties/microsoft-uet';\nimport { track } from '../track/index';\n\n/**\n * Its own component under a Suspense boundary: `useSearchParams` in a statically rendered route\n * bails the whole tree out to client rendering unless something above it suspends, and Next\n * fails the build for a page that lets it. The boundary is here so a host does not have to know.\n */\nfunction PageViews() {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n useWebAnalytics(pathname, searchParams.toString());\n return null;\n}\n\nexport function Analytics({\n integrations = [],\n facebookAppId,\n nonce,\n reportWebVitals = true,\n}: AnalyticsProps) {\n useOutboundClickAnalytics();\n useUETIdSync(uetCustomerIdOf(integrations));\n preconnectIntegrations(integrations);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n value: metric.delta,\n metric_id: metric.id,\n metric_value: metric.value,\n metric_delta: metric.delta,\n metric_rating: metric.rating,\n metric_navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n <Suspense fallback={null}>\n <PageViews />\n </Suspense>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {integrations
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["usePathname","useSearchParams","uetCustomerIdOf","Suspense","integrationScripts","Script"],"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { Suspense } from 'react';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useUETIdSync } from '../hooks/use-uet-id-sync';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { type AnalyticsProps, preconnectIntegrations } from '../third-parties/analytics-props';\nimport { integrationScripts } from '../third-parties/integration';\nimport { uetCustomerIdOf } from '../third-parties/microsoft-uet';\nimport { track } from '../track/index';\n\n/**\n * Its own component under a Suspense boundary: `useSearchParams` in a statically rendered route\n * bails the whole tree out to client rendering unless something above it suspends, and Next\n * fails the build for a page that lets it. The boundary is here so a host does not have to know.\n */\nfunction PageViews() {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n useWebAnalytics(pathname, searchParams.toString());\n return null;\n}\n\nexport function Analytics({\n integrations = [],\n facebookAppId,\n nonce,\n reportWebVitals = true,\n}: AnalyticsProps) {\n useOutboundClickAnalytics();\n useUETIdSync(uetCustomerIdOf(integrations));\n preconnectIntegrations(integrations);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n value: metric.delta,\n metric_id: metric.id,\n metric_value: metric.value,\n metric_delta: metric.delta,\n metric_rating: metric.rating,\n metric_navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n <Suspense fallback={null}>\n <PageViews />\n </Suspense>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {integrationScripts(integrations).map((script) => (\n <Script\n key={script.id}\n id={script.id}\n nonce={nonce}\n strategy={script.strategy ?? 'afterInteractive'}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ))}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBA,SAAS,YAAY;CACnB,MAAM,YAAA,GAAWA,gBAAAA,YAAAA,CAAY;CAC7B,MAAM,gBAAA,GAAeC,gBAAAA,gBAAAA,CAAgB;CACrC,gCAAA,gBAAgB,UAAU,aAAa,SAAS,CAAC;CACjD,OAAO;AACT;AAEA,SAAgB,UAAU,EACxB,eAAe,CAAC,GAChB,eACA,OACA,kBAAkB,QACD;CACjB,2CAAA,0BAA0B;CAC1B,8BAAA,aAAaC,oCAAAA,gBAAgB,YAAY,CAAC;CAC1C,sCAAA,uBAAuB,YAAY;CAEnC,CAAA,GAAA,gBAAA,mBAAA,EAAoB,WAAW;EAC7B,IAAI,CAAC,iBAAiB;EACtB,MAAM,aAAa;GACjB,OAAO,OAAO;GACd,WAAW,OAAO;GAClB,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,eAAe,OAAO;GACtB,wBAAwB,OAAO;GAC/B,iBAAiB;EACnB;EACA,oBAAA,MAAM,OAAO,MAAM,UAAU;CAC/B,CAAC;CAED,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA;EACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,MAAAA,UAAD;GAAU,UAAU;GAClB,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD,CAAY,CAAA;EACJ,CAAA;EACT,iBAAiB,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;GAAM,UAAS;GAAY,SAAS;EAAgB,CAAA;EACrEC,kCAAAA,mBAAmB,YAAY,CAAC,CAAC,KAAK,WACrC,iBAAA,GAAA,kBAAA,IAAA,CAACC,YAAAA,SAAD;GAEE,IAAI,OAAO;GACJ;GACP,UAAU,OAAO,YAAY;GAC7B,yBAAyB,EAAE,QAAQ,OAAO,OAAO;EAClD,GALM,OAAO,EAKb,CACF;CACD,EAAA,CAAA;AAEN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/next/index.tsx"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/next/index.tsx"],"mappings":";wBA0BgB,YACd,cACA,eACA,OACA,mBACC,iCAAc,IAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/next/index.tsx"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/next/index.tsx"],"mappings":";wBA0BgB,YACd,cACA,eACA,OACA,mBACC,iCAAc,IAAA"}
|
package/dist/next/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { track } from "../track/index.mjs";
|
|
3
3
|
import { useOutboundClickAnalytics } from "../hooks/use-outbound-click-analytics.mjs";
|
|
4
|
+
import { integrationScripts } from "../third-parties/integration.mjs";
|
|
4
5
|
import { uetCustomerIdOf } from "../third-parties/microsoft-uet.mjs";
|
|
5
6
|
import { useUETIdSync } from "../hooks/use-uet-id-sync.mjs";
|
|
6
7
|
import { useWebAnalytics } from "../hooks/use-web-analytics.mjs";
|
|
@@ -48,7 +49,7 @@ function Analytics({ integrations = [], facebookAppId, nonce, reportWebVitals =
|
|
|
48
49
|
property: "fb:app_id",
|
|
49
50
|
content: facebookAppId
|
|
50
51
|
}),
|
|
51
|
-
integrations
|
|
52
|
+
integrationScripts(integrations).map((script) => /* @__PURE__ */ jsx(Script, {
|
|
52
53
|
id: script.id,
|
|
53
54
|
nonce,
|
|
54
55
|
strategy: script.strategy ?? "afterInteractive",
|
package/dist/next/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { Suspense } from 'react';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useUETIdSync } from '../hooks/use-uet-id-sync';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { type AnalyticsProps, preconnectIntegrations } from '../third-parties/analytics-props';\nimport { uetCustomerIdOf } from '../third-parties/microsoft-uet';\nimport { track } from '../track/index';\n\n/**\n * Its own component under a Suspense boundary: `useSearchParams` in a statically rendered route\n * bails the whole tree out to client rendering unless something above it suspends, and Next\n * fails the build for a page that lets it. The boundary is here so a host does not have to know.\n */\nfunction PageViews() {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n useWebAnalytics(pathname, searchParams.toString());\n return null;\n}\n\nexport function Analytics({\n integrations = [],\n facebookAppId,\n nonce,\n reportWebVitals = true,\n}: AnalyticsProps) {\n useOutboundClickAnalytics();\n useUETIdSync(uetCustomerIdOf(integrations));\n preconnectIntegrations(integrations);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n value: metric.delta,\n metric_id: metric.id,\n metric_value: metric.value,\n metric_delta: metric.delta,\n metric_rating: metric.rating,\n metric_navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n <Suspense fallback={null}>\n <PageViews />\n </Suspense>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {integrations
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { Suspense } from 'react';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useUETIdSync } from '../hooks/use-uet-id-sync';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { type AnalyticsProps, preconnectIntegrations } from '../third-parties/analytics-props';\nimport { integrationScripts } from '../third-parties/integration';\nimport { uetCustomerIdOf } from '../third-parties/microsoft-uet';\nimport { track } from '../track/index';\n\n/**\n * Its own component under a Suspense boundary: `useSearchParams` in a statically rendered route\n * bails the whole tree out to client rendering unless something above it suspends, and Next\n * fails the build for a page that lets it. The boundary is here so a host does not have to know.\n */\nfunction PageViews() {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n useWebAnalytics(pathname, searchParams.toString());\n return null;\n}\n\nexport function Analytics({\n integrations = [],\n facebookAppId,\n nonce,\n reportWebVitals = true,\n}: AnalyticsProps) {\n useOutboundClickAnalytics();\n useUETIdSync(uetCustomerIdOf(integrations));\n preconnectIntegrations(integrations);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n value: metric.delta,\n metric_id: metric.id,\n metric_value: metric.value,\n metric_delta: metric.delta,\n metric_rating: metric.rating,\n metric_navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n <Suspense fallback={null}>\n <PageViews />\n </Suspense>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {integrationScripts(integrations).map((script) => (\n <Script\n key={script.id}\n id={script.id}\n nonce={nonce}\n strategy={script.strategy ?? 'afterInteractive'}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ))}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,SAAS,YAAY;CACnB,MAAM,WAAW,YAAY;CAC7B,MAAM,eAAe,gBAAgB;CACrC,gBAAgB,UAAU,aAAa,SAAS,CAAC;CACjD,OAAO;AACT;AAEA,SAAgB,UAAU,EACxB,eAAe,CAAC,GAChB,eACA,OACA,kBAAkB,QACD;CACjB,0BAA0B;CAC1B,aAAa,gBAAgB,YAAY,CAAC;CAC1C,uBAAuB,YAAY;CAEnC,oBAAoB,WAAW;EAC7B,IAAI,CAAC,iBAAiB;EACtB,MAAM,aAAa;GACjB,OAAO,OAAO;GACd,WAAW,OAAO;GAClB,cAAc,OAAO;GACrB,cAAc,OAAO;GACrB,eAAe,OAAO;GACtB,wBAAwB,OAAO;GAC/B,iBAAiB;EACnB;EACA,MAAM,OAAO,MAAM,UAAU;CAC/B,CAAC;CAED,OACE,qBAAA,UAAA,EAAA,UAAA;EACE,oBAAC,UAAD;GAAU,UAAU;GAClB,UAAA,oBAAC,WAAD,CAAY,CAAA;EACJ,CAAA;EACT,iBAAiB,oBAAC,QAAD;GAAM,UAAS;GAAY,SAAS;EAAgB,CAAA;EACrE,mBAAmB,YAAY,CAAC,CAAC,KAAK,WACrC,oBAAC,QAAD;GAEE,IAAI,OAAO;GACJ;GACP,UAAU,OAAO,YAAY;GAC7B,yBAAyB,EAAE,QAAQ,OAAO,OAAO;EAClD,GALM,OAAO,EAKb,CACF;CACD,EAAA,CAAA;AAEN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_third_parties_integration = require("./integration.cjs");
|
|
2
3
|
let react_dom = require("react-dom");
|
|
3
4
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
5
|
// src/third-parties/analytics-props.tsx
|
|
@@ -16,7 +17,7 @@ function preconnectIntegrations(integrations = []) {
|
|
|
16
17
|
* they are (react).
|
|
17
18
|
*/
|
|
18
19
|
function IntegrationScripts({ integrations = [], nonce }) {
|
|
19
|
-
return
|
|
20
|
+
return require_third_parties_integration.integrationScripts(integrations).map((script) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
20
21
|
id: script.id,
|
|
21
22
|
nonce,
|
|
22
23
|
dangerouslySetInnerHTML: { __html: script.inline }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics-props.cjs","names":["preconnect"],"sources":["../../src/third-parties/analytics-props.tsx"],"sourcesContent":["import { preconnect } from 'react-dom';\nimport type
|
|
1
|
+
{"version":3,"file":"analytics-props.cjs","names":["preconnect","integrationScripts"],"sources":["../../src/third-parties/analytics-props.tsx"],"sourcesContent":["import { preconnect } from 'react-dom';\nimport { type Integration, integrationScripts } from './integration';\n\n/** The props every framework's `<Analytics>` takes (react, next). */\nexport interface AnalyticsProps {\n /** The integrations passed to `setupAnalytics`, whose scripts this renders. */\n integrations?: readonly Integration[];\n /** Renders `<meta property=\"fb:app_id\">`, for Facebook's sharing insights. */\n facebookAppId?: string;\n /** The request's CSP nonce, set on every script rendered. */\n nonce?: string;\n /** Reports Core Web Vitals as events (on by default). */\n reportWebVitals?: boolean;\n}\n\n/**\n * Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes\n * the hints and, on the server, puts them at the top of `<head>`.\n */\nexport function preconnectIntegrations(integrations: readonly Integration[] = []) {\n integrations.forEach((integration) => {\n integration.preconnect?.forEach((origin) => preconnect(origin, { crossOrigin: 'anonymous' }));\n });\n}\n\n/**\n * The integrations' scripts as plain `<script>` elements, for the frameworks that render them as\n * they are (react).\n */\nexport function IntegrationScripts({\n integrations = [],\n nonce,\n}: Pick<AnalyticsProps, 'integrations' | 'nonce'>) {\n return integrationScripts(integrations).map((script) => (\n <script\n key={script.id}\n id={script.id}\n nonce={nonce}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ));\n}\n"],"mappings":";;;;;;;;;AAmBA,SAAgB,uBAAuB,eAAuC,CAAC,GAAG;CAChF,aAAa,SAAS,gBAAgB;EACpC,YAAY,YAAY,SAAS,YAAA,GAAWA,UAAAA,WAAAA,CAAW,QAAQ,EAAE,aAAa,YAAY,CAAC,CAAC;CAC9F,CAAC;AACH;;;;;AAMA,SAAgB,mBAAmB,EACjC,eAAe,CAAC,GAChB,SACiD;CACjD,OAAOC,kCAAAA,mBAAmB,YAAY,CAAC,CAAC,KAAK,WAC3C,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;EAEE,IAAI,OAAO;EACJ;EACP,yBAAyB,EAAE,QAAQ,OAAO,OAAO;CAClD,GAJM,OAAO,EAIb,CACF;AACH"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { integrationScripts } from "./integration.mjs";
|
|
1
2
|
import { preconnect } from "react-dom";
|
|
2
3
|
import { jsx } from "react/jsx-runtime";
|
|
3
4
|
// src/third-parties/analytics-props.tsx
|
|
@@ -15,7 +16,7 @@ function preconnectIntegrations(integrations = []) {
|
|
|
15
16
|
* they are (react).
|
|
16
17
|
*/
|
|
17
18
|
function IntegrationScripts({ integrations = [], nonce }) {
|
|
18
|
-
return integrations
|
|
19
|
+
return integrationScripts(integrations).map((script) => /* @__PURE__ */ jsx("script", {
|
|
19
20
|
id: script.id,
|
|
20
21
|
nonce,
|
|
21
22
|
dangerouslySetInnerHTML: { __html: script.inline }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics-props.mjs","names":[],"sources":["../../src/third-parties/analytics-props.tsx"],"sourcesContent":["import { preconnect } from 'react-dom';\nimport type
|
|
1
|
+
{"version":3,"file":"analytics-props.mjs","names":[],"sources":["../../src/third-parties/analytics-props.tsx"],"sourcesContent":["import { preconnect } from 'react-dom';\nimport { type Integration, integrationScripts } from './integration';\n\n/** The props every framework's `<Analytics>` takes (react, next). */\nexport interface AnalyticsProps {\n /** The integrations passed to `setupAnalytics`, whose scripts this renders. */\n integrations?: readonly Integration[];\n /** Renders `<meta property=\"fb:app_id\">`, for Facebook's sharing insights. */\n facebookAppId?: string;\n /** The request's CSP nonce, set on every script rendered. */\n nonce?: string;\n /** Reports Core Web Vitals as events (on by default). */\n reportWebVitals?: boolean;\n}\n\n/**\n * Preconnects to every integration's `preconnect` origins. Called while rendering: React dedupes\n * the hints and, on the server, puts them at the top of `<head>`.\n */\nexport function preconnectIntegrations(integrations: readonly Integration[] = []) {\n integrations.forEach((integration) => {\n integration.preconnect?.forEach((origin) => preconnect(origin, { crossOrigin: 'anonymous' }));\n });\n}\n\n/**\n * The integrations' scripts as plain `<script>` elements, for the frameworks that render them as\n * they are (react).\n */\nexport function IntegrationScripts({\n integrations = [],\n nonce,\n}: Pick<AnalyticsProps, 'integrations' | 'nonce'>) {\n return integrationScripts(integrations).map((script) => (\n <script\n key={script.id}\n id={script.id}\n nonce={nonce}\n dangerouslySetInnerHTML={{ __html: script.inline }}\n />\n ));\n}\n"],"mappings":";;;;;;;;AAmBA,SAAgB,uBAAuB,eAAuC,CAAC,GAAG;CAChF,aAAa,SAAS,gBAAgB;EACpC,YAAY,YAAY,SAAS,WAAW,WAAW,QAAQ,EAAE,aAAa,YAAY,CAAC,CAAC;CAC9F,CAAC;AACH;;;;;AAMA,SAAgB,mBAAmB,EACjC,eAAe,CAAC,GAChB,SACiD;CACjD,OAAO,mBAAmB,YAAY,CAAC,CAAC,KAAK,WAC3C,oBAAC,UAAD;EAEE,IAAI,OAAO;EACJ;EACP,yBAAyB,EAAE,QAAQ,OAAO,OAAO;CAClD,GAJM,OAAO,EAIb,CACF;AACH"}
|
|
@@ -13,6 +13,7 @@ exports.configureUET = require_third_parties_microsoft_uet.configureUET;
|
|
|
13
13
|
exports.getLoadedPosthog = require_third_parties_posthog.getLoadedPosthog;
|
|
14
14
|
exports.getPosthog = require_third_parties_posthog.getPosthog;
|
|
15
15
|
exports.googleAnalytics = require_third_parties_google_analytics.googleAnalytics;
|
|
16
|
+
exports.isLocalHost = require_third_parties_integration.isLocalHost;
|
|
16
17
|
exports.linkedInAds = require_third_parties_linkedin_insight_tag.linkedInAds;
|
|
17
18
|
exports.metaAds = require_third_parties_meta_pixel.metaAds;
|
|
18
19
|
exports.microsoftAds = require_third_parties_microsoft_uet.microsoftAds;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdsOptions, CONVERSION_EVENTS, Integration, IntegrationScript } from "./integration.cjs";
|
|
1
|
+
import { AdsOptions, CONVERSION_EVENTS, Integration, IntegrationScript, isLocalHost } from "./integration.cjs";
|
|
2
2
|
import { metaAds, sendFBEvent, setFBUser } from "./meta-pixel.cjs";
|
|
3
3
|
import { redditAds, sendRedditEvent, setRedditUser } from "./reddit-pixel.cjs";
|
|
4
4
|
import { LinkedinConversionConfig, linkedInAds, sendLinkedinEvent, setLinkedinUser } from "./linkedin-insight-tag.cjs";
|
|
@@ -7,4 +7,4 @@ import { UETConsent, UETEventParams, UETItem, UETPageType, UETPid } from "../tra
|
|
|
7
7
|
import { MicrosoftAdsIntegration, configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf } from "./microsoft-uet.cjs";
|
|
8
8
|
import { googleAnalytics, sendGAEvent, setGAUser } from "./google-analytics.cjs";
|
|
9
9
|
import { ErrorPattern, PostHog, PostHogConfig, PosthogErrorTrackingOptions, capturePosthogException, getLoadedPosthog, getPosthog, posthogAnalytics, posthogFlagsReady, sendPosthogEvent, setPosthogUser } from "./posthog.cjs";
|
|
10
|
-
export { type AdsOptions, CONVERSION_EVENTS, type ErrorPattern, type Integration, type IntegrationScript, type LinkedinConversionConfig, type MicrosoftAdsIntegration, type PostHog, type PostHogConfig, type PosthogErrorTrackingOptions, type UETConsent, type UETEventParams, type UETItem, type UETPageType, type UETPid, capturePosthogException, configureUET, getLoadedPosthog, getPosthog, googleAnalytics, linkedInAds, metaAds, microsoftAds, openaiAds, posthogAnalytics, posthogFlagsReady, redditAds, sendFBEvent, sendGAEvent, sendLinkedinEvent, sendOpenAIEvent, sendPosthogEvent, sendRedditEvent, sendUETEvent, sendUETIdSync, setFBUser, setGAUser, setLinkedinUser, setOpenAIUser, setPosthogUser, setRedditUser, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
|
|
10
|
+
export { type AdsOptions, CONVERSION_EVENTS, type ErrorPattern, type Integration, type IntegrationScript, type LinkedinConversionConfig, type MicrosoftAdsIntegration, type PostHog, type PostHogConfig, type PosthogErrorTrackingOptions, type UETConsent, type UETEventParams, type UETItem, type UETPageType, type UETPid, capturePosthogException, configureUET, getLoadedPosthog, getPosthog, googleAnalytics, isLocalHost, linkedInAds, metaAds, microsoftAds, openaiAds, posthogAnalytics, posthogFlagsReady, redditAds, sendFBEvent, sendGAEvent, sendLinkedinEvent, sendOpenAIEvent, sendPosthogEvent, sendRedditEvent, sendUETEvent, sendUETIdSync, setFBUser, setGAUser, setLinkedinUser, setOpenAIUser, setPosthogUser, setRedditUser, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdsOptions, CONVERSION_EVENTS, Integration, IntegrationScript } from "./integration.mjs";
|
|
1
|
+
import { AdsOptions, CONVERSION_EVENTS, Integration, IntegrationScript, isLocalHost } from "./integration.mjs";
|
|
2
2
|
import { metaAds, sendFBEvent, setFBUser } from "./meta-pixel.mjs";
|
|
3
3
|
import { redditAds, sendRedditEvent, setRedditUser } from "./reddit-pixel.mjs";
|
|
4
4
|
import { LinkedinConversionConfig, linkedInAds, sendLinkedinEvent, setLinkedinUser } from "./linkedin-insight-tag.mjs";
|
|
@@ -7,4 +7,4 @@ import { UETConsent, UETEventParams, UETItem, UETPageType, UETPid } from "../tra
|
|
|
7
7
|
import { MicrosoftAdsIntegration, configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf } from "./microsoft-uet.mjs";
|
|
8
8
|
import { googleAnalytics, sendGAEvent, setGAUser } from "./google-analytics.mjs";
|
|
9
9
|
import { ErrorPattern, PostHog, PostHogConfig, PosthogErrorTrackingOptions, capturePosthogException, getLoadedPosthog, getPosthog, posthogAnalytics, posthogFlagsReady, sendPosthogEvent, setPosthogUser } from "./posthog.mjs";
|
|
10
|
-
export { type AdsOptions, CONVERSION_EVENTS, type ErrorPattern, type Integration, type IntegrationScript, type LinkedinConversionConfig, type MicrosoftAdsIntegration, type PostHog, type PostHogConfig, type PosthogErrorTrackingOptions, type UETConsent, type UETEventParams, type UETItem, type UETPageType, type UETPid, capturePosthogException, configureUET, getLoadedPosthog, getPosthog, googleAnalytics, linkedInAds, metaAds, microsoftAds, openaiAds, posthogAnalytics, posthogFlagsReady, redditAds, sendFBEvent, sendGAEvent, sendLinkedinEvent, sendOpenAIEvent, sendPosthogEvent, sendRedditEvent, sendUETEvent, sendUETIdSync, setFBUser, setGAUser, setLinkedinUser, setOpenAIUser, setPosthogUser, setRedditUser, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
|
|
10
|
+
export { type AdsOptions, CONVERSION_EVENTS, type ErrorPattern, type Integration, type IntegrationScript, type LinkedinConversionConfig, type MicrosoftAdsIntegration, type PostHog, type PostHogConfig, type PosthogErrorTrackingOptions, type UETConsent, type UETEventParams, type UETItem, type UETPageType, type UETPid, capturePosthogException, configureUET, getLoadedPosthog, getPosthog, googleAnalytics, isLocalHost, linkedInAds, metaAds, microsoftAds, openaiAds, posthogAnalytics, posthogFlagsReady, redditAds, sendFBEvent, sendGAEvent, sendLinkedinEvent, sendOpenAIEvent, sendPosthogEvent, sendRedditEvent, sendUETEvent, sendUETIdSync, setFBUser, setGAUser, setLinkedinUser, setOpenAIUser, setPosthogUser, setRedditUser, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONVERSION_EVENTS } from "./integration.mjs";
|
|
1
|
+
import { CONVERSION_EVENTS, isLocalHost } from "./integration.mjs";
|
|
2
2
|
import { configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf } from "./microsoft-uet.mjs";
|
|
3
3
|
import { capturePosthogException, getLoadedPosthog, getPosthog, posthogAnalytics, posthogFlagsReady, sendPosthogEvent, setPosthogUser } from "./posthog.mjs";
|
|
4
4
|
import { googleAnalytics, sendGAEvent, setGAUser } from "./google-analytics.mjs";
|
|
@@ -6,4 +6,4 @@ import { metaAds, sendFBEvent, setFBUser } from "./meta-pixel.mjs";
|
|
|
6
6
|
import { linkedInAds, sendLinkedinEvent, setLinkedinUser } from "./linkedin-insight-tag.mjs";
|
|
7
7
|
import { openaiAds, sendOpenAIEvent, setOpenAIUser } from "./openai-pixel.mjs";
|
|
8
8
|
import { redditAds, sendRedditEvent, setRedditUser } from "./reddit-pixel.mjs";
|
|
9
|
-
export { CONVERSION_EVENTS, capturePosthogException, configureUET, getLoadedPosthog, getPosthog, googleAnalytics, linkedInAds, metaAds, microsoftAds, openaiAds, posthogAnalytics, posthogFlagsReady, redditAds, sendFBEvent, sendGAEvent, sendLinkedinEvent, sendOpenAIEvent, sendPosthogEvent, sendRedditEvent, sendUETEvent, sendUETIdSync, setFBUser, setGAUser, setLinkedinUser, setOpenAIUser, setPosthogUser, setRedditUser, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
|
|
9
|
+
export { CONVERSION_EVENTS, capturePosthogException, configureUET, getLoadedPosthog, getPosthog, googleAnalytics, isLocalHost, linkedInAds, metaAds, microsoftAds, openaiAds, posthogAnalytics, posthogFlagsReady, redditAds, sendFBEvent, sendGAEvent, sendLinkedinEvent, sendOpenAIEvent, sendPosthogEvent, sendRedditEvent, sendUETEvent, sendUETIdSync, setFBUser, setGAUser, setLinkedinUser, setOpenAIUser, setPosthogUser, setRedditUser, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
|
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
// src/third-parties/integration.ts
|
|
3
3
|
/**
|
|
4
|
+
* A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under
|
|
5
|
+
* portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One
|
|
6
|
+
* pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.
|
|
7
|
+
*/
|
|
8
|
+
const LOCAL_HOST_PATTERN = String.raw`(^|\.)localhost(:|$)|^127\.0\.0\.1(:|$)`;
|
|
9
|
+
const LOCAL_HOST = new RegExp(LOCAL_HOST_PATTERN);
|
|
10
|
+
/** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */
|
|
11
|
+
function isLocalHost(host = window.location.host) {
|
|
12
|
+
return LOCAL_HOST.test(host);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The script an ad platform's integration puts on the page, silenced on a development host.
|
|
16
|
+
* Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,
|
|
17
|
+
* `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so
|
|
18
|
+
* a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The
|
|
19
|
+
* guard is in the snippet itself: the renderer has no request host on the server.
|
|
20
|
+
*/
|
|
21
|
+
function integrationScripts(integrations) {
|
|
22
|
+
return integrations.flatMap(({ type, script }) => {
|
|
23
|
+
if (!script) return [];
|
|
24
|
+
if (type !== "ads") return [script];
|
|
25
|
+
return [{
|
|
26
|
+
...script,
|
|
27
|
+
inline: `if (!/${LOCAL_HOST_PATTERN}/.test(window.location.host)) {${script.inline}}`
|
|
28
|
+
}];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
4
32
|
* The GA4 recommended events that are conversions or close to one, for an ad platform with no
|
|
5
33
|
* standard events of its own to map to (Microsoft UET), so it is not sent the whole product.
|
|
6
34
|
*/
|
|
@@ -40,7 +68,10 @@ function adsTracker(send, accepts) {
|
|
|
40
68
|
};
|
|
41
69
|
}
|
|
42
70
|
exports.CONVERSION_EVENTS = CONVERSION_EVENTS;
|
|
71
|
+
exports.LOCAL_HOST_PATTERN = LOCAL_HOST_PATTERN;
|
|
43
72
|
exports.adEvents = adEvents;
|
|
44
73
|
exports.adsTracker = adsTracker;
|
|
74
|
+
exports.integrationScripts = integrationScripts;
|
|
75
|
+
exports.isLocalHost = isLocalHost;
|
|
45
76
|
|
|
46
77
|
//# sourceMappingURL=integration.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.cjs","names":[],"sources":["../../src/third-parties/integration.ts"],"sourcesContent":["import type { EventName, ThirdPartyTracker, TrackName } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\n/**\n * The one script an integration puts on the page, rendered by `<Analytics integrations>`\n * (react, next) with the request's `nonce`: an inline snippet that loads the\n * vendor's own script from its host, as every vendor's official snippet does.\n */\nexport interface IntegrationScript {\n /**\n * The element id; also its React key, and how a test or a CSP report finds it. Never a global's\n * name: an element's id is readable as `window[id]` until a script defines it, so an id like\n * `posthog` hands the snippet's `window.posthog || []` the <script> element. Keep a hyphen in it.\n */\n readonly id: string;\n readonly inline: string;\n /** `next/script`'s loading strategy, `afterInteractive` by default; the other frameworks ignore it. */\n readonly strategy?: 'beforeInteractive' | 'afterInteractive' | 'lazyOnload';\n}\n\n/**\n * One third party, configured in one place: how events reach it, how it learns the signed-in\n * user, and the script it needs. Built by the factories in `@shware/analytics/third-parties`\n * (`googleAnalytics`, `metaAds`, …) and handed to both `setupAnalytics({ integrations })` and\n * `<Analytics integrations>`. A host can write its own for a platform the SDK does not cover.\n *\n * `type` says what the platform is for. An `analytics` integration (GA4, PostHog) receives every\n * event, for behavior analysis. An `ads` integration receives only what helps an ad platform\n * optimize and build audiences — the conversion events it maps to its own standard events, plus\n * the custom events it was explicitly given — and filters in its own `track`.\n */\nexport interface Integration {\n readonly type: 'analytics' | 'ads';\n readonly track: ThirdPartyTracker;\n readonly setUser?: ThirdPartyUserSetter;\n readonly script?: IntegrationScript;\n /**\n * Origins `<Analytics>` preconnects to (`react-dom`'s `preconnect`), so the connection is up\n * before the script asks for something there — e.g. where a snippet loads its library from.\n */\n readonly preconnect?: readonly string[];\n}\n\n/**\n * The GA4 recommended events that are conversions or close to one, for an ad platform with no\n * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.\n */\nexport const CONVERSION_EVENTS = [\n 'sign_up',\n 'login',\n 'generate_lead',\n 'view_item',\n 'add_to_cart',\n 'add_to_wishlist',\n 'begin_checkout',\n 'add_payment_info',\n 'purchase',\n 'subscribe',\n 'trial_begin',\n 'search',\n 'schedule',\n 'submit_application',\n 'contact',\n] as const satisfies readonly EventName[];\n\nexport interface AdsOptions {\n /**\n * Custom events this platform receives besides the conversions it maps to its standard\n * events, e.g. one used as an optimization goal or for an audience. Everything else is not\n * sent to it. The names `track` accepts, so with strict event names a typo is a compile error.\n */\n customEvents?: readonly TrackName[];\n}\n\n/**\n * Which events an ad platform receives: what `isStandard` accepts — the events its mapper turns\n * into one of its standard events — and the custom events the host listed. Everything else in the\n * product (feature use, clicks, onboarding steps) is behavior analysis, which is GA4's and\n * PostHog's job, and only noise to an ad platform's optimization. The same rule picks what the\n * browser tag and the platform's conversions API send (`@shware/analytics/server`), so the two\n * report the same events.\n */\nexport function adEvents(\n isStandard: (name: string) => boolean,\n customEvents: readonly string[] = []\n): (name: string) => boolean {\n return (name) => isStandard(name) || customEvents.includes(name);\n}\n\n/** An ad tracker that sends only the events `accepts` lets through (`adEvents`). */\nexport function adsTracker(\n send: ThirdPartyTracker,\n accepts: (name: string) => boolean\n): ThirdPartyTracker {\n return (name, properties, eventId) => {\n if (!accepts(name)) return;\n return send(name, properties, eventId);\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"integration.cjs","names":[],"sources":["../../src/third-parties/integration.ts"],"sourcesContent":["import type { EventName, ThirdPartyTracker, TrackName } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\n/**\n * The one script an integration puts on the page, rendered by `<Analytics integrations>`\n * (react, next) with the request's `nonce`: an inline snippet that loads the\n * vendor's own script from its host, as every vendor's official snippet does.\n */\nexport interface IntegrationScript {\n /**\n * The element id; also its React key, and how a test or a CSP report finds it. Never a global's\n * name: an element's id is readable as `window[id]` until a script defines it, so an id like\n * `posthog` hands the snippet's `window.posthog || []` the <script> element. Keep a hyphen in it.\n */\n readonly id: string;\n readonly inline: string;\n /** `next/script`'s loading strategy, `afterInteractive` by default; the other frameworks ignore it. */\n readonly strategy?: 'beforeInteractive' | 'afterInteractive' | 'lazyOnload';\n}\n\n/**\n * One third party, configured in one place: how events reach it, how it learns the signed-in\n * user, and the script it needs. Built by the factories in `@shware/analytics/third-parties`\n * (`googleAnalytics`, `metaAds`, …) and handed to both `setupAnalytics({ integrations })` and\n * `<Analytics integrations>`. A host can write its own for a platform the SDK does not cover.\n *\n * `type` says what the platform is for. An `analytics` integration (GA4, PostHog) receives every\n * event, for behavior analysis. An `ads` integration receives only what helps an ad platform\n * optimize and build audiences — the conversion events it maps to its own standard events, plus\n * the custom events it was explicitly given — and filters in its own `track`.\n */\nexport interface Integration {\n readonly type: 'analytics' | 'ads';\n readonly track: ThirdPartyTracker;\n readonly setUser?: ThirdPartyUserSetter;\n readonly script?: IntegrationScript;\n /**\n * Origins `<Analytics>` preconnects to (`react-dom`'s `preconnect`), so the connection is up\n * before the script asks for something there — e.g. where a snippet loads its library from.\n */\n readonly preconnect?: readonly string[];\n}\n\n/**\n * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under\n * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One\n * pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.\n */\nexport const LOCAL_HOST_PATTERN = String.raw`(^|\\.)localhost(:|$)|^127\\.0\\.0\\.1(:|$)`;\nconst LOCAL_HOST = new RegExp(LOCAL_HOST_PATTERN);\n\n/** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */\nexport function isLocalHost(host: string = window.location.host): boolean {\n return LOCAL_HOST.test(host);\n}\n\n/**\n * The script an ad platform's integration puts on the page, silenced on a development host.\n * Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,\n * `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so\n * a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The\n * guard is in the snippet itself: the renderer has no request host on the server.\n */\nexport function integrationScripts(integrations: readonly Integration[]): IntegrationScript[] {\n return integrations.flatMap(({ type, script }) => {\n if (!script) return [];\n if (type !== 'ads') return [script];\n return [\n {\n ...script,\n inline: `if (!/${LOCAL_HOST_PATTERN}/.test(window.location.host)) {${script.inline}}`,\n },\n ];\n });\n}\n\n/**\n * The GA4 recommended events that are conversions or close to one, for an ad platform with no\n * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.\n */\nexport const CONVERSION_EVENTS = [\n 'sign_up',\n 'login',\n 'generate_lead',\n 'view_item',\n 'add_to_cart',\n 'add_to_wishlist',\n 'begin_checkout',\n 'add_payment_info',\n 'purchase',\n 'subscribe',\n 'trial_begin',\n 'search',\n 'schedule',\n 'submit_application',\n 'contact',\n] as const satisfies readonly EventName[];\n\nexport interface AdsOptions {\n /**\n * Custom events this platform receives besides the conversions it maps to its standard\n * events, e.g. one used as an optimization goal or for an audience. Everything else is not\n * sent to it. The names `track` accepts, so with strict event names a typo is a compile error.\n */\n customEvents?: readonly TrackName[];\n}\n\n/**\n * Which events an ad platform receives: what `isStandard` accepts — the events its mapper turns\n * into one of its standard events — and the custom events the host listed. Everything else in the\n * product (feature use, clicks, onboarding steps) is behavior analysis, which is GA4's and\n * PostHog's job, and only noise to an ad platform's optimization. The same rule picks what the\n * browser tag and the platform's conversions API send (`@shware/analytics/server`), so the two\n * report the same events.\n */\nexport function adEvents(\n isStandard: (name: string) => boolean,\n customEvents: readonly string[] = []\n): (name: string) => boolean {\n return (name) => isStandard(name) || customEvents.includes(name);\n}\n\n/** An ad tracker that sends only the events `accepts` lets through (`adEvents`). */\nexport function adsTracker(\n send: ThirdPartyTracker,\n accepts: (name: string) => boolean\n): ThirdPartyTracker {\n return (name, properties, eventId) => {\n if (!accepts(name)) return;\n return send(name, properties, eventId);\n };\n}\n"],"mappings":";;;;;;;AAgDA,MAAa,qBAAqB,OAAO,GAAG;AAC5C,MAAM,aAAa,IAAI,OAAO,kBAAkB;;AAGhD,SAAgB,YAAY,OAAe,OAAO,SAAS,MAAe;CACxE,OAAO,WAAW,KAAK,IAAI;AAC7B;;;;;;;;AASA,SAAgB,mBAAmB,cAA2D;CAC5F,OAAO,aAAa,SAAS,EAAE,MAAM,aAAa;EAChD,IAAI,CAAC,QAAQ,OAAO,CAAC;EACrB,IAAI,SAAS,OAAO,OAAO,CAAC,MAAM;EAClC,OAAO,CACL;GACE,GAAG;GACH,QAAQ,SAAS,mBAAmB,iCAAiC,OAAO,OAAO;EACrF,CACF;CACF,CAAC;AACH;;;;;AAMA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;AAmBA,SAAgB,SACd,YACA,eAAkC,CAAC,GACR;CAC3B,QAAQ,SAAS,WAAW,IAAI,KAAK,aAAa,SAAS,IAAI;AACjE;;AAGA,SAAgB,WACd,MACA,SACmB;CACnB,QAAQ,MAAM,YAAY,YAAY;EACpC,IAAI,CAAC,QAAQ,IAAI,GAAG;EACpB,OAAO,KAAK,MAAM,YAAY,OAAO;CACvC;AACF"}
|
|
@@ -38,6 +38,22 @@ export interface Integration {
|
|
|
38
38
|
*/
|
|
39
39
|
readonly preconnect?: readonly string[];
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under
|
|
43
|
+
* portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One
|
|
44
|
+
* pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.
|
|
45
|
+
*/
|
|
46
|
+
export declare const LOCAL_HOST_PATTERN: string;
|
|
47
|
+
/** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */
|
|
48
|
+
export declare function isLocalHost(host?: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The script an ad platform's integration puts on the page, silenced on a development host.
|
|
51
|
+
* Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,
|
|
52
|
+
* `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so
|
|
53
|
+
* a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The
|
|
54
|
+
* guard is in the snippet itself: the renderer has no request host on the server.
|
|
55
|
+
*/
|
|
56
|
+
export declare function integrationScripts(integrations: readonly Integration[]): IntegrationScript[];
|
|
41
57
|
/**
|
|
42
58
|
* The GA4 recommended events that are conversions or close to one, for an ad platform with no
|
|
43
59
|
* standard events of its own to map to (Microsoft UET), so it is not sent the whole product.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.cts","names":[],"sources":["../../src/third-parties/integration.ts"],"mappings":";;;;;;;iBAQiB;;;;;;WAMN;WACA;;WAEA;;;;;;;;;;;;;iBAcM;WACN;WACA,OAAO;WACP,UAAU;WACV,SAAS;;;;;WAKT
|
|
1
|
+
{"version":3,"file":"integration.d.cts","names":[],"sources":["../../src/third-parties/integration.ts"],"mappings":";;;;;;;iBAQiB;;;;;;WAMN;WACA;;WAEA;;;;;;;;;;;;;iBAcM;WACN;WACA,OAAO;WACP,UAAU;WACV,SAAS;;;;;WAKT;;;;;;;qBAQE;;wBAIG,YAAY;;;;;;;;wBAWZ,mBAAmB,uBAAuB,gBAAgB;;;;;qBAiB7D;iBAkBI;;;;;;EAMf,wBAAwB;;;;;;;;;;wBAWV,SACd,aAAa,0BACb,oCACE;;wBAKY,WACd,MAAM,mBACN,UAAU,2BACT"}
|
|
@@ -38,6 +38,22 @@ export interface Integration {
|
|
|
38
38
|
*/
|
|
39
39
|
readonly preconnect?: readonly string[];
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under
|
|
43
|
+
* portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One
|
|
44
|
+
* pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.
|
|
45
|
+
*/
|
|
46
|
+
export declare const LOCAL_HOST_PATTERN: string;
|
|
47
|
+
/** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */
|
|
48
|
+
export declare function isLocalHost(host?: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The script an ad platform's integration puts on the page, silenced on a development host.
|
|
51
|
+
* Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,
|
|
52
|
+
* `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so
|
|
53
|
+
* a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The
|
|
54
|
+
* guard is in the snippet itself: the renderer has no request host on the server.
|
|
55
|
+
*/
|
|
56
|
+
export declare function integrationScripts(integrations: readonly Integration[]): IntegrationScript[];
|
|
41
57
|
/**
|
|
42
58
|
* The GA4 recommended events that are conversions or close to one, for an ad platform with no
|
|
43
59
|
* standard events of its own to map to (Microsoft UET), so it is not sent the whole product.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.mts","names":[],"sources":["../../src/third-parties/integration.ts"],"mappings":";;;;;;;iBAQiB;;;;;;WAMN;WACA;;WAEA;;;;;;;;;;;;;iBAcM;WACN;WACA,OAAO;WACP,UAAU;WACV,SAAS;;;;;WAKT
|
|
1
|
+
{"version":3,"file":"integration.d.mts","names":[],"sources":["../../src/third-parties/integration.ts"],"mappings":";;;;;;;iBAQiB;;;;;;WAMN;WACA;;WAEA;;;;;;;;;;;;;iBAcM;WACN;WACA,OAAO;WACP,UAAU;WACV,SAAS;;;;;WAKT;;;;;;;qBAQE;;wBAIG,YAAY;;;;;;;;wBAWZ,mBAAmB,uBAAuB,gBAAgB;;;;;qBAiB7D;iBAkBI;;;;;;EAMf,wBAAwB;;;;;;;;;;wBAWV,SACd,aAAa,0BACb,oCACE;;wBAKY,WACd,MAAM,mBACN,UAAU,2BACT"}
|
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
// src/third-parties/integration.ts
|
|
2
2
|
/**
|
|
3
|
+
* A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under
|
|
4
|
+
* portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One
|
|
5
|
+
* pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.
|
|
6
|
+
*/
|
|
7
|
+
const LOCAL_HOST_PATTERN = String.raw`(^|\.)localhost(:|$)|^127\.0\.0\.1(:|$)`;
|
|
8
|
+
const LOCAL_HOST = new RegExp(LOCAL_HOST_PATTERN);
|
|
9
|
+
/** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */
|
|
10
|
+
function isLocalHost(host = window.location.host) {
|
|
11
|
+
return LOCAL_HOST.test(host);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The script an ad platform's integration puts on the page, silenced on a development host.
|
|
15
|
+
* Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,
|
|
16
|
+
* `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so
|
|
17
|
+
* a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The
|
|
18
|
+
* guard is in the snippet itself: the renderer has no request host on the server.
|
|
19
|
+
*/
|
|
20
|
+
function integrationScripts(integrations) {
|
|
21
|
+
return integrations.flatMap(({ type, script }) => {
|
|
22
|
+
if (!script) return [];
|
|
23
|
+
if (type !== "ads") return [script];
|
|
24
|
+
return [{
|
|
25
|
+
...script,
|
|
26
|
+
inline: `if (!/${LOCAL_HOST_PATTERN}/.test(window.location.host)) {${script.inline}}`
|
|
27
|
+
}];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
3
31
|
* The GA4 recommended events that are conversions or close to one, for an ad platform with no
|
|
4
32
|
* standard events of its own to map to (Microsoft UET), so it is not sent the whole product.
|
|
5
33
|
*/
|
|
@@ -38,6 +66,6 @@ function adsTracker(send, accepts) {
|
|
|
38
66
|
return send(name, properties, eventId);
|
|
39
67
|
};
|
|
40
68
|
}
|
|
41
|
-
export { CONVERSION_EVENTS, adEvents, adsTracker };
|
|
69
|
+
export { CONVERSION_EVENTS, LOCAL_HOST_PATTERN, adEvents, adsTracker, integrationScripts, isLocalHost };
|
|
42
70
|
|
|
43
71
|
//# sourceMappingURL=integration.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.mjs","names":[],"sources":["../../src/third-parties/integration.ts"],"sourcesContent":["import type { EventName, ThirdPartyTracker, TrackName } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\n/**\n * The one script an integration puts on the page, rendered by `<Analytics integrations>`\n * (react, next) with the request's `nonce`: an inline snippet that loads the\n * vendor's own script from its host, as every vendor's official snippet does.\n */\nexport interface IntegrationScript {\n /**\n * The element id; also its React key, and how a test or a CSP report finds it. Never a global's\n * name: an element's id is readable as `window[id]` until a script defines it, so an id like\n * `posthog` hands the snippet's `window.posthog || []` the <script> element. Keep a hyphen in it.\n */\n readonly id: string;\n readonly inline: string;\n /** `next/script`'s loading strategy, `afterInteractive` by default; the other frameworks ignore it. */\n readonly strategy?: 'beforeInteractive' | 'afterInteractive' | 'lazyOnload';\n}\n\n/**\n * One third party, configured in one place: how events reach it, how it learns the signed-in\n * user, and the script it needs. Built by the factories in `@shware/analytics/third-parties`\n * (`googleAnalytics`, `metaAds`, …) and handed to both `setupAnalytics({ integrations })` and\n * `<Analytics integrations>`. A host can write its own for a platform the SDK does not cover.\n *\n * `type` says what the platform is for. An `analytics` integration (GA4, PostHog) receives every\n * event, for behavior analysis. An `ads` integration receives only what helps an ad platform\n * optimize and build audiences — the conversion events it maps to its own standard events, plus\n * the custom events it was explicitly given — and filters in its own `track`.\n */\nexport interface Integration {\n readonly type: 'analytics' | 'ads';\n readonly track: ThirdPartyTracker;\n readonly setUser?: ThirdPartyUserSetter;\n readonly script?: IntegrationScript;\n /**\n * Origins `<Analytics>` preconnects to (`react-dom`'s `preconnect`), so the connection is up\n * before the script asks for something there — e.g. where a snippet loads its library from.\n */\n readonly preconnect?: readonly string[];\n}\n\n/**\n * The GA4 recommended events that are conversions or close to one, for an ad platform with no\n * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.\n */\nexport const CONVERSION_EVENTS = [\n 'sign_up',\n 'login',\n 'generate_lead',\n 'view_item',\n 'add_to_cart',\n 'add_to_wishlist',\n 'begin_checkout',\n 'add_payment_info',\n 'purchase',\n 'subscribe',\n 'trial_begin',\n 'search',\n 'schedule',\n 'submit_application',\n 'contact',\n] as const satisfies readonly EventName[];\n\nexport interface AdsOptions {\n /**\n * Custom events this platform receives besides the conversions it maps to its standard\n * events, e.g. one used as an optimization goal or for an audience. Everything else is not\n * sent to it. The names `track` accepts, so with strict event names a typo is a compile error.\n */\n customEvents?: readonly TrackName[];\n}\n\n/**\n * Which events an ad platform receives: what `isStandard` accepts — the events its mapper turns\n * into one of its standard events — and the custom events the host listed. Everything else in the\n * product (feature use, clicks, onboarding steps) is behavior analysis, which is GA4's and\n * PostHog's job, and only noise to an ad platform's optimization. The same rule picks what the\n * browser tag and the platform's conversions API send (`@shware/analytics/server`), so the two\n * report the same events.\n */\nexport function adEvents(\n isStandard: (name: string) => boolean,\n customEvents: readonly string[] = []\n): (name: string) => boolean {\n return (name) => isStandard(name) || customEvents.includes(name);\n}\n\n/** An ad tracker that sends only the events `accepts` lets through (`adEvents`). */\nexport function adsTracker(\n send: ThirdPartyTracker,\n accepts: (name: string) => boolean\n): ThirdPartyTracker {\n return (name, properties, eventId) => {\n if (!accepts(name)) return;\n return send(name, properties, eventId);\n };\n}\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"integration.mjs","names":[],"sources":["../../src/third-parties/integration.ts"],"sourcesContent":["import type { EventName, ThirdPartyTracker, TrackName } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\n/**\n * The one script an integration puts on the page, rendered by `<Analytics integrations>`\n * (react, next) with the request's `nonce`: an inline snippet that loads the\n * vendor's own script from its host, as every vendor's official snippet does.\n */\nexport interface IntegrationScript {\n /**\n * The element id; also its React key, and how a test or a CSP report finds it. Never a global's\n * name: an element's id is readable as `window[id]` until a script defines it, so an id like\n * `posthog` hands the snippet's `window.posthog || []` the <script> element. Keep a hyphen in it.\n */\n readonly id: string;\n readonly inline: string;\n /** `next/script`'s loading strategy, `afterInteractive` by default; the other frameworks ignore it. */\n readonly strategy?: 'beforeInteractive' | 'afterInteractive' | 'lazyOnload';\n}\n\n/**\n * One third party, configured in one place: how events reach it, how it learns the signed-in\n * user, and the script it needs. Built by the factories in `@shware/analytics/third-parties`\n * (`googleAnalytics`, `metaAds`, …) and handed to both `setupAnalytics({ integrations })` and\n * `<Analytics integrations>`. A host can write its own for a platform the SDK does not cover.\n *\n * `type` says what the platform is for. An `analytics` integration (GA4, PostHog) receives every\n * event, for behavior analysis. An `ads` integration receives only what helps an ad platform\n * optimize and build audiences — the conversion events it maps to its own standard events, plus\n * the custom events it was explicitly given — and filters in its own `track`.\n */\nexport interface Integration {\n readonly type: 'analytics' | 'ads';\n readonly track: ThirdPartyTracker;\n readonly setUser?: ThirdPartyUserSetter;\n readonly script?: IntegrationScript;\n /**\n * Origins `<Analytics>` preconnects to (`react-dom`'s `preconnect`), so the connection is up\n * before the script asks for something there — e.g. where a snippet loads its library from.\n */\n readonly preconnect?: readonly string[];\n}\n\n/**\n * A page served by a development setup: `localhost`, a `*.localhost` subdomain (a worktree under\n * portless is `<branch>.web.localhost:1355`) or the loopback address, with or without a port. One\n * pattern, used as a string in the inline scripts and as a RegExp here, so the two agree.\n */\nexport const LOCAL_HOST_PATTERN = String.raw`(^|\\.)localhost(:|$)|^127\\.0\\.0\\.1(:|$)`;\nconst LOCAL_HOST = new RegExp(LOCAL_HOST_PATTERN);\n\n/** Whether the page is served from a development host (`LOCAL_HOST_PATTERN`). */\nexport function isLocalHost(host: string = window.location.host): boolean {\n return LOCAL_HOST.test(host);\n}\n\n/**\n * The script an ad platform's integration puts on the page, silenced on a development host.\n * Every vendor snippet reports a page view as it loads (`fbq('track', 'PageView')`,\n * `rdt('track', 'PageVisit')`, UET's `pageLoad`), before any sender's own local check can run, so\n * a worktree served at `*.web.localhost` showed up at Meta as a new domain sending data. The\n * guard is in the snippet itself: the renderer has no request host on the server.\n */\nexport function integrationScripts(integrations: readonly Integration[]): IntegrationScript[] {\n return integrations.flatMap(({ type, script }) => {\n if (!script) return [];\n if (type !== 'ads') return [script];\n return [\n {\n ...script,\n inline: `if (!/${LOCAL_HOST_PATTERN}/.test(window.location.host)) {${script.inline}}`,\n },\n ];\n });\n}\n\n/**\n * The GA4 recommended events that are conversions or close to one, for an ad platform with no\n * standard events of its own to map to (Microsoft UET), so it is not sent the whole product.\n */\nexport const CONVERSION_EVENTS = [\n 'sign_up',\n 'login',\n 'generate_lead',\n 'view_item',\n 'add_to_cart',\n 'add_to_wishlist',\n 'begin_checkout',\n 'add_payment_info',\n 'purchase',\n 'subscribe',\n 'trial_begin',\n 'search',\n 'schedule',\n 'submit_application',\n 'contact',\n] as const satisfies readonly EventName[];\n\nexport interface AdsOptions {\n /**\n * Custom events this platform receives besides the conversions it maps to its standard\n * events, e.g. one used as an optimization goal or for an audience. Everything else is not\n * sent to it. The names `track` accepts, so with strict event names a typo is a compile error.\n */\n customEvents?: readonly TrackName[];\n}\n\n/**\n * Which events an ad platform receives: what `isStandard` accepts — the events its mapper turns\n * into one of its standard events — and the custom events the host listed. Everything else in the\n * product (feature use, clicks, onboarding steps) is behavior analysis, which is GA4's and\n * PostHog's job, and only noise to an ad platform's optimization. The same rule picks what the\n * browser tag and the platform's conversions API send (`@shware/analytics/server`), so the two\n * report the same events.\n */\nexport function adEvents(\n isStandard: (name: string) => boolean,\n customEvents: readonly string[] = []\n): (name: string) => boolean {\n return (name) => isStandard(name) || customEvents.includes(name);\n}\n\n/** An ad tracker that sends only the events `accepts` lets through (`adEvents`). */\nexport function adsTracker(\n send: ThirdPartyTracker,\n accepts: (name: string) => boolean\n): ThirdPartyTracker {\n return (name, properties, eventId) => {\n if (!accepts(name)) return;\n return send(name, properties, eventId);\n };\n}\n"],"mappings":";;;;;;AAgDA,MAAa,qBAAqB,OAAO,GAAG;AAC5C,MAAM,aAAa,IAAI,OAAO,kBAAkB;;AAGhD,SAAgB,YAAY,OAAe,OAAO,SAAS,MAAe;CACxE,OAAO,WAAW,KAAK,IAAI;AAC7B;;;;;;;;AASA,SAAgB,mBAAmB,cAA2D;CAC5F,OAAO,aAAa,SAAS,EAAE,MAAM,aAAa;EAChD,IAAI,CAAC,QAAQ,OAAO,CAAC;EACrB,IAAI,SAAS,OAAO,OAAO,CAAC,MAAM;EAClC,OAAO,CACL;GACE,GAAG;GACH,QAAQ,SAAS,mBAAmB,iCAAiC,OAAO,OAAO;EACrF,CACF;CACF,CAAC;AACH;;;;;AAMA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;AAmBA,SAAgB,SACd,YACA,eAAkC,CAAC,GACR;CAC3B,QAAQ,SAAS,WAAW,IAAI,KAAK,aAAa,SAAS,IAAI;AACjE;;AAGA,SAAgB,WACd,MACA,SACmB;CACnB,QAAQ,MAAM,YAAY,YAAY;EACpC,IAAI,CAAC,QAAQ,IAAI,GAAG;EACpB,OAAO,KAAK,MAAM,YAAY,OAAO;CACvC;AACF"}
|