@shware/analytics 3.8.3 → 4.0.1
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/click-id/index.cjs +125 -0
- package/dist/click-id/index.cjs.map +1 -0
- package/dist/click-id/index.d.cts +76 -0
- package/dist/click-id/index.d.cts.map +1 -0
- package/dist/click-id/index.d.mts +76 -0
- package/dist/click-id/index.d.mts.map +1 -0
- package/dist/click-id/index.mjs +119 -0
- package/dist/click-id/index.mjs.map +1 -0
- package/dist/constants/storage.cjs +1 -4
- package/dist/constants/storage.cjs.map +1 -1
- package/dist/constants/storage.d.cts +0 -3
- package/dist/constants/storage.d.cts.map +1 -1
- package/dist/constants/storage.d.mts +0 -3
- package/dist/constants/storage.d.mts.map +1 -1
- package/dist/constants/storage.mjs +1 -4
- package/dist/constants/storage.mjs.map +1 -1
- package/dist/hooks/use-report-web-vitals.cjs +17 -0
- package/dist/hooks/use-report-web-vitals.cjs.map +1 -0
- package/dist/hooks/use-report-web-vitals.d.cts +6 -0
- package/dist/hooks/use-report-web-vitals.d.cts.map +1 -0
- package/dist/hooks/use-report-web-vitals.d.mts +6 -0
- package/dist/hooks/use-report-web-vitals.d.mts.map +1 -0
- package/dist/hooks/use-report-web-vitals.mjs +16 -0
- package/dist/hooks/use-report-web-vitals.mjs.map +1 -0
- package/dist/next/index.cjs +0 -2
- 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 +0 -2
- package/dist/next/index.mjs.map +1 -1
- package/dist/react-router/index.cjs +2 -14
- package/dist/react-router/index.cjs.map +1 -1
- package/dist/react-router/index.d.cts.map +1 -1
- package/dist/react-router/index.d.mts.map +1 -1
- package/dist/react-router/index.mjs +1 -13
- package/dist/react-router/index.mjs.map +1 -1
- package/dist/server/index.cjs +7 -0
- package/dist/server/index.d.cts +2 -1
- package/dist/server/index.d.mts +2 -1
- package/dist/server/index.mjs +2 -1
- package/dist/tanstack/analytics.cjs +154 -0
- package/dist/tanstack/analytics.cjs.map +1 -0
- package/dist/tanstack/analytics.d.cts +22 -0
- package/dist/tanstack/analytics.d.cts.map +1 -0
- package/dist/tanstack/analytics.d.mts +22 -0
- package/dist/tanstack/analytics.d.mts.map +1 -0
- package/dist/tanstack/analytics.mjs +153 -0
- package/dist/tanstack/analytics.mjs.map +1 -0
- package/dist/tanstack/index.cjs +5 -165
- package/dist/tanstack/index.d.cts +3 -22
- package/dist/tanstack/index.d.mts +3 -22
- package/dist/tanstack/index.mjs +3 -165
- package/dist/tanstack/middleware.cjs +52 -0
- package/dist/tanstack/middleware.cjs.map +1 -0
- package/dist/tanstack/middleware.d.cts +54 -0
- package/dist/tanstack/middleware.d.cts.map +1 -0
- package/dist/tanstack/middleware.d.mts +54 -0
- package/dist/tanstack/middleware.d.mts.map +1 -0
- package/dist/tanstack/middleware.mjs +50 -0
- package/dist/tanstack/middleware.mjs.map +1 -0
- package/dist/web/index.cjs +3 -4
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts.map +1 -1
- package/dist/web/index.d.mts.map +1 -1
- package/dist/web/index.mjs +3 -4
- package/dist/web/index.mjs.map +1 -1
- package/package.json +5 -1
- package/dist/hooks/use-click-id-persistence.cjs +0 -52
- package/dist/hooks/use-click-id-persistence.cjs.map +0 -1
- package/dist/hooks/use-click-id-persistence.d.cts +0 -5
- package/dist/hooks/use-click-id-persistence.d.cts.map +0 -1
- package/dist/hooks/use-click-id-persistence.d.mts +0 -5
- package/dist/hooks/use-click-id-persistence.d.mts.map +0 -1
- package/dist/hooks/use-click-id-persistence.mjs +0 -51
- package/dist/hooks/use-click-id-persistence.mjs.map +0 -1
- package/dist/tanstack/index.cjs.map +0 -1
- package/dist/tanstack/index.d.cts.map +0 -1
- package/dist/tanstack/index.d.mts.map +0 -1
- package/dist/tanstack/index.mjs.map +0 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { track } from "../track/index.mjs";
|
|
2
|
+
import { useOutboundClickAnalytics } from "../hooks/use-outbound-click-analytics.mjs";
|
|
3
|
+
import { useReportWebVitals } from "../hooks/use-report-web-vitals.mjs";
|
|
4
|
+
import { useWebAnalytics } from "../hooks/use-web-analytics.mjs";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useLocation } from "@tanstack/react-router";
|
|
7
|
+
//#region src/tanstack/analytics.tsx
|
|
8
|
+
function Analytics({ gaId, gaSrc, nonce, debugMode, metaPixelId, openaiPixelId, redditPixelId, linkedInPartnerId, hotjarId, facebookAppId, reportWebVitals = true }) {
|
|
9
|
+
const { pathname } = useLocation();
|
|
10
|
+
useWebAnalytics(pathname);
|
|
11
|
+
useOutboundClickAnalytics();
|
|
12
|
+
useReportWebVitals((metric) => {
|
|
13
|
+
if (!reportWebVitals) return;
|
|
14
|
+
const properties = {
|
|
15
|
+
value: metric.delta,
|
|
16
|
+
metric_id: metric.id,
|
|
17
|
+
metric_value: metric.value,
|
|
18
|
+
metric_delta: metric.delta,
|
|
19
|
+
metric_rating: metric.rating,
|
|
20
|
+
metric_navigation_type: metric.navigationType,
|
|
21
|
+
non_interaction: true
|
|
22
|
+
};
|
|
23
|
+
track(metric.name, properties);
|
|
24
|
+
});
|
|
25
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
26
|
+
facebookAppId && /* @__PURE__ */ jsx("meta", {
|
|
27
|
+
property: "fb:app_id",
|
|
28
|
+
content: facebookAppId
|
|
29
|
+
}),
|
|
30
|
+
gaId && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("script", {
|
|
31
|
+
async: true,
|
|
32
|
+
id: "gtag",
|
|
33
|
+
nonce,
|
|
34
|
+
src: gaSrc ?? `https://www.googletagmanager.com/gtag/js?id=${gaId}`
|
|
35
|
+
}), /* @__PURE__ */ jsx("script", {
|
|
36
|
+
async: true,
|
|
37
|
+
nonce,
|
|
38
|
+
id: "gtag-init",
|
|
39
|
+
dangerouslySetInnerHTML: { __html: `
|
|
40
|
+
window.dataLayer = window.dataLayer || [];
|
|
41
|
+
function gtag(){dataLayer.push(arguments);}
|
|
42
|
+
gtag('js', new Date());
|
|
43
|
+
gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
|
|
44
|
+
` }
|
|
45
|
+
})] }),
|
|
46
|
+
metaPixelId && /* @__PURE__ */ jsx("script", {
|
|
47
|
+
async: true,
|
|
48
|
+
id: "meta-pixel",
|
|
49
|
+
dangerouslySetInnerHTML: { __html: `
|
|
50
|
+
!(function (f, b, e, v, n, t, s) {
|
|
51
|
+
if (f.fbq) return;
|
|
52
|
+
n = f.fbq = function () {
|
|
53
|
+
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
54
|
+
};
|
|
55
|
+
if (!f._fbq) f._fbq = n;
|
|
56
|
+
n.push = n;
|
|
57
|
+
n.loaded = !0;
|
|
58
|
+
n.version = '2.0';
|
|
59
|
+
n.queue = [];
|
|
60
|
+
t = b.createElement(e);
|
|
61
|
+
t.async = !0;
|
|
62
|
+
t.src = v;
|
|
63
|
+
s = b.getElementsByTagName(e)[0];
|
|
64
|
+
s.parentNode.insertBefore(t, s);
|
|
65
|
+
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
66
|
+
fbq('init', '${metaPixelId}');
|
|
67
|
+
fbq('track', 'PageView');` }
|
|
68
|
+
}),
|
|
69
|
+
openaiPixelId && /* @__PURE__ */ jsx("script", {
|
|
70
|
+
async: true,
|
|
71
|
+
id: "openai-pixel",
|
|
72
|
+
dangerouslySetInnerHTML: { __html: `
|
|
73
|
+
(function (w, d, s, u) {
|
|
74
|
+
if (w.oaiq) return;
|
|
75
|
+
var q = function () {
|
|
76
|
+
q.q.push(arguments);
|
|
77
|
+
};
|
|
78
|
+
q.q = [];
|
|
79
|
+
w.oaiq = q;
|
|
80
|
+
var js = d.createElement(s);
|
|
81
|
+
js.async = true;
|
|
82
|
+
js.src = u;
|
|
83
|
+
var f = d.getElementsByTagName(s)[0];
|
|
84
|
+
f.parentNode.insertBefore(js, f);
|
|
85
|
+
})(window, document, "script", "https://bzrcdn.openai.com/sdk/oaiq.min.js");
|
|
86
|
+
|
|
87
|
+
oaiq("init", { pixelId: "${openaiPixelId}" });
|
|
88
|
+
oaiq("measure", "page_viewed", { type: "contents" });
|
|
89
|
+
` }
|
|
90
|
+
}),
|
|
91
|
+
redditPixelId && /* @__PURE__ */ jsx("script", {
|
|
92
|
+
async: true,
|
|
93
|
+
id: "reddit-pixel",
|
|
94
|
+
dangerouslySetInnerHTML: { __html: `
|
|
95
|
+
!function(w,d) {
|
|
96
|
+
if(!w.rdt) {
|
|
97
|
+
var p = w.rdt = function() {
|
|
98
|
+
p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)
|
|
99
|
+
};
|
|
100
|
+
p.callQueue = [];
|
|
101
|
+
var t = d.createElement("script");
|
|
102
|
+
t.src = "https://www.redditstatic.com/ads/pixel.js";
|
|
103
|
+
t.async = !0;
|
|
104
|
+
var s = d.getElementsByTagName("script")[0];
|
|
105
|
+
s.parentNode.insertBefore(t,s)
|
|
106
|
+
}
|
|
107
|
+
}(window, document);
|
|
108
|
+
rdt('init', '${redditPixelId}');
|
|
109
|
+
rdt('track', 'PageVisit');` }
|
|
110
|
+
}),
|
|
111
|
+
linkedInPartnerId && /* @__PURE__ */ jsx("script", {
|
|
112
|
+
async: true,
|
|
113
|
+
id: "linkedin-insight-tag",
|
|
114
|
+
dangerouslySetInnerHTML: { __html: `
|
|
115
|
+
_linkedin_partner_id = "${linkedInPartnerId}";
|
|
116
|
+
window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
|
|
117
|
+
window._linkedin_data_partner_ids.push(_linkedin_partner_id);
|
|
118
|
+
|
|
119
|
+
(function(l) {
|
|
120
|
+
if (!l){
|
|
121
|
+
window.lintrk = function(a,b){
|
|
122
|
+
window.lintrk.q.push([a,b])
|
|
123
|
+
};
|
|
124
|
+
window.lintrk.q=[]
|
|
125
|
+
}
|
|
126
|
+
var s = document.getElementsByTagName("script")[0];
|
|
127
|
+
var b = document.createElement("script");
|
|
128
|
+
b.type = "text/javascript";b.async = true;
|
|
129
|
+
b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
|
|
130
|
+
s.parentNode.insertBefore(b, s);
|
|
131
|
+
})(window.lintrk);
|
|
132
|
+
` }
|
|
133
|
+
}),
|
|
134
|
+
hotjarId && /* @__PURE__ */ jsx("script", {
|
|
135
|
+
async: true,
|
|
136
|
+
id: "hotjar",
|
|
137
|
+
dangerouslySetInnerHTML: { __html: `
|
|
138
|
+
(function(h,o,t,j,a,r){
|
|
139
|
+
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
|
140
|
+
h._hjSettings={hjid:${hotjarId},hjsv:6};
|
|
141
|
+
a=o.getElementsByTagName('head')[0];
|
|
142
|
+
r=o.createElement('script');r.async=1;
|
|
143
|
+
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
|
144
|
+
a.appendChild(r);
|
|
145
|
+
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
|
146
|
+
` }
|
|
147
|
+
})
|
|
148
|
+
] });
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
export { Analytics };
|
|
152
|
+
|
|
153
|
+
//# sourceMappingURL=analytics.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.mjs","names":[],"sources":["../../src/tanstack/analytics.tsx"],"sourcesContent":["import { useLocation } from '@tanstack/react-router';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useReportWebVitals } from '../hooks/use-report-web-vitals';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport type { PixelId as MetaPixelId } from '../track/fbq';\nimport type { GaId, GtmId } from '../track/gtag';\nimport { track } from '../track/index';\nimport type { PixelId as RedditPixelId } from '../track/rdt';\n\ninterface Props {\n gaId?: GaId;\n gaSrc?: string;\n gtmId?: GtmId;\n metaPixelId?: MetaPixelId;\n openaiPixelId?: string;\n redditPixelId?: RedditPixelId;\n linkedInPartnerId?: `${number}`;\n hotjarId?: `${number}`;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function Analytics({\n gaId,\n gaSrc,\n nonce,\n debugMode,\n metaPixelId,\n openaiPixelId,\n redditPixelId,\n linkedInPartnerId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const { pathname } = useLocation();\n useWebAnalytics(pathname);\n useOutboundClickAnalytics();\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 {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {gaId && (\n <>\n <script\n async\n id=\"gtag\"\n nonce={nonce}\n src={gaSrc ?? `https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <script\n async\n nonce={nonce}\n id=\"gtag-init\"\n dangerouslySetInnerHTML={{\n __html: `\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '${gaId}'${debugMode ? \" ,{ 'debug_mode': true }\" : ''});\n `,\n }}\n />\n </>\n )}\n {metaPixelId && (\n <script\n async\n id=\"meta-pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '${metaPixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {openaiPixelId && (\n <script\n async\n id=\"openai-pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n (function (w, d, s, u) {\n if (w.oaiq) return;\n var q = function () {\n q.q.push(arguments);\n };\n q.q = [];\n w.oaiq = q;\n var js = d.createElement(s);\n js.async = true;\n js.src = u;\n var f = d.getElementsByTagName(s)[0];\n f.parentNode.insertBefore(js, f);\n })(window, document, \"script\", \"https://bzrcdn.openai.com/sdk/oaiq.min.js\");\n\n oaiq(\"init\", { pixelId: \"${openaiPixelId}\" });\n oaiq(\"measure\", \"page_viewed\", { type: \"contents\" });\n `,\n }}\n />\n )}\n {redditPixelId && (\n <script\n async\n id=\"reddit-pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n !function(w,d) {\n if(!w.rdt) {\n var p = w.rdt = function() {\n p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)\n };\n p.callQueue = [];\n var t = d.createElement(\"script\");\n t.src = \"https://www.redditstatic.com/ads/pixel.js\";\n t.async = !0;\n var s = d.getElementsByTagName(\"script\")[0];\n s.parentNode.insertBefore(t,s)\n }\n }(window, document);\n rdt('init', '${redditPixelId}');\n rdt('track', 'PageVisit');`,\n }}\n />\n )}\n {linkedInPartnerId && (\n <script\n async\n id=\"linkedin-insight-tag\"\n dangerouslySetInnerHTML={{\n __html: `\n _linkedin_partner_id = \"${linkedInPartnerId}\";\n window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];\n window._linkedin_data_partner_ids.push(_linkedin_partner_id);\n\n (function(l) {\n if (!l){\n window.lintrk = function(a,b){\n window.lintrk.q.push([a,b])\n };\n window.lintrk.q=[]\n }\n var s = document.getElementsByTagName(\"script\")[0];\n var b = document.createElement(\"script\");\n b.type = \"text/javascript\";b.async = true;\n b.src = \"https://snap.licdn.com/li.lms-analytics/insight.min.js\";\n s.parentNode.insertBefore(b, s);\n })(window.lintrk);\n `,\n }}\n />\n )}\n {hotjarId && (\n <script\n async\n id=\"hotjar\"\n dangerouslySetInnerHTML={{\n __html: `\n (function(h,o,t,j,a,r){\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\n h._hjSettings={hjid:${hotjarId},hjsv:6};\n a=o.getElementsByTagName('head')[0];\n r=o.createElement('script');r.async=1;\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\n a.appendChild(r);\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\n `,\n }}\n />\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,UAAU,EACxB,MACA,OACA,OACA,WACA,aACA,eACA,eACA,mBACA,UACA,eACA,kBAAkB,QACV;CACR,MAAM,EAAE,aAAa,YAAY;CACjC,gBAAgB,QAAQ;CACxB,0BAA0B;CAE1B,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;EACG,iBAAiB,oBAAC,QAAD;GAAM,UAAS;GAAY,SAAS;EAAgB,CAAA;EACrE,QACC,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,UAAD;GACE,OAAA;GACA,IAAG;GACI;GACP,KAAK,SAAS,+CAA+C;EAC9D,CAAA,GACD,oBAAC,UAAD;GACE,OAAA;GACO;GACP,IAAG;GACH,yBAAyB,EACvB,QAAQ;;;;gCAIU,KAAK,GAAG,YAAY,6BAA6B,GAAG;cAExE;EACD,CAAA,CACD,EAAA,CAAA;EAEH,eACC,oBAAC,UAAD;GACE,OAAA;GACA,IAAG;GACH,yBAAyB,EACvB,QAAQ;;;;;;;;;;;;;;;;;2BAiBO,YAAY;uCAE7B;EACD,CAAA;EAEF,iBACC,oBAAC,UAAD;GACE,OAAA;GACA,IAAG;GACH,yBAAyB,EACvB,QAAQ;;;;;;;;;;;;;;;2CAeuB,cAAc;;cAG/C;EACD,CAAA;EAEF,iBACC,oBAAC,UAAD;GACE,OAAA;GACA,IAAG;GACH,yBAAyB,EACvB,QAAQ;;;;;;;;;;;;;;2BAcO,cAAc;wCAE/B;EACD,CAAA;EAEF,qBACC,oBAAC,UAAD;GACE,OAAA;GACA,IAAG;GACH,yBAAyB,EACvB,QAAQ;sCACkB,kBAAkB;;;;;;;;;;;;;;;;;cAkB9C;EACD,CAAA;EAEF,YACC,oBAAC,UAAD;GACE,OAAA;GACA,IAAG;GACH,yBAAyB,EACvB,QAAQ;;;oCAGgB,SAAS;;;;;;cAOnC;EACD,CAAA;CAEH,EAAA,CAAA;AAEN"}
|
package/dist/tanstack/index.cjs
CHANGED
|
@@ -1,166 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
-
let web_vitals = require("web-vitals");
|
|
9
|
-
let _tanstack_react_router = require("@tanstack/react-router");
|
|
10
|
-
//#region src/tanstack/index.tsx
|
|
11
|
-
function useReportWebVitals(reportWebVitalsFn) {
|
|
12
|
-
(0, react.useEffect)(() => {
|
|
13
|
-
(0, web_vitals.onCLS)(reportWebVitalsFn);
|
|
14
|
-
(0, web_vitals.onLCP)(reportWebVitalsFn);
|
|
15
|
-
(0, web_vitals.onINP)(reportWebVitalsFn);
|
|
16
|
-
(0, web_vitals.onFCP)(reportWebVitalsFn);
|
|
17
|
-
(0, web_vitals.onTTFB)(reportWebVitalsFn);
|
|
18
|
-
}, [reportWebVitalsFn]);
|
|
19
|
-
}
|
|
20
|
-
function Analytics({ gaId, gaSrc, nonce, debugMode, metaPixelId, openaiPixelId, redditPixelId, linkedInPartnerId, hotjarId, facebookAppId, reportWebVitals = true }) {
|
|
21
|
-
require_hooks_use_click_id_persistence.useClickIdPersistence();
|
|
22
|
-
const { pathname } = (0, _tanstack_react_router.useLocation)();
|
|
23
|
-
require_hooks_use_web_analytics.useWebAnalytics(pathname);
|
|
24
|
-
require_hooks_use_outbound_click_analytics.useOutboundClickAnalytics();
|
|
25
|
-
useReportWebVitals((metric) => {
|
|
26
|
-
if (!reportWebVitals) return;
|
|
27
|
-
const properties = {
|
|
28
|
-
value: metric.delta,
|
|
29
|
-
metric_id: metric.id,
|
|
30
|
-
metric_value: metric.value,
|
|
31
|
-
metric_delta: metric.delta,
|
|
32
|
-
metric_rating: metric.rating,
|
|
33
|
-
metric_navigation_type: metric.navigationType,
|
|
34
|
-
non_interaction: true
|
|
35
|
-
};
|
|
36
|
-
require_track_index.track(metric.name, properties);
|
|
37
|
-
});
|
|
38
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
39
|
-
facebookAppId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("meta", {
|
|
40
|
-
property: "fb:app_id",
|
|
41
|
-
content: facebookAppId
|
|
42
|
-
}),
|
|
43
|
-
gaId && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
44
|
-
async: true,
|
|
45
|
-
id: "gtag",
|
|
46
|
-
nonce,
|
|
47
|
-
src: gaSrc ?? `https://www.googletagmanager.com/gtag/js?id=${gaId}`
|
|
48
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
49
|
-
async: true,
|
|
50
|
-
nonce,
|
|
51
|
-
id: "gtag-init",
|
|
52
|
-
dangerouslySetInnerHTML: { __html: `
|
|
53
|
-
window.dataLayer = window.dataLayer || [];
|
|
54
|
-
function gtag(){dataLayer.push(arguments);}
|
|
55
|
-
gtag('js', new Date());
|
|
56
|
-
gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
|
|
57
|
-
` }
|
|
58
|
-
})] }),
|
|
59
|
-
metaPixelId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
60
|
-
async: true,
|
|
61
|
-
id: "meta-pixel",
|
|
62
|
-
dangerouslySetInnerHTML: { __html: `
|
|
63
|
-
!(function (f, b, e, v, n, t, s) {
|
|
64
|
-
if (f.fbq) return;
|
|
65
|
-
n = f.fbq = function () {
|
|
66
|
-
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
67
|
-
};
|
|
68
|
-
if (!f._fbq) f._fbq = n;
|
|
69
|
-
n.push = n;
|
|
70
|
-
n.loaded = !0;
|
|
71
|
-
n.version = '2.0';
|
|
72
|
-
n.queue = [];
|
|
73
|
-
t = b.createElement(e);
|
|
74
|
-
t.async = !0;
|
|
75
|
-
t.src = v;
|
|
76
|
-
s = b.getElementsByTagName(e)[0];
|
|
77
|
-
s.parentNode.insertBefore(t, s);
|
|
78
|
-
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
79
|
-
fbq('init', '${metaPixelId}');
|
|
80
|
-
fbq('track', 'PageView');` }
|
|
81
|
-
}),
|
|
82
|
-
openaiPixelId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
83
|
-
async: true,
|
|
84
|
-
id: "openai-pixel",
|
|
85
|
-
dangerouslySetInnerHTML: { __html: `
|
|
86
|
-
(function (w, d, s, u) {
|
|
87
|
-
if (w.oaiq) return;
|
|
88
|
-
var q = function () {
|
|
89
|
-
q.q.push(arguments);
|
|
90
|
-
};
|
|
91
|
-
q.q = [];
|
|
92
|
-
w.oaiq = q;
|
|
93
|
-
var js = d.createElement(s);
|
|
94
|
-
js.async = true;
|
|
95
|
-
js.src = u;
|
|
96
|
-
var f = d.getElementsByTagName(s)[0];
|
|
97
|
-
f.parentNode.insertBefore(js, f);
|
|
98
|
-
})(window, document, "script", "https://bzrcdn.openai.com/sdk/oaiq.min.js");
|
|
99
|
-
|
|
100
|
-
oaiq("init", { pixelId: "${openaiPixelId}" });
|
|
101
|
-
oaiq("measure", "page_viewed", { type: "contents" });
|
|
102
|
-
` }
|
|
103
|
-
}),
|
|
104
|
-
redditPixelId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
105
|
-
async: true,
|
|
106
|
-
id: "reddit-pixel",
|
|
107
|
-
dangerouslySetInnerHTML: { __html: `
|
|
108
|
-
!function(w,d) {
|
|
109
|
-
if(!w.rdt) {
|
|
110
|
-
var p = w.rdt = function() {
|
|
111
|
-
p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)
|
|
112
|
-
};
|
|
113
|
-
p.callQueue = [];
|
|
114
|
-
var t = d.createElement("script");
|
|
115
|
-
t.src = "https://www.redditstatic.com/ads/pixel.js";
|
|
116
|
-
t.async = !0;
|
|
117
|
-
var s = d.getElementsByTagName("script")[0];
|
|
118
|
-
s.parentNode.insertBefore(t,s)
|
|
119
|
-
}
|
|
120
|
-
}(window, document);
|
|
121
|
-
rdt('init', '${redditPixelId}');
|
|
122
|
-
rdt('track', 'PageVisit');` }
|
|
123
|
-
}),
|
|
124
|
-
linkedInPartnerId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
125
|
-
async: true,
|
|
126
|
-
id: "linkedin-insight-tag",
|
|
127
|
-
dangerouslySetInnerHTML: { __html: `
|
|
128
|
-
_linkedin_partner_id = "${linkedInPartnerId}";
|
|
129
|
-
window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
|
|
130
|
-
window._linkedin_data_partner_ids.push(_linkedin_partner_id);
|
|
131
|
-
|
|
132
|
-
(function(l) {
|
|
133
|
-
if (!l){
|
|
134
|
-
window.lintrk = function(a,b){
|
|
135
|
-
window.lintrk.q.push([a,b])
|
|
136
|
-
};
|
|
137
|
-
window.lintrk.q=[]
|
|
138
|
-
}
|
|
139
|
-
var s = document.getElementsByTagName("script")[0];
|
|
140
|
-
var b = document.createElement("script");
|
|
141
|
-
b.type = "text/javascript";b.async = true;
|
|
142
|
-
b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
|
|
143
|
-
s.parentNode.insertBefore(b, s);
|
|
144
|
-
})(window.lintrk);
|
|
145
|
-
` }
|
|
146
|
-
}),
|
|
147
|
-
hotjarId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("script", {
|
|
148
|
-
async: true,
|
|
149
|
-
id: "hotjar",
|
|
150
|
-
dangerouslySetInnerHTML: { __html: `
|
|
151
|
-
(function(h,o,t,j,a,r){
|
|
152
|
-
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
|
153
|
-
h._hjSettings={hjid:${hotjarId},hjsv:6};
|
|
154
|
-
a=o.getElementsByTagName('head')[0];
|
|
155
|
-
r=o.createElement('script');r.async=1;
|
|
156
|
-
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
|
157
|
-
a.appendChild(r);
|
|
158
|
-
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
|
159
|
-
` }
|
|
160
|
-
})
|
|
161
|
-
] });
|
|
162
|
-
}
|
|
163
|
-
//#endregion
|
|
164
|
-
exports.Analytics = Analytics;
|
|
165
|
-
|
|
166
|
-
//# sourceMappingURL=index.cjs.map
|
|
2
|
+
const require_tanstack_analytics = require("./analytics.cjs");
|
|
3
|
+
const require_tanstack_middleware = require("./middleware.cjs");
|
|
4
|
+
exports.Analytics = require_tanstack_analytics.Analytics;
|
|
5
|
+
exports.clickIdMiddleware = require_tanstack_middleware.clickIdMiddleware;
|
|
6
|
+
exports.createClickIdMiddleware = require_tanstack_middleware.createClickIdMiddleware;
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/tanstack/index.d.ts
|
|
5
|
-
interface Props {
|
|
6
|
-
gaId?: GaId;
|
|
7
|
-
gaSrc?: string;
|
|
8
|
-
gtmId?: GtmId;
|
|
9
|
-
metaPixelId?: PixelId;
|
|
10
|
-
openaiPixelId?: string;
|
|
11
|
-
redditPixelId?: PixelId$1;
|
|
12
|
-
linkedInPartnerId?: `${number}`;
|
|
13
|
-
hotjarId?: `${number}`;
|
|
14
|
-
facebookAppId?: string;
|
|
15
|
-
nonce?: string;
|
|
16
|
-
debugMode?: boolean;
|
|
17
|
-
reportWebVitals?: boolean;
|
|
18
|
-
}
|
|
19
|
-
declare function Analytics({ gaId, gaSrc, nonce, debugMode, metaPixelId, openaiPixelId, redditPixelId, linkedInPartnerId, hotjarId, facebookAppId, reportWebVitals }: Props): import("react").JSX.Element;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { Analytics };
|
|
22
|
-
//# sourceMappingURL=index.d.cts.map
|
|
1
|
+
import { Analytics } from "./analytics.cjs";
|
|
2
|
+
import { ClickIdMiddlewareOptions, clickIdMiddleware, createClickIdMiddleware } from "./middleware.cjs";
|
|
3
|
+
export { Analytics, type ClickIdMiddlewareOptions, clickIdMiddleware, createClickIdMiddleware };
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/tanstack/index.d.ts
|
|
5
|
-
interface Props {
|
|
6
|
-
gaId?: GaId;
|
|
7
|
-
gaSrc?: string;
|
|
8
|
-
gtmId?: GtmId;
|
|
9
|
-
metaPixelId?: PixelId;
|
|
10
|
-
openaiPixelId?: string;
|
|
11
|
-
redditPixelId?: PixelId$1;
|
|
12
|
-
linkedInPartnerId?: `${number}`;
|
|
13
|
-
hotjarId?: `${number}`;
|
|
14
|
-
facebookAppId?: string;
|
|
15
|
-
nonce?: string;
|
|
16
|
-
debugMode?: boolean;
|
|
17
|
-
reportWebVitals?: boolean;
|
|
18
|
-
}
|
|
19
|
-
declare function Analytics({ gaId, gaSrc, nonce, debugMode, metaPixelId, openaiPixelId, redditPixelId, linkedInPartnerId, hotjarId, facebookAppId, reportWebVitals }: Props): import("react").JSX.Element;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { Analytics };
|
|
22
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1
|
+
import { Analytics } from "./analytics.mjs";
|
|
2
|
+
import { ClickIdMiddlewareOptions, clickIdMiddleware, createClickIdMiddleware } from "./middleware.mjs";
|
|
3
|
+
export { Analytics, type ClickIdMiddlewareOptions, clickIdMiddleware, createClickIdMiddleware };
|
package/dist/tanstack/index.mjs
CHANGED
|
@@ -1,165 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { useWebAnalytics } from "../hooks/use-web-analytics.mjs";
|
|
5
|
-
import { useEffect } from "react";
|
|
6
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
import { onCLS, onFCP, onINP, onLCP, onTTFB } from "web-vitals";
|
|
8
|
-
import { useLocation } from "@tanstack/react-router";
|
|
9
|
-
//#region src/tanstack/index.tsx
|
|
10
|
-
function useReportWebVitals(reportWebVitalsFn) {
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
onCLS(reportWebVitalsFn);
|
|
13
|
-
onLCP(reportWebVitalsFn);
|
|
14
|
-
onINP(reportWebVitalsFn);
|
|
15
|
-
onFCP(reportWebVitalsFn);
|
|
16
|
-
onTTFB(reportWebVitalsFn);
|
|
17
|
-
}, [reportWebVitalsFn]);
|
|
18
|
-
}
|
|
19
|
-
function Analytics({ gaId, gaSrc, nonce, debugMode, metaPixelId, openaiPixelId, redditPixelId, linkedInPartnerId, hotjarId, facebookAppId, reportWebVitals = true }) {
|
|
20
|
-
useClickIdPersistence();
|
|
21
|
-
const { pathname } = useLocation();
|
|
22
|
-
useWebAnalytics(pathname);
|
|
23
|
-
useOutboundClickAnalytics();
|
|
24
|
-
useReportWebVitals((metric) => {
|
|
25
|
-
if (!reportWebVitals) return;
|
|
26
|
-
const properties = {
|
|
27
|
-
value: metric.delta,
|
|
28
|
-
metric_id: metric.id,
|
|
29
|
-
metric_value: metric.value,
|
|
30
|
-
metric_delta: metric.delta,
|
|
31
|
-
metric_rating: metric.rating,
|
|
32
|
-
metric_navigation_type: metric.navigationType,
|
|
33
|
-
non_interaction: true
|
|
34
|
-
};
|
|
35
|
-
track(metric.name, properties);
|
|
36
|
-
});
|
|
37
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
38
|
-
facebookAppId && /* @__PURE__ */ jsx("meta", {
|
|
39
|
-
property: "fb:app_id",
|
|
40
|
-
content: facebookAppId
|
|
41
|
-
}),
|
|
42
|
-
gaId && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("script", {
|
|
43
|
-
async: true,
|
|
44
|
-
id: "gtag",
|
|
45
|
-
nonce,
|
|
46
|
-
src: gaSrc ?? `https://www.googletagmanager.com/gtag/js?id=${gaId}`
|
|
47
|
-
}), /* @__PURE__ */ jsx("script", {
|
|
48
|
-
async: true,
|
|
49
|
-
nonce,
|
|
50
|
-
id: "gtag-init",
|
|
51
|
-
dangerouslySetInnerHTML: { __html: `
|
|
52
|
-
window.dataLayer = window.dataLayer || [];
|
|
53
|
-
function gtag(){dataLayer.push(arguments);}
|
|
54
|
-
gtag('js', new Date());
|
|
55
|
-
gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
|
|
56
|
-
` }
|
|
57
|
-
})] }),
|
|
58
|
-
metaPixelId && /* @__PURE__ */ jsx("script", {
|
|
59
|
-
async: true,
|
|
60
|
-
id: "meta-pixel",
|
|
61
|
-
dangerouslySetInnerHTML: { __html: `
|
|
62
|
-
!(function (f, b, e, v, n, t, s) {
|
|
63
|
-
if (f.fbq) return;
|
|
64
|
-
n = f.fbq = function () {
|
|
65
|
-
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
66
|
-
};
|
|
67
|
-
if (!f._fbq) f._fbq = n;
|
|
68
|
-
n.push = n;
|
|
69
|
-
n.loaded = !0;
|
|
70
|
-
n.version = '2.0';
|
|
71
|
-
n.queue = [];
|
|
72
|
-
t = b.createElement(e);
|
|
73
|
-
t.async = !0;
|
|
74
|
-
t.src = v;
|
|
75
|
-
s = b.getElementsByTagName(e)[0];
|
|
76
|
-
s.parentNode.insertBefore(t, s);
|
|
77
|
-
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
78
|
-
fbq('init', '${metaPixelId}');
|
|
79
|
-
fbq('track', 'PageView');` }
|
|
80
|
-
}),
|
|
81
|
-
openaiPixelId && /* @__PURE__ */ jsx("script", {
|
|
82
|
-
async: true,
|
|
83
|
-
id: "openai-pixel",
|
|
84
|
-
dangerouslySetInnerHTML: { __html: `
|
|
85
|
-
(function (w, d, s, u) {
|
|
86
|
-
if (w.oaiq) return;
|
|
87
|
-
var q = function () {
|
|
88
|
-
q.q.push(arguments);
|
|
89
|
-
};
|
|
90
|
-
q.q = [];
|
|
91
|
-
w.oaiq = q;
|
|
92
|
-
var js = d.createElement(s);
|
|
93
|
-
js.async = true;
|
|
94
|
-
js.src = u;
|
|
95
|
-
var f = d.getElementsByTagName(s)[0];
|
|
96
|
-
f.parentNode.insertBefore(js, f);
|
|
97
|
-
})(window, document, "script", "https://bzrcdn.openai.com/sdk/oaiq.min.js");
|
|
98
|
-
|
|
99
|
-
oaiq("init", { pixelId: "${openaiPixelId}" });
|
|
100
|
-
oaiq("measure", "page_viewed", { type: "contents" });
|
|
101
|
-
` }
|
|
102
|
-
}),
|
|
103
|
-
redditPixelId && /* @__PURE__ */ jsx("script", {
|
|
104
|
-
async: true,
|
|
105
|
-
id: "reddit-pixel",
|
|
106
|
-
dangerouslySetInnerHTML: { __html: `
|
|
107
|
-
!function(w,d) {
|
|
108
|
-
if(!w.rdt) {
|
|
109
|
-
var p = w.rdt = function() {
|
|
110
|
-
p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)
|
|
111
|
-
};
|
|
112
|
-
p.callQueue = [];
|
|
113
|
-
var t = d.createElement("script");
|
|
114
|
-
t.src = "https://www.redditstatic.com/ads/pixel.js";
|
|
115
|
-
t.async = !0;
|
|
116
|
-
var s = d.getElementsByTagName("script")[0];
|
|
117
|
-
s.parentNode.insertBefore(t,s)
|
|
118
|
-
}
|
|
119
|
-
}(window, document);
|
|
120
|
-
rdt('init', '${redditPixelId}');
|
|
121
|
-
rdt('track', 'PageVisit');` }
|
|
122
|
-
}),
|
|
123
|
-
linkedInPartnerId && /* @__PURE__ */ jsx("script", {
|
|
124
|
-
async: true,
|
|
125
|
-
id: "linkedin-insight-tag",
|
|
126
|
-
dangerouslySetInnerHTML: { __html: `
|
|
127
|
-
_linkedin_partner_id = "${linkedInPartnerId}";
|
|
128
|
-
window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
|
|
129
|
-
window._linkedin_data_partner_ids.push(_linkedin_partner_id);
|
|
130
|
-
|
|
131
|
-
(function(l) {
|
|
132
|
-
if (!l){
|
|
133
|
-
window.lintrk = function(a,b){
|
|
134
|
-
window.lintrk.q.push([a,b])
|
|
135
|
-
};
|
|
136
|
-
window.lintrk.q=[]
|
|
137
|
-
}
|
|
138
|
-
var s = document.getElementsByTagName("script")[0];
|
|
139
|
-
var b = document.createElement("script");
|
|
140
|
-
b.type = "text/javascript";b.async = true;
|
|
141
|
-
b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
|
|
142
|
-
s.parentNode.insertBefore(b, s);
|
|
143
|
-
})(window.lintrk);
|
|
144
|
-
` }
|
|
145
|
-
}),
|
|
146
|
-
hotjarId && /* @__PURE__ */ jsx("script", {
|
|
147
|
-
async: true,
|
|
148
|
-
id: "hotjar",
|
|
149
|
-
dangerouslySetInnerHTML: { __html: `
|
|
150
|
-
(function(h,o,t,j,a,r){
|
|
151
|
-
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
|
152
|
-
h._hjSettings={hjid:${hotjarId},hjsv:6};
|
|
153
|
-
a=o.getElementsByTagName('head')[0];
|
|
154
|
-
r=o.createElement('script');r.async=1;
|
|
155
|
-
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
|
156
|
-
a.appendChild(r);
|
|
157
|
-
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
|
158
|
-
` }
|
|
159
|
-
})
|
|
160
|
-
] });
|
|
161
|
-
}
|
|
162
|
-
//#endregion
|
|
163
|
-
export { Analytics };
|
|
164
|
-
|
|
165
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import { Analytics } from "./analytics.mjs";
|
|
2
|
+
import { clickIdMiddleware, createClickIdMiddleware } from "./middleware.mjs";
|
|
3
|
+
export { Analytics, clickIdMiddleware, createClickIdMiddleware };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_click_id_index = require("../click-id/index.cjs");
|
|
3
|
+
let _tanstack_react_start = require("@tanstack/react-start");
|
|
4
|
+
//#region src/tanstack/middleware.ts
|
|
5
|
+
/**
|
|
6
|
+
* TanStack Start request middleware that persists ad click-id cookies (`_fbc`, `_rdt_cid`) on the
|
|
7
|
+
* document response.
|
|
8
|
+
*
|
|
9
|
+
* Setting `_fbc` here — on the top document via an HTTP `Set-Cookie` header, before any client JS
|
|
10
|
+
* runs — is what Meta officially recommends and the only reliable way to keep the cookie alive for
|
|
11
|
+
* 90 days in Safari: ITP caps JavaScript-set cookies on a fbclid-decorated landing page to 24
|
|
12
|
+
* hours, and a document response is never classified as CNAME/IP cloaking (it is the reference the
|
|
13
|
+
* browser measures cloaking against).
|
|
14
|
+
*
|
|
15
|
+
* Register it as a global request middleware:
|
|
16
|
+
* ```ts
|
|
17
|
+
* // start.ts
|
|
18
|
+
* import { createStart } from '@tanstack/react-start'
|
|
19
|
+
* import { clickIdMiddleware } from '@shware/analytics/tanstack'
|
|
20
|
+
* export const startInstance = createStart(() => ({ requestMiddleware: [clickIdMiddleware] }))
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc
|
|
24
|
+
*/
|
|
25
|
+
function createClickIdMiddleware(options = {}) {
|
|
26
|
+
const { cacheControl = "private, no-store" } = options;
|
|
27
|
+
return (0, _tanstack_react_start.createMiddleware)({ type: "request" }).server(async ({ request, next, handlerType }) => {
|
|
28
|
+
const result = await next();
|
|
29
|
+
if (handlerType !== "router") return result;
|
|
30
|
+
if (options.shouldPersist && !options.shouldPersist(request)) return result;
|
|
31
|
+
const { cookies } = require_click_id_index.resolveClickIdCookies({
|
|
32
|
+
url: request.url,
|
|
33
|
+
cookieHeader: request.headers.get("cookie"),
|
|
34
|
+
domain: options.domain,
|
|
35
|
+
secure: options.secure,
|
|
36
|
+
subdomainIndex: options.subdomainIndex,
|
|
37
|
+
refresh: options.refresh ?? true
|
|
38
|
+
});
|
|
39
|
+
if (cookies.length > 0) {
|
|
40
|
+
for (const header of require_click_id_index.toSetCookieHeaders(cookies)) result.response.headers.append("set-cookie", header);
|
|
41
|
+
if (cacheControl !== false) result.response.headers.set("cache-control", cacheControl);
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** Ready-to-register middleware with default options. */
|
|
47
|
+
const clickIdMiddleware = createClickIdMiddleware();
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.clickIdMiddleware = clickIdMiddleware;
|
|
50
|
+
exports.createClickIdMiddleware = createClickIdMiddleware;
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=middleware.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.cjs","names":["resolveClickIdCookies","toSetCookieHeaders"],"sources":["../../src/tanstack/middleware.ts"],"sourcesContent":["import { createMiddleware } from '@tanstack/react-start';\nimport { resolveClickIdCookies, toSetCookieHeaders } from '../click-id/index';\n\nexport interface ClickIdMiddlewareOptions {\n /** `Domain` attribute for the cookies, e.g. `.edensign.io`. Omit for a host-only cookie. */\n domain?: string;\n /** `Secure` attribute, default true. Set false only for local http testing. */\n secure?: boolean;\n /** subdomainIndex for a freshly built `_fbc` (com=0, example.com=1, www.example.com=2). Default 1. */\n subdomainIndex?: number;\n /**\n * Re-issue a still-valid `_fbc` on every request as an ITP self-heal (restores the long-lived\n * HTTP cookie if the Meta Pixel's `document.cookie` write re-capped it to 24h in Safari). On by\n * default. Note it attaches a per-user `Set-Cookie` — and thus `no-store` — to every page\n * response carrying an `_fbc`, defeating CDN caching of those pages; set false to strictly follow\n * Meta's conditional-write rule and keep them cacheable. See {@link resolveClickIdCookies}.\n */\n refresh?: boolean;\n /**\n * Override the `Cache-Control` of a response we attach cookies to (default `private, no-store`).\n * A per-user `Set-Cookie` must never end up on a shared-cache entry, or one visitor's `_fbc` would\n * be served to everyone. Only set this false if you guarantee these responses are never cached.\n */\n cacheControl?: string | false;\n /**\n * Consent gate. Return false to skip setting cookies for this request (e.g. before the visitor has\n * granted consent where required). Runs per request with the incoming `Request`.\n */\n shouldPersist?: (request: Request) => boolean;\n}\n\n/**\n * TanStack Start request middleware that persists ad click-id cookies (`_fbc`, `_rdt_cid`) on the\n * document response.\n *\n * Setting `_fbc` here — on the top document via an HTTP `Set-Cookie` header, before any client JS\n * runs — is what Meta officially recommends and the only reliable way to keep the cookie alive for\n * 90 days in Safari: ITP caps JavaScript-set cookies on a fbclid-decorated landing page to 24\n * hours, and a document response is never classified as CNAME/IP cloaking (it is the reference the\n * browser measures cloaking against).\n *\n * Register it as a global request middleware:\n * ```ts\n * // start.ts\n * import { createStart } from '@tanstack/react-start'\n * import { clickIdMiddleware } from '@shware/analytics/tanstack'\n * export const startInstance = createStart(() => ({ requestMiddleware: [clickIdMiddleware] }))\n * ```\n *\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/fbp-and-fbc\n */\nexport function createClickIdMiddleware(options: ClickIdMiddlewareOptions = {}) {\n const { cacheControl = 'private, no-store' } = options;\n\n return createMiddleware({ type: 'request' }).server(async ({ request, next, handlerType }) => {\n const result = await next();\n\n // Skip serverFn RPC responses. 'router' covers SSR document requests *and* custom server\n // routes (API endpoints) — those also get cookies when the URL carries a click id.\n if (handlerType !== 'router') return result;\n if (options.shouldPersist && !options.shouldPersist(request)) return result;\n\n const { cookies } = resolveClickIdCookies({\n url: request.url,\n cookieHeader: request.headers.get('cookie'),\n domain: options.domain,\n secure: options.secure,\n subdomainIndex: options.subdomainIndex,\n refresh: options.refresh ?? true,\n });\n\n if (cookies.length > 0) {\n for (const header of toSetCookieHeaders(cookies)) {\n result.response.headers.append('set-cookie', header);\n }\n if (cacheControl !== false) {\n result.response.headers.set('cache-control', cacheControl);\n }\n }\n\n return result;\n });\n}\n\n/** Ready-to-register middleware with default options. */\nexport const clickIdMiddleware = createClickIdMiddleware();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmDA,SAAgB,wBAAwB,UAAoC,CAAC,GAAG;CAC9E,MAAM,EAAE,eAAe,wBAAwB;CAE/C,QAAA,GAAA,sBAAA,iBAAA,CAAwB,EAAE,MAAM,UAAU,CAAC,CAAC,CAAC,OAAO,OAAO,EAAE,SAAS,MAAM,kBAAkB;EAC5F,MAAM,SAAS,MAAM,KAAK;EAI1B,IAAI,gBAAgB,UAAU,OAAO;EACrC,IAAI,QAAQ,iBAAiB,CAAC,QAAQ,cAAc,OAAO,GAAG,OAAO;EAErE,MAAM,EAAE,YAAYA,uBAAAA,sBAAsB;GACxC,KAAK,QAAQ;GACb,cAAc,QAAQ,QAAQ,IAAI,QAAQ;GAC1C,QAAQ,QAAQ;GAChB,QAAQ,QAAQ;GAChB,gBAAgB,QAAQ;GACxB,SAAS,QAAQ,WAAW;EAC9B,CAAC;EAED,IAAI,QAAQ,SAAS,GAAG;GACtB,KAAK,MAAM,UAAUC,uBAAAA,mBAAmB,OAAO,GAC7C,OAAO,SAAS,QAAQ,OAAO,cAAc,MAAM;GAErD,IAAI,iBAAiB,OACnB,OAAO,SAAS,QAAQ,IAAI,iBAAiB,YAAY;EAE7D;EAEA,OAAO;CACT,CAAC;AACH;;AAGA,MAAa,oBAAoB,wBAAwB"}
|