@shware/analytics 2.1.5 → 2.1.6
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/next/index.cjs +40 -20
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +3 -1
- package/dist/next/index.d.ts +3 -1
- package/dist/next/index.mjs +40 -20
- package/dist/next/index.mjs.map +1 -1
- package/dist/react-router/index.cjs +41 -20
- package/dist/react-router/index.cjs.map +1 -1
- package/dist/react-router/index.d.cts +3 -1
- package/dist/react-router/index.d.ts +3 -1
- package/dist/react-router/index.mjs +41 -20
- package/dist/react-router/index.mjs.map +1 -1
- package/dist/schema/index.d.cts +2 -2
- package/dist/schema/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/next/index.cjs
CHANGED
|
@@ -70,6 +70,7 @@ function Analytics({
|
|
|
70
70
|
nonce,
|
|
71
71
|
debugMode,
|
|
72
72
|
pixelId,
|
|
73
|
+
hotjarId,
|
|
73
74
|
facebookAppId,
|
|
74
75
|
reportWebVitals = true
|
|
75
76
|
}) {
|
|
@@ -136,34 +137,53 @@ function Analytics({
|
|
|
136
137
|
}
|
|
137
138
|
)
|
|
138
139
|
] }),
|
|
139
|
-
pixelId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
140
|
+
pixelId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
140
141
|
import_script.default,
|
|
141
142
|
{
|
|
142
143
|
id: "pixel",
|
|
143
144
|
strategy: "afterInteractive",
|
|
144
145
|
dangerouslySetInnerHTML: {
|
|
145
146
|
__html: `
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
147
|
+
!(function (f, b, e, v, n, t, s) {
|
|
148
|
+
if (f.fbq) return;
|
|
149
|
+
n = f.fbq = function () {
|
|
150
|
+
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
151
|
+
};
|
|
152
|
+
if (!f._fbq) f._fbq = n;
|
|
153
|
+
n.push = n;
|
|
154
|
+
n.loaded = !0;
|
|
155
|
+
n.version = '2.0';
|
|
156
|
+
n.queue = [];
|
|
157
|
+
t = b.createElement(e);
|
|
158
|
+
t.async = !0;
|
|
159
|
+
t.src = v;
|
|
160
|
+
s = b.getElementsByTagName(e)[0];
|
|
161
|
+
s.parentNode.insertBefore(t, s);
|
|
162
|
+
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
163
|
+
fbq('init', '${pixelId}');
|
|
164
|
+
fbq('track', 'PageView');`
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
|
-
)
|
|
167
|
+
),
|
|
168
|
+
hotjarId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
169
|
+
import_script.default,
|
|
170
|
+
{
|
|
171
|
+
id: "hotjar",
|
|
172
|
+
strategy: "afterInteractive",
|
|
173
|
+
dangerouslySetInnerHTML: {
|
|
174
|
+
__html: `
|
|
175
|
+
(function(h,o,t,j,a,r){
|
|
176
|
+
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
|
177
|
+
h._hjSettings={hjid:${hotjarId},hjsv:6};
|
|
178
|
+
a=o.getElementsByTagName('head')[0];
|
|
179
|
+
r=o.createElement('script');r.async=1;
|
|
180
|
+
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
|
181
|
+
a.appendChild(r);
|
|
182
|
+
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
|
183
|
+
`
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
)
|
|
167
187
|
] });
|
|
168
188
|
}
|
|
169
189
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/next/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { useEffect } from 'react';\nimport { getLink, type Link } from '../link/index';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (!window.gtag) {\n console.warn('GA has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const pathname = usePathname();\n\n useEffect(() => {\n const trackUTM = async () => {\n const params = new URLSearchParams(document.location.search);\n let link: Link | null = null;\n if (params.has('s')) link = await getLink(params.get('s')!);\n\n const properties = {\n pathname,\n referrer: document.referrer,\n fbclid: params.get('fbclid'),\n gclid: params.get('gclid'),\n gad_source: params.get('gad_source'),\n gad_campaignid: params.get('gad_campaignid'),\n utm_source: link?.utm_source ?? params.get('utm_source'),\n utm_medium: link?.utm_medium ?? params.get('utm_medium'),\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign'),\n utm_term: link?.utm_term ?? params.get('utm_term'),\n utm_content: link?.utm_content ?? params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n };\n\n trackUTM();\n }, [pathname]);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n 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 id=\"gtag\"\n nonce={nonce}\n src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <Script\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 {pixelId && (\n
|
|
1
|
+
{"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { useEffect } from 'react';\nimport { getLink, type Link } from '../link/index';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ntype HotjarId = `${number}`;\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (!window.gtag) {\n console.warn('GA has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const pathname = usePathname();\n\n useEffect(() => {\n const trackUTM = async () => {\n const params = new URLSearchParams(document.location.search);\n let link: Link | null = null;\n if (params.has('s')) link = await getLink(params.get('s')!);\n\n const properties = {\n pathname,\n referrer: document.referrer,\n fbclid: params.get('fbclid'),\n gclid: params.get('gclid'),\n gad_source: params.get('gad_source'),\n gad_campaignid: params.get('gad_campaignid'),\n utm_source: link?.utm_source ?? params.get('utm_source'),\n utm_medium: link?.utm_medium ?? params.get('utm_medium'),\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign'),\n utm_term: link?.utm_term ?? params.get('utm_term'),\n utm_content: link?.utm_content ?? params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n };\n\n trackUTM();\n }, [pathname]);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n 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 id=\"gtag\"\n nonce={nonce}\n src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <Script\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 {pixelId && (\n <Script\n id=\"pixel\"\n strategy=\"afterInteractive\"\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', '${pixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {hotjarId && (\n <Script\n id=\"hotjar\"\n strategy=\"afterInteractive\"\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wBAA4B;AAC5B,oBAAmB;AACnB,wBAAmC;AACnC,mBAA0B;A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AAA;AAAA,IACF;AAAA,IAED,YACC;AAAA,MAAC,cAAAA;AAAA,MAAA;AAAA,QACC,IAAG;AAAA,QACH,UAAS;AAAA,QACT,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA,oCAGgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOlC;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":["Script"]}
|
package/dist/next/index.d.cts
CHANGED
|
@@ -3,6 +3,7 @@ import { Pixel, PixelId } from '../track/fbq.cjs';
|
|
|
3
3
|
import { Gtag, GaId, GtmId } from '../track/gtag.cjs';
|
|
4
4
|
import { EventName, TrackName, TrackProperties } from '../track/types.cjs';
|
|
5
5
|
|
|
6
|
+
type HotjarId = `${number}`;
|
|
6
7
|
declare global {
|
|
7
8
|
interface Window extends Gtag, Pixel {
|
|
8
9
|
}
|
|
@@ -11,6 +12,7 @@ interface Props {
|
|
|
11
12
|
gaId?: GaId;
|
|
12
13
|
gtmId?: GtmId;
|
|
13
14
|
pixelId?: PixelId;
|
|
15
|
+
hotjarId?: HotjarId;
|
|
14
16
|
facebookAppId?: string;
|
|
15
17
|
nonce?: string;
|
|
16
18
|
debugMode?: boolean;
|
|
@@ -18,6 +20,6 @@ interface Props {
|
|
|
18
20
|
}
|
|
19
21
|
declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
|
|
20
22
|
declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): void;
|
|
21
|
-
declare function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
|
|
23
|
+
declare function Analytics({ gaId, nonce, debugMode, pixelId, hotjarId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
|
|
22
24
|
|
|
23
25
|
export { Analytics, sendFBEvent, sendGAEvent };
|
package/dist/next/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Pixel, PixelId } from '../track/fbq.js';
|
|
|
3
3
|
import { Gtag, GaId, GtmId } from '../track/gtag.js';
|
|
4
4
|
import { EventName, TrackName, TrackProperties } from '../track/types.js';
|
|
5
5
|
|
|
6
|
+
type HotjarId = `${number}`;
|
|
6
7
|
declare global {
|
|
7
8
|
interface Window extends Gtag, Pixel {
|
|
8
9
|
}
|
|
@@ -11,6 +12,7 @@ interface Props {
|
|
|
11
12
|
gaId?: GaId;
|
|
12
13
|
gtmId?: GtmId;
|
|
13
14
|
pixelId?: PixelId;
|
|
15
|
+
hotjarId?: HotjarId;
|
|
14
16
|
facebookAppId?: string;
|
|
15
17
|
nonce?: string;
|
|
16
18
|
debugMode?: boolean;
|
|
@@ -18,6 +20,6 @@ interface Props {
|
|
|
18
20
|
}
|
|
19
21
|
declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
|
|
20
22
|
declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): void;
|
|
21
|
-
declare function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
|
|
23
|
+
declare function Analytics({ gaId, nonce, debugMode, pixelId, hotjarId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
|
|
22
24
|
|
|
23
25
|
export { Analytics, sendFBEvent, sendGAEvent };
|
package/dist/next/index.mjs
CHANGED
|
@@ -35,6 +35,7 @@ function Analytics({
|
|
|
35
35
|
nonce,
|
|
36
36
|
debugMode,
|
|
37
37
|
pixelId,
|
|
38
|
+
hotjarId,
|
|
38
39
|
facebookAppId,
|
|
39
40
|
reportWebVitals = true
|
|
40
41
|
}) {
|
|
@@ -101,34 +102,53 @@ function Analytics({
|
|
|
101
102
|
}
|
|
102
103
|
)
|
|
103
104
|
] }),
|
|
104
|
-
pixelId && /* @__PURE__ */ jsx(
|
|
105
|
+
pixelId && /* @__PURE__ */ jsx(
|
|
105
106
|
Script,
|
|
106
107
|
{
|
|
107
108
|
id: "pixel",
|
|
108
109
|
strategy: "afterInteractive",
|
|
109
110
|
dangerouslySetInnerHTML: {
|
|
110
111
|
__html: `
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
112
|
+
!(function (f, b, e, v, n, t, s) {
|
|
113
|
+
if (f.fbq) return;
|
|
114
|
+
n = f.fbq = function () {
|
|
115
|
+
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
116
|
+
};
|
|
117
|
+
if (!f._fbq) f._fbq = n;
|
|
118
|
+
n.push = n;
|
|
119
|
+
n.loaded = !0;
|
|
120
|
+
n.version = '2.0';
|
|
121
|
+
n.queue = [];
|
|
122
|
+
t = b.createElement(e);
|
|
123
|
+
t.async = !0;
|
|
124
|
+
t.src = v;
|
|
125
|
+
s = b.getElementsByTagName(e)[0];
|
|
126
|
+
s.parentNode.insertBefore(t, s);
|
|
127
|
+
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
128
|
+
fbq('init', '${pixelId}');
|
|
129
|
+
fbq('track', 'PageView');`
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
|
-
)
|
|
132
|
+
),
|
|
133
|
+
hotjarId && /* @__PURE__ */ jsx(
|
|
134
|
+
Script,
|
|
135
|
+
{
|
|
136
|
+
id: "hotjar",
|
|
137
|
+
strategy: "afterInteractive",
|
|
138
|
+
dangerouslySetInnerHTML: {
|
|
139
|
+
__html: `
|
|
140
|
+
(function(h,o,t,j,a,r){
|
|
141
|
+
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
|
142
|
+
h._hjSettings={hjid:${hotjarId},hjsv:6};
|
|
143
|
+
a=o.getElementsByTagName('head')[0];
|
|
144
|
+
r=o.createElement('script');r.async=1;
|
|
145
|
+
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
|
146
|
+
a.appendChild(r);
|
|
147
|
+
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
|
148
|
+
`
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
)
|
|
132
152
|
] });
|
|
133
153
|
}
|
|
134
154
|
export {
|
package/dist/next/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { useEffect } from 'react';\nimport { getLink, type Link } from '../link/index';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (!window.gtag) {\n console.warn('GA has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const pathname = usePathname();\n\n useEffect(() => {\n const trackUTM = async () => {\n const params = new URLSearchParams(document.location.search);\n let link: Link | null = null;\n if (params.has('s')) link = await getLink(params.get('s')!);\n\n const properties = {\n pathname,\n referrer: document.referrer,\n fbclid: params.get('fbclid'),\n gclid: params.get('gclid'),\n gad_source: params.get('gad_source'),\n gad_campaignid: params.get('gad_campaignid'),\n utm_source: link?.utm_source ?? params.get('utm_source'),\n utm_medium: link?.utm_medium ?? params.get('utm_medium'),\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign'),\n utm_term: link?.utm_term ?? params.get('utm_term'),\n utm_content: link?.utm_content ?? params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n };\n\n trackUTM();\n }, [pathname]);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n 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 id=\"gtag\"\n nonce={nonce}\n src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <Script\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 {pixelId && (\n
|
|
1
|
+
{"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname } from 'next/navigation';\nimport Script from 'next/script';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { useEffect } from 'react';\nimport { getLink, type Link } from '../link/index';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ntype HotjarId = `${number}`;\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (!window.gtag) {\n console.warn('GA has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const pathname = usePathname();\n\n useEffect(() => {\n const trackUTM = async () => {\n const params = new URLSearchParams(document.location.search);\n let link: Link | null = null;\n if (params.has('s')) link = await getLink(params.get('s')!);\n\n const properties = {\n pathname,\n referrer: document.referrer,\n fbclid: params.get('fbclid'),\n gclid: params.get('gclid'),\n gad_source: params.get('gad_source'),\n gad_campaignid: params.get('gad_campaignid'),\n utm_source: link?.utm_source ?? params.get('utm_source'),\n utm_medium: link?.utm_medium ?? params.get('utm_medium'),\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign'),\n utm_term: link?.utm_term ?? params.get('utm_term'),\n utm_content: link?.utm_content ?? params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n };\n\n trackUTM();\n }, [pathname]);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n 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 id=\"gtag\"\n nonce={nonce}\n src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <Script\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 {pixelId && (\n <Script\n id=\"pixel\"\n strategy=\"afterInteractive\"\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', '${pixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {hotjarId && (\n <Script\n id=\"hotjar\"\n strategy=\"afterInteractive\"\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":";;;AAEA,SAAS,mBAAmB;AAC5B,OAAO,YAAY;AACnB,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,eAA0B;AACnC,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AAwGE,SAEhB,UAFgB,KAEhB,YAFgB;AAlFjB,SAAS,YACd,MACA,YACA;AACA,MAAI,CAAC,OAAO,MAAM;AAChB,YAAQ,KAAK,6BAA6B;AAC1C;AAAA,EACF;AACA,SAAO,KAAK,SAAS,MAAM,UAAU;AACvC;AAEO,SAAS,YACd,MACA,YACA,UACA;AACA,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;AAChD,YAAQ,KAAK,8BAA8B;AAC3C;AAAA,EACF;AACA,QAAM,EAAE,IAAI,IAAI;AAChB,QAAM,UAAU,EAAE,SAAS,SAAS;AACpC,QAAM,CAAC,MAAM,aAAa,iBAAiB,IAAI,WAAW,MAAM,UAAU;AAC1E,MAAI,SAAS,SAAS;AACpB,QAAI,MAAM,aAAa,mBAAmB,OAAO;AAAA,EACnD,OAAO;AACL,QAAI,MAAM,aAAa,mBAAmB,OAAO;AAAA,EACnD;AACF;AAEO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AACpB,GAAU;AACR,QAAM,WAAW,YAAY;AAE7B,YAAU,MAAM;AACd,UAAM,WAAW,YAAY;AAC3B,YAAM,SAAS,IAAI,gBAAgB,SAAS,SAAS,MAAM;AAC3D,UAAI,OAAoB;AACxB,UAAI,OAAO,IAAI,GAAG,EAAG,QAAO,MAAM,QAAQ,OAAO,IAAI,GAAG,CAAE;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AAAA;AAAA,MACF;AAAA,OACF;AAAA,IAED,WACC;AAAA,MAAC;AAAA;AAAA,QACC,IAAG;AAAA,QACH,UAAS;AAAA,QACT,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAiBO,OAAO;AAAA;AAAA,QAExB;AAAA;AAAA,IACF;AAAA,IAED,YACC;AAAA,MAAC;AAAA;AAAA,QACC,IAAG;AAAA,QACH,UAAS;AAAA,QACT,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA,oCAGgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOlC;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -67,6 +67,7 @@ function Analytics({
|
|
|
67
67
|
nonce,
|
|
68
68
|
debugMode,
|
|
69
69
|
pixelId,
|
|
70
|
+
hotjarId,
|
|
70
71
|
facebookAppId,
|
|
71
72
|
reportWebVitals = true
|
|
72
73
|
}) {
|
|
@@ -135,33 +136,53 @@ function Analytics({
|
|
|
135
136
|
}
|
|
136
137
|
)
|
|
137
138
|
] }),
|
|
138
|
-
pixelId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
139
|
+
pixelId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
139
140
|
"script",
|
|
140
141
|
{
|
|
142
|
+
async: true,
|
|
141
143
|
id: "pixel",
|
|
142
144
|
dangerouslySetInnerHTML: {
|
|
143
145
|
__html: `
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
146
|
+
!(function (f, b, e, v, n, t, s) {
|
|
147
|
+
if (f.fbq) return;
|
|
148
|
+
n = f.fbq = function () {
|
|
149
|
+
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
150
|
+
};
|
|
151
|
+
if (!f._fbq) f._fbq = n;
|
|
152
|
+
n.push = n;
|
|
153
|
+
n.loaded = !0;
|
|
154
|
+
n.version = '2.0';
|
|
155
|
+
n.queue = [];
|
|
156
|
+
t = b.createElement(e);
|
|
157
|
+
t.async = !0;
|
|
158
|
+
t.src = v;
|
|
159
|
+
s = b.getElementsByTagName(e)[0];
|
|
160
|
+
s.parentNode.insertBefore(t, s);
|
|
161
|
+
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
162
|
+
fbq('init', '${pixelId}');
|
|
163
|
+
fbq('track', 'PageView');`
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
|
-
)
|
|
166
|
+
),
|
|
167
|
+
hotjarId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
168
|
+
"script",
|
|
169
|
+
{
|
|
170
|
+
async: true,
|
|
171
|
+
id: "hotjar",
|
|
172
|
+
dangerouslySetInnerHTML: {
|
|
173
|
+
__html: `
|
|
174
|
+
(function(h,o,t,j,a,r){
|
|
175
|
+
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
|
176
|
+
h._hjSettings={hjid:${hotjarId},hjsv:6};
|
|
177
|
+
a=o.getElementsByTagName('head')[0];
|
|
178
|
+
r=o.createElement('script');r.async=1;
|
|
179
|
+
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
|
180
|
+
a.appendChild(r);
|
|
181
|
+
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
|
182
|
+
`
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
)
|
|
165
186
|
] });
|
|
166
187
|
}
|
|
167
188
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation, useSearchParams } from 'react-router';\nimport { onLCP, onCLS, onINP, onFCP, onTTFB, type Metric } from 'web-vitals';\nimport { getLink, type Link } from '../link/index';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('gtag has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const { pathname } = useLocation();\n const [params] = useSearchParams();\n\n useEffect(() => {\n const trackUTM = async () => {\n let link: Link | null = null;\n if (params.has('s')) link = await getLink(params.get('s')!);\n\n const properties = {\n pathname,\n referrer: document.referrer,\n fbclid: params.get('fbclid'),\n gclid: params.get('gclid'),\n gad_source: params.get('gad_source'),\n gad_campaignid: params.get('gad_campaignid'),\n utm_source: link?.utm_source ?? params.get('utm_source'),\n utm_medium: link?.utm_medium ?? params.get('utm_medium'),\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign'),\n utm_term: link?.utm_term ?? params.get('utm_term'),\n utm_content: link?.utm_content ?? params.get('utm_content'),\n };\n\n /**\n * Pixel:\n * Each time the Pixel loads, it automatically calls fbq('track', 'PageView') to track a\n * PageView standard event.\n */\n track('page_view', properties, { enableThirdPartyTracking: false });\n };\n\n trackUTM();\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n 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={`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 {pixelId && (\n
|
|
1
|
+
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation, useSearchParams } from 'react-router';\nimport { onLCP, onCLS, onINP, onFCP, onTTFB, type Metric } from 'web-vitals';\nimport { getLink, type Link } from '../link/index';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ntype HotjarId = `${number}`;\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('gtag has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const { pathname } = useLocation();\n const [params] = useSearchParams();\n\n useEffect(() => {\n const trackUTM = async () => {\n let link: Link | null = null;\n if (params.has('s')) link = await getLink(params.get('s')!);\n\n const properties = {\n pathname,\n referrer: document.referrer,\n fbclid: params.get('fbclid'),\n gclid: params.get('gclid'),\n gad_source: params.get('gad_source'),\n gad_campaignid: params.get('gad_campaignid'),\n utm_source: link?.utm_source ?? params.get('utm_source'),\n utm_medium: link?.utm_medium ?? params.get('utm_medium'),\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign'),\n utm_term: link?.utm_term ?? params.get('utm_term'),\n utm_content: link?.utm_content ?? params.get('utm_content'),\n };\n\n /**\n * Pixel:\n * Each time the Pixel loads, it automatically calls fbq('track', 'PageView') to track a\n * PageView standard event.\n */\n track('page_view', properties, { enableThirdPartyTracking: false });\n };\n\n trackUTM();\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n 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={`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 {pixelId && (\n <script\n async\n id=\"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', '${pixelId}');\n fbq('track', 'PageView');`,\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,0BAA6C;AAC7C,wBAAgE;AAChE,kBAAmC;AACnC,iBAA2B;AAC3B,mBAAsB;AAuHE;AAhHxB,SAAS,mBAAmB,mBAA6C;AACvE,8BAAU,MAAM;AACd,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,kCAAO,iBAAiB;AAAA,EAC1B,GAAG,CAAC,iBAAiB,CAAC;AACxB;AAiBO,SAAS,YACd,MACA,YACA;AACA,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;AACjD,YAAQ,KAAK,+BAA+B;AAC5C;AAAA,EACF;AACA,SAAO,KAAK,SAAS,MAAM,UAAU;AACvC;AAEO,SAAS,YACd,MACA,YACA,UACA;AACA,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;AAChD,YAAQ,KAAK,8BAA8B;AAC3C;AAAA,EACF;AACA,QAAM,EAAE,IAAI,IAAI;AAChB,QAAM,UAAU,EAAE,SAAS,SAAS;AACpC,QAAM,CAAC,MAAM,aAAa,iBAAiB,QAAI,uBAAW,MAAM,UAAU;AAC1E,MAAI,SAAS,SAAS;AACpB,QAAI,MAAM,aAAa,mBAAmB,OAAO;AAAA,EACnD,OAAO;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UAAU;AAAA,EAC/B,CAAC;AAED,SACE,4EACG;AAAA,qBAAiB,4CAAC,UAAK,UAAS,aAAY,SAAS,eAAe;AAAA,IACpE,QACC,4EACE;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,OAAK;AAAA,UACL,IAAG;AAAA,UACH;AAAA,UACA,KAAK,+CAA+C,IAAI;AAAA;AAAA,MAC1D;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACC,OAAK;AAAA,UACL;AAAA,UACA,IAAG;AAAA,UACH,yBAAyB;AAAA,YACvB,QAAQ;AAAA;AAAA;AAAA;AAAA,gCAIU,IAAI,IAAI,YAAY,6BAA6B,EAAE;AAAA;AAAA,UAEvE;AAAA;AAAA,MACF;AAAA,OACF;AAAA,IAED,WACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAK;AAAA,QACL,IAAG;AAAA,QACH,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAiBO,OAAO;AAAA;AAAA,QAExB;AAAA;AAAA,IACF;AAAA,IAED,YACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAK;AAAA,QACL,IAAG;AAAA,QACH,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA,oCAGgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOlC;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -3,6 +3,7 @@ import { Pixel, PixelId } from '../track/fbq.cjs';
|
|
|
3
3
|
import { Gtag, GaId, GtmId } from '../track/gtag.cjs';
|
|
4
4
|
import { EventName, TrackName, TrackProperties } from '../track/types.cjs';
|
|
5
5
|
|
|
6
|
+
type HotjarId = `${number}`;
|
|
6
7
|
declare global {
|
|
7
8
|
interface Window extends Gtag, Pixel {
|
|
8
9
|
}
|
|
@@ -11,6 +12,7 @@ interface Props {
|
|
|
11
12
|
gaId?: GaId;
|
|
12
13
|
gtmId?: GtmId;
|
|
13
14
|
pixelId?: PixelId;
|
|
15
|
+
hotjarId?: HotjarId;
|
|
14
16
|
facebookAppId?: string;
|
|
15
17
|
nonce?: string;
|
|
16
18
|
debugMode?: boolean;
|
|
@@ -18,6 +20,6 @@ interface Props {
|
|
|
18
20
|
}
|
|
19
21
|
declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
|
|
20
22
|
declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): void;
|
|
21
|
-
declare function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
|
|
23
|
+
declare function Analytics({ gaId, nonce, debugMode, pixelId, hotjarId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
|
|
22
24
|
|
|
23
25
|
export { Analytics, sendFBEvent, sendGAEvent };
|
|
@@ -3,6 +3,7 @@ import { Pixel, PixelId } from '../track/fbq.js';
|
|
|
3
3
|
import { Gtag, GaId, GtmId } from '../track/gtag.js';
|
|
4
4
|
import { EventName, TrackName, TrackProperties } from '../track/types.js';
|
|
5
5
|
|
|
6
|
+
type HotjarId = `${number}`;
|
|
6
7
|
declare global {
|
|
7
8
|
interface Window extends Gtag, Pixel {
|
|
8
9
|
}
|
|
@@ -11,6 +12,7 @@ interface Props {
|
|
|
11
12
|
gaId?: GaId;
|
|
12
13
|
gtmId?: GtmId;
|
|
13
14
|
pixelId?: PixelId;
|
|
15
|
+
hotjarId?: HotjarId;
|
|
14
16
|
facebookAppId?: string;
|
|
15
17
|
nonce?: string;
|
|
16
18
|
debugMode?: boolean;
|
|
@@ -18,6 +20,6 @@ interface Props {
|
|
|
18
20
|
}
|
|
19
21
|
declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
|
|
20
22
|
declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): void;
|
|
21
|
-
declare function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
|
|
23
|
+
declare function Analytics({ gaId, nonce, debugMode, pixelId, hotjarId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
|
|
22
24
|
|
|
23
25
|
export { Analytics, sendFBEvent, sendGAEvent };
|
|
@@ -41,6 +41,7 @@ function Analytics({
|
|
|
41
41
|
nonce,
|
|
42
42
|
debugMode,
|
|
43
43
|
pixelId,
|
|
44
|
+
hotjarId,
|
|
44
45
|
facebookAppId,
|
|
45
46
|
reportWebVitals = true
|
|
46
47
|
}) {
|
|
@@ -109,33 +110,53 @@ function Analytics({
|
|
|
109
110
|
}
|
|
110
111
|
)
|
|
111
112
|
] }),
|
|
112
|
-
pixelId && /* @__PURE__ */ jsx(
|
|
113
|
+
pixelId && /* @__PURE__ */ jsx(
|
|
113
114
|
"script",
|
|
114
115
|
{
|
|
116
|
+
async: true,
|
|
115
117
|
id: "pixel",
|
|
116
118
|
dangerouslySetInnerHTML: {
|
|
117
119
|
__html: `
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
120
|
+
!(function (f, b, e, v, n, t, s) {
|
|
121
|
+
if (f.fbq) return;
|
|
122
|
+
n = f.fbq = function () {
|
|
123
|
+
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
124
|
+
};
|
|
125
|
+
if (!f._fbq) f._fbq = n;
|
|
126
|
+
n.push = n;
|
|
127
|
+
n.loaded = !0;
|
|
128
|
+
n.version = '2.0';
|
|
129
|
+
n.queue = [];
|
|
130
|
+
t = b.createElement(e);
|
|
131
|
+
t.async = !0;
|
|
132
|
+
t.src = v;
|
|
133
|
+
s = b.getElementsByTagName(e)[0];
|
|
134
|
+
s.parentNode.insertBefore(t, s);
|
|
135
|
+
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
136
|
+
fbq('init', '${pixelId}');
|
|
137
|
+
fbq('track', 'PageView');`
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
|
-
)
|
|
140
|
+
),
|
|
141
|
+
hotjarId && /* @__PURE__ */ jsx(
|
|
142
|
+
"script",
|
|
143
|
+
{
|
|
144
|
+
async: true,
|
|
145
|
+
id: "hotjar",
|
|
146
|
+
dangerouslySetInnerHTML: {
|
|
147
|
+
__html: `
|
|
148
|
+
(function(h,o,t,j,a,r){
|
|
149
|
+
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
|
150
|
+
h._hjSettings={hjid:${hotjarId},hjsv:6};
|
|
151
|
+
a=o.getElementsByTagName('head')[0];
|
|
152
|
+
r=o.createElement('script');r.async=1;
|
|
153
|
+
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
|
154
|
+
a.appendChild(r);
|
|
155
|
+
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
|
156
|
+
`
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
)
|
|
139
160
|
] });
|
|
140
161
|
}
|
|
141
162
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation, useSearchParams } from 'react-router';\nimport { onLCP, onCLS, onINP, onFCP, onTTFB, type Metric } from 'web-vitals';\nimport { getLink, type Link } from '../link/index';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('gtag has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const { pathname } = useLocation();\n const [params] = useSearchParams();\n\n useEffect(() => {\n const trackUTM = async () => {\n let link: Link | null = null;\n if (params.has('s')) link = await getLink(params.get('s')!);\n\n const properties = {\n pathname,\n referrer: document.referrer,\n fbclid: params.get('fbclid'),\n gclid: params.get('gclid'),\n gad_source: params.get('gad_source'),\n gad_campaignid: params.get('gad_campaignid'),\n utm_source: link?.utm_source ?? params.get('utm_source'),\n utm_medium: link?.utm_medium ?? params.get('utm_medium'),\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign'),\n utm_term: link?.utm_term ?? params.get('utm_term'),\n utm_content: link?.utm_content ?? params.get('utm_content'),\n };\n\n /**\n * Pixel:\n * Each time the Pixel loads, it automatically calls fbq('track', 'PageView') to track a\n * PageView standard event.\n */\n track('page_view', properties, { enableThirdPartyTracking: false });\n };\n\n trackUTM();\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n 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={`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 {pixelId && (\n
|
|
1
|
+
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation, useSearchParams } from 'react-router';\nimport { onLCP, onCLS, onINP, onFCP, onTTFB, type Metric } from 'web-vitals';\nimport { getLink, type Link } from '../link/index';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ntype HotjarId = `${number}`;\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('gtag has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const { pathname } = useLocation();\n const [params] = useSearchParams();\n\n useEffect(() => {\n const trackUTM = async () => {\n let link: Link | null = null;\n if (params.has('s')) link = await getLink(params.get('s')!);\n\n const properties = {\n pathname,\n referrer: document.referrer,\n fbclid: params.get('fbclid'),\n gclid: params.get('gclid'),\n gad_source: params.get('gad_source'),\n gad_campaignid: params.get('gad_campaignid'),\n utm_source: link?.utm_source ?? params.get('utm_source'),\n utm_medium: link?.utm_medium ?? params.get('utm_medium'),\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign'),\n utm_term: link?.utm_term ?? params.get('utm_term'),\n utm_content: link?.utm_content ?? params.get('utm_content'),\n };\n\n /**\n * Pixel:\n * Each time the Pixel loads, it automatically calls fbq('track', 'PageView') to track a\n * PageView standard event.\n */\n track('page_view', properties, { enableThirdPartyTracking: false });\n };\n\n trackUTM();\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n 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={`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 {pixelId && (\n <script\n async\n id=\"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', '${pixelId}');\n fbq('track', 'PageView');`,\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.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UACA,IAAG;AAAA,UACH,yBAAyB;AAAA,YACvB,QAAQ;AAAA;AAAA;AAAA;AAAA,gCAIU,IAAI,IAAI,YAAY,6BAA6B,EAAE;AAAA;AAAA,UAEvE;AAAA;AAAA,MACF;AAAA,OACF;AAAA,IAED,WACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAK;AAAA,QACL,IAAG;AAAA,QACH,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAiBO,OAAO;AAAA;AAAA,QAExB;AAAA;AAAA,IACF;AAAA,IAED,YACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAK;AAAA,QACL,IAAG;AAAA,QACH,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA,oCAGgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOlC;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":[]}
|
package/dist/schema/index.d.cts
CHANGED
|
@@ -13,13 +13,13 @@ declare const createTrackEventSchemaV1: z.ZodMiniArray<z.ZodMiniObject<{
|
|
|
13
13
|
browser_name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
14
14
|
browser_version: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
15
15
|
platform: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
16
|
+
unknown: "unknown";
|
|
16
17
|
ios: "ios";
|
|
17
18
|
android: "android";
|
|
18
19
|
web: "web";
|
|
19
20
|
macos: "macos";
|
|
20
21
|
windows: "windows";
|
|
21
22
|
linux: "linux";
|
|
22
|
-
unknown: "unknown";
|
|
23
23
|
}>>;
|
|
24
24
|
device: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
25
25
|
device_id: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
@@ -64,13 +64,13 @@ declare const createTrackEventSchema: z.ZodMiniArray<z.ZodMiniObject<{
|
|
|
64
64
|
browser_name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
65
65
|
browser_version: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
66
66
|
platform: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
67
|
+
unknown: "unknown";
|
|
67
68
|
ios: "ios";
|
|
68
69
|
android: "android";
|
|
69
70
|
web: "web";
|
|
70
71
|
macos: "macos";
|
|
71
72
|
windows: "windows";
|
|
72
73
|
linux: "linux";
|
|
73
|
-
unknown: "unknown";
|
|
74
74
|
}>>;
|
|
75
75
|
device: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
76
76
|
device_id: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -13,13 +13,13 @@ declare const createTrackEventSchemaV1: z.ZodMiniArray<z.ZodMiniObject<{
|
|
|
13
13
|
browser_name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
14
14
|
browser_version: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
15
15
|
platform: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
16
|
+
unknown: "unknown";
|
|
16
17
|
ios: "ios";
|
|
17
18
|
android: "android";
|
|
18
19
|
web: "web";
|
|
19
20
|
macos: "macos";
|
|
20
21
|
windows: "windows";
|
|
21
22
|
linux: "linux";
|
|
22
|
-
unknown: "unknown";
|
|
23
23
|
}>>;
|
|
24
24
|
device: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
25
25
|
device_id: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
@@ -64,13 +64,13 @@ declare const createTrackEventSchema: z.ZodMiniArray<z.ZodMiniObject<{
|
|
|
64
64
|
browser_name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
65
65
|
browser_version: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
66
66
|
platform: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
67
|
+
unknown: "unknown";
|
|
67
68
|
ios: "ios";
|
|
68
69
|
android: "android";
|
|
69
70
|
web: "web";
|
|
70
71
|
macos: "macos";
|
|
71
72
|
windows: "windows";
|
|
72
73
|
linux: "linux";
|
|
73
|
-
unknown: "unknown";
|
|
74
74
|
}>>;
|
|
75
75
|
device: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
76
76
|
device_id: z.ZodMiniOptional<z.ZodMiniString<string>>;
|