@shware/analytics 0.1.17 → 0.1.18
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/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs.map +1 -1
- package/dist/next/index.cjs +102 -5
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +21 -2
- package/dist/next/index.d.ts +21 -2
- package/dist/next/index.mjs +89 -4
- package/dist/next/index.mjs.map +1 -1
- package/dist/react-router/index.cjs +91 -4
- package/dist/react-router/index.cjs.map +1 -1
- package/dist/react-router/index.d.cts +21 -2
- package/dist/react-router/index.d.ts +21 -2
- package/dist/react-router/index.mjs +88 -3
- package/dist/react-router/index.mjs.map +1 -1
- package/dist/schema/index.d.cts +8 -8
- package/dist/schema/index.d.ts +8 -8
- package/dist/setup/index.cjs.map +1 -1
- package/dist/setup/index.d.cts +3 -1
- package/dist/setup/index.d.ts +3 -1
- package/dist/setup/index.mjs.map +1 -1
- package/dist/track/fbq.cjs +143 -0
- package/dist/track/fbq.cjs.map +1 -0
- package/dist/track/fbq.d.cts +278 -0
- package/dist/track/fbq.d.ts +278 -0
- package/dist/track/fbq.mjs +117 -0
- package/dist/track/fbq.mjs.map +1 -0
- package/dist/track/{ga.cjs → gtag.cjs} +5 -5
- package/dist/track/gtag.cjs.map +1 -0
- package/dist/track/gtag.d.cts +463 -0
- package/dist/track/gtag.d.ts +463 -0
- package/dist/track/{ga.mjs → gtag.mjs} +2 -2
- package/dist/track/gtag.mjs.map +1 -0
- package/dist/track/index.cjs.map +1 -1
- package/dist/track/index.d.cts +3 -2
- package/dist/track/index.d.ts +3 -2
- package/dist/track/index.mjs.map +1 -1
- package/dist/{types/index.cjs → track/types.cjs} +2 -2
- package/dist/track/types.cjs.map +1 -0
- package/dist/track/types.d.cts +87 -0
- package/dist/track/types.d.ts +87 -0
- package/dist/track/types.mjs +1 -0
- package/dist/visitor/index.cjs.map +1 -1
- package/dist/visitor/index.d.cts +1 -1
- package/dist/visitor/index.d.ts +1 -1
- package/dist/visitor/index.mjs.map +1 -1
- package/dist/visitor/types.cjs +19 -0
- package/dist/visitor/types.cjs.map +1 -0
- package/dist/visitor/types.d.cts +16 -0
- package/dist/visitor/types.d.ts +16 -0
- package/dist/visitor/types.mjs +1 -0
- package/dist/visitor/types.mjs.map +1 -0
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +2 -1
- package/dist/web/index.d.ts +2 -1
- package/dist/web/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/track/ga.cjs.map +0 -1
- package/dist/track/ga.d.cts +0 -4
- package/dist/track/ga.d.ts +0 -4
- package/dist/track/ga.mjs.map +0 -1
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -327
- package/dist/types/index.d.ts +0 -327
- package/dist/types/index.mjs +0 -1
- /package/dist/{types/index.mjs.map → track/types.mjs.map} +0 -0
|
@@ -3,6 +3,8 @@ import { useEffect } from "react";
|
|
|
3
3
|
import { useLocation, useSearchParams } from "react-router";
|
|
4
4
|
import { onLCP, onFID, onCLS, onINP, onFCP, onTTFB } from "web-vitals";
|
|
5
5
|
import { track } from "../track/index.mjs";
|
|
6
|
+
import { mapAndSendFbqEvent } from "../track/fbq.mjs";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
8
|
function useReportWebVitals(reportWebVitalsFn) {
|
|
7
9
|
useEffect(() => {
|
|
8
10
|
onCLS(reportWebVitalsFn);
|
|
@@ -13,7 +15,21 @@ function useReportWebVitals(reportWebVitalsFn) {
|
|
|
13
15
|
onTTFB(reportWebVitalsFn);
|
|
14
16
|
}, [reportWebVitalsFn]);
|
|
15
17
|
}
|
|
16
|
-
function
|
|
18
|
+
function sendGAEvent(name, properties) {
|
|
19
|
+
if (typeof window === "undefined" || !window.gtag) {
|
|
20
|
+
console.warn("gtag has not been initialized");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
window.gtag("event", name, properties);
|
|
24
|
+
}
|
|
25
|
+
function sendFBEvent(name, properties, event_id) {
|
|
26
|
+
if (typeof window === "undefined" || !window.fbq) {
|
|
27
|
+
console.warn("fbq has not been initialized");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
mapAndSendFbqEvent(window.fbq, name, properties, { eventID: event_id });
|
|
31
|
+
}
|
|
32
|
+
function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }) {
|
|
17
33
|
const { pathname } = useLocation();
|
|
18
34
|
const [params] = useSearchParams();
|
|
19
35
|
useEffect(() => {
|
|
@@ -42,9 +58,78 @@ function Analytics() {
|
|
|
42
58
|
};
|
|
43
59
|
track(metric.name, properties);
|
|
44
60
|
});
|
|
45
|
-
return
|
|
61
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
62
|
+
facebookAppId && /* @__PURE__ */ jsx("meta", { property: "fb:app_id", content: facebookAppId }),
|
|
63
|
+
gaId && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
64
|
+
/* @__PURE__ */ jsx(
|
|
65
|
+
"script",
|
|
66
|
+
{
|
|
67
|
+
async: true,
|
|
68
|
+
id: "gtag",
|
|
69
|
+
nonce,
|
|
70
|
+
src: `https://www.googletagmanager.com/gtag/js?id=${gaId}`
|
|
71
|
+
}
|
|
72
|
+
),
|
|
73
|
+
/* @__PURE__ */ jsx(
|
|
74
|
+
"script",
|
|
75
|
+
{
|
|
76
|
+
async: true,
|
|
77
|
+
nonce,
|
|
78
|
+
id: "gtag-init",
|
|
79
|
+
dangerouslySetInnerHTML: {
|
|
80
|
+
__html: `
|
|
81
|
+
window.dataLayer = window.dataLayer || [];
|
|
82
|
+
function gtag(){dataLayer.push(arguments);}
|
|
83
|
+
gtag('js', new Date());
|
|
84
|
+
gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
|
|
85
|
+
`
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
] }),
|
|
90
|
+
pixelId && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
91
|
+
/* @__PURE__ */ jsx(
|
|
92
|
+
"script",
|
|
93
|
+
{
|
|
94
|
+
id: "pixel",
|
|
95
|
+
dangerouslySetInnerHTML: {
|
|
96
|
+
__html: `
|
|
97
|
+
!(function (f, b, e, v, n, t, s) {
|
|
98
|
+
if (f.fbq) return;
|
|
99
|
+
n = f.fbq = function () {
|
|
100
|
+
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
101
|
+
};
|
|
102
|
+
if (!f._fbq) f._fbq = n;
|
|
103
|
+
n.push = n;
|
|
104
|
+
n.loaded = !0;
|
|
105
|
+
n.version = '2.0';
|
|
106
|
+
n.queue = [];
|
|
107
|
+
t = b.createElement(e);
|
|
108
|
+
t.async = !0;
|
|
109
|
+
t.src = v;
|
|
110
|
+
s = b.getElementsByTagName(e)[0];
|
|
111
|
+
s.parentNode.insertBefore(t, s);
|
|
112
|
+
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
|
|
113
|
+
fbq('init', '${pixelId}');
|
|
114
|
+
fbq('track', 'PageView');`
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
/* @__PURE__ */ jsx("noscript", { children: /* @__PURE__ */ jsx(
|
|
119
|
+
"img",
|
|
120
|
+
{
|
|
121
|
+
width: "1",
|
|
122
|
+
height: "1",
|
|
123
|
+
style: { display: "none" },
|
|
124
|
+
src: `https://www.facebook.com/tr?id=${pixelId}&ev=PageView&noscript=1`
|
|
125
|
+
}
|
|
126
|
+
) })
|
|
127
|
+
] })
|
|
128
|
+
] });
|
|
46
129
|
}
|
|
47
130
|
export {
|
|
48
|
-
Analytics
|
|
131
|
+
Analytics,
|
|
132
|
+
sendFBEvent,
|
|
133
|
+
sendGAEvent
|
|
49
134
|
};
|
|
50
135
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation, useSearchParams } from 'react-router';\nimport { onLCP, onFID, onCLS, onINP, onFCP, onTTFB, type Metric } from 'web-vitals';\nimport { track } from '../track/index';\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onFID(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\nexport function Analytics() {\n const { pathname } = useLocation();\n const [params] = useSearchParams();\n\n useEffect(() => {\n const properties = {\n pathname,\n referrer: document.referrer,\n gclid: params.get('gclid'),\n fbclid: params.get('fbclid'),\n utm_source: params.get('utm_source'),\n utm_medium: params.get('utm_medium'),\n utm_campaign: params.get('utm_campaign'),\n utm_term: params.get('utm_term'),\n utm_content: params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\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
|
|
1
|
+
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation, useSearchParams } from 'react-router';\nimport { onLCP, onFID, onCLS, onINP, onFCP, onTTFB, type Metric } from 'web-vitals';\nimport { track } from '../track/index';\nimport { mapAndSendFbqEvent } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { Fbq, PixelId } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onFID(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\ndeclare global {\n interface Window extends Gtag, Fbq {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: 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 mapAndSendFbqEvent(window.fbq, name, properties, { eventID: event_id });\n}\n\nexport function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }: Props) {\n const { pathname } = useLocation();\n const [params] = useSearchParams();\n\n useEffect(() => {\n const properties = {\n pathname,\n referrer: document.referrer,\n gclid: params.get('gclid'),\n fbclid: params.get('fbclid'),\n utm_source: params.get('utm_source'),\n utm_medium: params.get('utm_medium'),\n utm_campaign: params.get('utm_campaign'),\n utm_term: params.get('utm_term'),\n 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 }, [pathname, params]);\n\n useReportWebVitals((metric) => {\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 <>\n <script\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 <noscript>\n <img\n width=\"1\"\n height=\"1\"\n style={{ display: 'none' }}\n src={`https://www.facebook.com/tr?id=${pixelId}&ev=PageView&noscript=1`}\n />\n </noscript>\n </>\n )}\n </>\n );\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,aAAa,uBAAuB;AAC7C,SAAS,OAAO,OAAO,OAAO,OAAO,OAAO,cAA2B;AACvE,SAAS,aAAa;AACtB,SAAS,0BAA0B;AA2FX,SAEhB,UAFgB,KAEhB,YAFgB;AAtFxB,SAAS,mBAAmB,mBAA6C;AACvE,YAAU,MAAM;AACd,UAAM,iBAAiB;AACvB,UAAM,iBAAiB;AACvB,UAAM,iBAAiB;AACvB,UAAM,iBAAiB;AACvB,UAAM,iBAAiB;AACvB,WAAO,iBAAiB;AAAA,EAC1B,GAAG,CAAC,iBAAiB,CAAC;AACxB;AAeO,SAAS,YACd,MACA,YACA;AACA,MAAI,OAAO,W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C;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,iCACE;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,IAAG;AAAA,UACH,yBAAyB;AAAA,YACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAiBO,OAAO;AAAA;AAAA,UAExB;AAAA;AAAA,MACF;AAAA,MACA,oBAAC,cACC;AAAA,QAAC;AAAA;AAAA,UACC,OAAM;AAAA,UACN,QAAO;AAAA,UACP,OAAO,EAAE,SAAS,OAAO;AAAA,UACzB,KAAK,kCAAkC,OAAO;AAAA;AAAA,MAChD,GACF;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":[]}
|
package/dist/schema/index.d.cts
CHANGED
|
@@ -32,6 +32,8 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
32
32
|
utm_term: z.ZodOptional<z.ZodString>;
|
|
33
33
|
utm_content: z.ZodOptional<z.ZodString>;
|
|
34
34
|
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
language?: string | undefined;
|
|
36
|
+
screen_resolution?: `${number}x${number}` | undefined;
|
|
35
37
|
os?: string | undefined;
|
|
36
38
|
os_name?: string | undefined;
|
|
37
39
|
os_version?: string | undefined;
|
|
@@ -44,9 +46,7 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
44
46
|
device_type?: string | undefined;
|
|
45
47
|
device_vendor?: string | undefined;
|
|
46
48
|
device_pixel_ratio?: string | undefined;
|
|
47
|
-
screen_resolution?: `${number}x${number}` | undefined;
|
|
48
49
|
release?: string | undefined;
|
|
49
|
-
language?: string | undefined;
|
|
50
50
|
timezone?: string | undefined;
|
|
51
51
|
environment?: "development" | "production" | undefined;
|
|
52
52
|
source_url?: string | undefined;
|
|
@@ -60,6 +60,8 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
60
60
|
utm_term?: string | undefined;
|
|
61
61
|
utm_content?: string | undefined;
|
|
62
62
|
}, {
|
|
63
|
+
language?: string | undefined;
|
|
64
|
+
screen_resolution?: string | undefined;
|
|
63
65
|
os?: string | undefined;
|
|
64
66
|
os_name?: string | undefined;
|
|
65
67
|
os_version?: string | undefined;
|
|
@@ -72,9 +74,7 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
72
74
|
device_type?: string | undefined;
|
|
73
75
|
device_vendor?: string | undefined;
|
|
74
76
|
device_pixel_ratio?: string | undefined;
|
|
75
|
-
screen_resolution?: string | undefined;
|
|
76
77
|
release?: string | undefined;
|
|
77
|
-
language?: string | undefined;
|
|
78
78
|
timezone?: string | undefined;
|
|
79
79
|
environment?: "development" | "production" | undefined;
|
|
80
80
|
source_url?: string | undefined;
|
|
@@ -93,6 +93,8 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
93
93
|
visitor_id: bigint;
|
|
94
94
|
name: string;
|
|
95
95
|
tags: {
|
|
96
|
+
language?: string | undefined;
|
|
97
|
+
screen_resolution?: `${number}x${number}` | undefined;
|
|
96
98
|
os?: string | undefined;
|
|
97
99
|
os_name?: string | undefined;
|
|
98
100
|
os_version?: string | undefined;
|
|
@@ -105,9 +107,7 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
105
107
|
device_type?: string | undefined;
|
|
106
108
|
device_vendor?: string | undefined;
|
|
107
109
|
device_pixel_ratio?: string | undefined;
|
|
108
|
-
screen_resolution?: `${number}x${number}` | undefined;
|
|
109
110
|
release?: string | undefined;
|
|
110
|
-
language?: string | undefined;
|
|
111
111
|
timezone?: string | undefined;
|
|
112
112
|
environment?: "development" | "production" | undefined;
|
|
113
113
|
source_url?: string | undefined;
|
|
@@ -126,6 +126,8 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
126
126
|
visitor_id: bigint;
|
|
127
127
|
name: string;
|
|
128
128
|
tags: {
|
|
129
|
+
language?: string | undefined;
|
|
130
|
+
screen_resolution?: string | undefined;
|
|
129
131
|
os?: string | undefined;
|
|
130
132
|
os_name?: string | undefined;
|
|
131
133
|
os_version?: string | undefined;
|
|
@@ -138,9 +140,7 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
138
140
|
device_type?: string | undefined;
|
|
139
141
|
device_vendor?: string | undefined;
|
|
140
142
|
device_pixel_ratio?: string | undefined;
|
|
141
|
-
screen_resolution?: string | undefined;
|
|
142
143
|
release?: string | undefined;
|
|
143
|
-
language?: string | undefined;
|
|
144
144
|
timezone?: string | undefined;
|
|
145
145
|
environment?: "development" | "production" | undefined;
|
|
146
146
|
source_url?: string | undefined;
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
32
32
|
utm_term: z.ZodOptional<z.ZodString>;
|
|
33
33
|
utm_content: z.ZodOptional<z.ZodString>;
|
|
34
34
|
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
language?: string | undefined;
|
|
36
|
+
screen_resolution?: `${number}x${number}` | undefined;
|
|
35
37
|
os?: string | undefined;
|
|
36
38
|
os_name?: string | undefined;
|
|
37
39
|
os_version?: string | undefined;
|
|
@@ -44,9 +46,7 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
44
46
|
device_type?: string | undefined;
|
|
45
47
|
device_vendor?: string | undefined;
|
|
46
48
|
device_pixel_ratio?: string | undefined;
|
|
47
|
-
screen_resolution?: `${number}x${number}` | undefined;
|
|
48
49
|
release?: string | undefined;
|
|
49
|
-
language?: string | undefined;
|
|
50
50
|
timezone?: string | undefined;
|
|
51
51
|
environment?: "development" | "production" | undefined;
|
|
52
52
|
source_url?: string | undefined;
|
|
@@ -60,6 +60,8 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
60
60
|
utm_term?: string | undefined;
|
|
61
61
|
utm_content?: string | undefined;
|
|
62
62
|
}, {
|
|
63
|
+
language?: string | undefined;
|
|
64
|
+
screen_resolution?: string | undefined;
|
|
63
65
|
os?: string | undefined;
|
|
64
66
|
os_name?: string | undefined;
|
|
65
67
|
os_version?: string | undefined;
|
|
@@ -72,9 +74,7 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
72
74
|
device_type?: string | undefined;
|
|
73
75
|
device_vendor?: string | undefined;
|
|
74
76
|
device_pixel_ratio?: string | undefined;
|
|
75
|
-
screen_resolution?: string | undefined;
|
|
76
77
|
release?: string | undefined;
|
|
77
|
-
language?: string | undefined;
|
|
78
78
|
timezone?: string | undefined;
|
|
79
79
|
environment?: "development" | "production" | undefined;
|
|
80
80
|
source_url?: string | undefined;
|
|
@@ -93,6 +93,8 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
93
93
|
visitor_id: bigint;
|
|
94
94
|
name: string;
|
|
95
95
|
tags: {
|
|
96
|
+
language?: string | undefined;
|
|
97
|
+
screen_resolution?: `${number}x${number}` | undefined;
|
|
96
98
|
os?: string | undefined;
|
|
97
99
|
os_name?: string | undefined;
|
|
98
100
|
os_version?: string | undefined;
|
|
@@ -105,9 +107,7 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
105
107
|
device_type?: string | undefined;
|
|
106
108
|
device_vendor?: string | undefined;
|
|
107
109
|
device_pixel_ratio?: string | undefined;
|
|
108
|
-
screen_resolution?: `${number}x${number}` | undefined;
|
|
109
110
|
release?: string | undefined;
|
|
110
|
-
language?: string | undefined;
|
|
111
111
|
timezone?: string | undefined;
|
|
112
112
|
environment?: "development" | "production" | undefined;
|
|
113
113
|
source_url?: string | undefined;
|
|
@@ -126,6 +126,8 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
126
126
|
visitor_id: bigint;
|
|
127
127
|
name: string;
|
|
128
128
|
tags: {
|
|
129
|
+
language?: string | undefined;
|
|
130
|
+
screen_resolution?: string | undefined;
|
|
129
131
|
os?: string | undefined;
|
|
130
132
|
os_name?: string | undefined;
|
|
131
133
|
os_version?: string | undefined;
|
|
@@ -138,9 +140,7 @@ declare const createTrackEventSchema: z.ZodObject<{
|
|
|
138
140
|
device_type?: string | undefined;
|
|
139
141
|
device_vendor?: string | undefined;
|
|
140
142
|
device_pixel_ratio?: string | undefined;
|
|
141
|
-
screen_resolution?: string | undefined;
|
|
142
143
|
release?: string | undefined;
|
|
143
|
-
language?: string | undefined;
|
|
144
144
|
timezone?: string | undefined;
|
|
145
145
|
environment?: "development" | "production" | undefined;
|
|
146
146
|
source_url?: string | undefined;
|
package/dist/setup/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/setup/index.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport retry from 'axios-retry';\nimport { ThirdPartyTracker,
|
|
1
|
+
{"version":3,"sources":["../../src/setup/index.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport retry from 'axios-retry';\nimport type { ThirdPartyTracker, TrackTags } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\nexport interface Storage {\n getItem: (key: string) => (string | null) | Promise<string | null>;\n setItem: (key: string, value: string) => void | Promise<void>;\n}\n\nexport interface Options {\n release: string;\n storage: Storage;\n endpoint: string;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n thirdPartyTrackers?: ThirdPartyTracker[];\n thirdPartyUserSetters?: ThirdPartyUserSetter[];\n}\n\ninterface Config {\n release: string;\n storage: Storage;\n http: AxiosInstance;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n thirdPartyTrackers: ThirdPartyTracker[];\n thirdPartyUserSetters: ThirdPartyUserSetter[];\n}\n\nexport const config: Config = {\n http: null!,\n release: '0.0.0',\n storage: null!,\n getTags: null!,\n getDeviceId: null!,\n thirdPartyTrackers: [],\n thirdPartyUserSetters: [],\n};\n\nexport function setupAnalytics(init: Options) {\n config.release = init.release;\n config.storage = init.storage;\n config.getTags = init.getTags;\n config.getDeviceId = init.getDeviceId;\n config.thirdPartyTrackers = init.thirdPartyTrackers ?? [];\n config.thirdPartyUserSetters = init.thirdPartyUserSetters ?? [];\n config.http = axios.create({ baseURL: init.endpoint, withCredentials: true, adapter: 'fetch' });\n retry(config.http, { retries: 5, retryDelay: retry.exponentialDelay });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AACrC,yBAAkB;AA6BX,IAAM,SAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,aAAa;AAAA,EACb,oBAAoB,CAAC;AAAA,EACrB,uBAAuB,CAAC;AAC1B;AAEO,SAAS,eAAe,MAAe;AAC5C,SAAO,UAAU,KAAK;AACtB,SAAO,UAAU,KAAK;AACtB,SAAO,UAAU,KAAK;AACtB,SAAO,cAAc,KAAK;AAC1B,SAAO,qBAAqB,KAAK,sBAAsB,CAAC;AACxD,SAAO,wBAAwB,KAAK,yBAAyB,CAAC;AAC9D,SAAO,OAAO,aAAAA,QAAM,OAAO,EAAE,SAAS,KAAK,UAAU,iBAAiB,MAAM,SAAS,QAAQ,CAAC;AAC9F,yBAAAC,SAAM,OAAO,MAAM,EAAE,SAAS,GAAG,YAAY,mBAAAA,QAAM,iBAAiB,CAAC;AACvE;","names":["axios","retry"]}
|
package/dist/setup/index.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { TrackTags, ThirdPartyTracker
|
|
2
|
+
import { TrackTags, ThirdPartyTracker } from '../track/types.cjs';
|
|
3
|
+
import { ThirdPartyUserSetter } from '../visitor/types.cjs';
|
|
4
|
+
import '../track/gtag.cjs';
|
|
3
5
|
|
|
4
6
|
interface Storage {
|
|
5
7
|
getItem: (key: string) => (string | null) | Promise<string | null>;
|
package/dist/setup/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { TrackTags, ThirdPartyTracker
|
|
2
|
+
import { TrackTags, ThirdPartyTracker } from '../track/types.js';
|
|
3
|
+
import { ThirdPartyUserSetter } from '../visitor/types.js';
|
|
4
|
+
import '../track/gtag.js';
|
|
3
5
|
|
|
4
6
|
interface Storage {
|
|
5
7
|
getItem: (key: string) => (string | null) | Promise<string | null>;
|
package/dist/setup/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/setup/index.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport retry from 'axios-retry';\nimport { ThirdPartyTracker,
|
|
1
|
+
{"version":3,"sources":["../../src/setup/index.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport retry from 'axios-retry';\nimport type { ThirdPartyTracker, TrackTags } from '../track/types';\nimport type { ThirdPartyUserSetter } from '../visitor/types';\n\nexport interface Storage {\n getItem: (key: string) => (string | null) | Promise<string | null>;\n setItem: (key: string, value: string) => void | Promise<void>;\n}\n\nexport interface Options {\n release: string;\n storage: Storage;\n endpoint: string;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n thirdPartyTrackers?: ThirdPartyTracker[];\n thirdPartyUserSetters?: ThirdPartyUserSetter[];\n}\n\ninterface Config {\n release: string;\n storage: Storage;\n http: AxiosInstance;\n getTags: () => TrackTags | Promise<TrackTags>;\n getDeviceId: () => string | Promise<string>;\n thirdPartyTrackers: ThirdPartyTracker[];\n thirdPartyUserSetters: ThirdPartyUserSetter[];\n}\n\nexport const config: Config = {\n http: null!,\n release: '0.0.0',\n storage: null!,\n getTags: null!,\n getDeviceId: null!,\n thirdPartyTrackers: [],\n thirdPartyUserSetters: [],\n};\n\nexport function setupAnalytics(init: Options) {\n config.release = init.release;\n config.storage = init.storage;\n config.getTags = init.getTags;\n config.getDeviceId = init.getDeviceId;\n config.thirdPartyTrackers = init.thirdPartyTrackers ?? [];\n config.thirdPartyUserSetters = init.thirdPartyUserSetters ?? [];\n config.http = axios.create({ baseURL: init.endpoint, withCredentials: true, adapter: 'fetch' });\n retry(config.http, { retries: 5, retryDelay: retry.exponentialDelay });\n}\n"],"mappings":";AAAA,OAAO,WAA8B;AACrC,OAAO,WAAW;AA6BX,IAAM,SAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,aAAa;AAAA,EACb,oBAAoB,CAAC;AAAA,EACrB,uBAAuB,CAAC;AAC1B;AAEO,SAAS,eAAe,MAAe;AAC5C,SAAO,UAAU,KAAK;AACtB,SAAO,UAAU,KAAK;AACtB,SAAO,UAAU,KAAK;AACtB,SAAO,cAAc,KAAK;AAC1B,SAAO,qBAAqB,KAAK,sBAAsB,CAAC;AACxD,SAAO,wBAAwB,KAAK,yBAAyB,CAAC;AAC9D,SAAO,OAAO,MAAM,OAAO,EAAE,SAAS,KAAK,UAAU,iBAAiB,MAAM,SAAS,QAAQ,CAAC;AAC9F,QAAM,OAAO,MAAM,EAAE,SAAS,GAAG,YAAY,MAAM,iBAAiB,CAAC;AACvE;","names":[]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/track/fbq.ts
|
|
21
|
+
var fbq_exports = {};
|
|
22
|
+
__export(fbq_exports, {
|
|
23
|
+
mapAndSendFbqEvent: () => mapAndSendFbqEvent,
|
|
24
|
+
normalize: () => normalize
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(fbq_exports);
|
|
27
|
+
function normalize(parameters) {
|
|
28
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
29
|
+
return {
|
|
30
|
+
...parameters,
|
|
31
|
+
em: (_a = parameters.em) == null ? void 0 : _a.toLowerCase().trim(),
|
|
32
|
+
ph: (_b = parameters.ph) == null ? void 0 : _b.replace(/[\+\-\(\)\s]/g, "").replace(/^0+/, ""),
|
|
33
|
+
zp: (_d = (_c = parameters.zp) == null ? void 0 : _c.split("-").at(0)) == null ? void 0 : _d.trim(),
|
|
34
|
+
fn: (_e = parameters.fn) == null ? void 0 : _e.toLowerCase().trim(),
|
|
35
|
+
ln: (_f = parameters.ln) == null ? void 0 : _f.toLowerCase().trim(),
|
|
36
|
+
ct: (_g = parameters.ct) == null ? void 0 : _g.toLowerCase().replace(/[s/-]/g, "").trim(),
|
|
37
|
+
st: (_h = parameters.st) == null ? void 0 : _h.toLowerCase().replace(/[s/-/,.]/g, "").trim(),
|
|
38
|
+
country: (_i = parameters.country) == null ? void 0 : _i.toLowerCase().replace(/[s/-]/g, "").trim()
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function mapItems(items) {
|
|
42
|
+
if (!items) return {};
|
|
43
|
+
const categories = Array.from(new Set(items.map((i) => i.item_category).filter(Boolean)));
|
|
44
|
+
const contents = items.map(({ item_id, quantity, ...others }) => ({
|
|
45
|
+
id: item_id,
|
|
46
|
+
quantity: quantity ?? 1,
|
|
47
|
+
...Object.fromEntries(
|
|
48
|
+
Object.entries(others).map(([key, value]) => [key.replace("item_", ""), value])
|
|
49
|
+
)
|
|
50
|
+
}));
|
|
51
|
+
return {
|
|
52
|
+
content_category: categories.length === 1 ? categories.at(0) : void 0,
|
|
53
|
+
contents,
|
|
54
|
+
content_ids: contents.map((c) => c.id),
|
|
55
|
+
num_items: items.reduce((acc, i) => acc + (i.quantity ?? 1), 0)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function mapAndSendFbqEvent(fbq, name, properties, options) {
|
|
59
|
+
if (name === "add_payment_info") {
|
|
60
|
+
const p = properties;
|
|
61
|
+
fbq(
|
|
62
|
+
"track",
|
|
63
|
+
"AddPaymentInfo",
|
|
64
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) },
|
|
65
|
+
options
|
|
66
|
+
);
|
|
67
|
+
} else if (name === "add_to_cart") {
|
|
68
|
+
const p = properties;
|
|
69
|
+
fbq(
|
|
70
|
+
"track",
|
|
71
|
+
"AddToCart",
|
|
72
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) },
|
|
73
|
+
options
|
|
74
|
+
);
|
|
75
|
+
} else if (name === "add_to_wishlist") {
|
|
76
|
+
const p = properties;
|
|
77
|
+
fbq(
|
|
78
|
+
"track",
|
|
79
|
+
"AddToWishlist",
|
|
80
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) },
|
|
81
|
+
options
|
|
82
|
+
);
|
|
83
|
+
} else if (name === "login") {
|
|
84
|
+
const p = properties;
|
|
85
|
+
fbq("track", "CompleteRegistration", { method: p == null ? void 0 : p.method }, options);
|
|
86
|
+
} else if (name === "contact") {
|
|
87
|
+
fbq("track", "Contact", {}, options);
|
|
88
|
+
} else if (name === "customize_product") {
|
|
89
|
+
fbq("track", "CustomizeProduct", {}, options);
|
|
90
|
+
} else if (name === "donate") {
|
|
91
|
+
fbq("track", "Donate", {}, options);
|
|
92
|
+
} else if (name === "find_location") {
|
|
93
|
+
fbq("track", "FindLocation", {}, options);
|
|
94
|
+
} else if (name === "begin_checkout") {
|
|
95
|
+
const p = properties;
|
|
96
|
+
fbq(
|
|
97
|
+
"track",
|
|
98
|
+
"InitiateCheckout",
|
|
99
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) },
|
|
100
|
+
options
|
|
101
|
+
);
|
|
102
|
+
} else if (name === "generate_lead") {
|
|
103
|
+
const p = properties;
|
|
104
|
+
fbq("track", "Lead", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }, options);
|
|
105
|
+
} else if (name === "purchase") {
|
|
106
|
+
const p = properties;
|
|
107
|
+
fbq(
|
|
108
|
+
"track",
|
|
109
|
+
"Purchase",
|
|
110
|
+
p ? { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) } : void 0,
|
|
111
|
+
options
|
|
112
|
+
);
|
|
113
|
+
} else if (name === "schedule") {
|
|
114
|
+
fbq("track", "Schedule", {}, options);
|
|
115
|
+
} else if (name === "search") {
|
|
116
|
+
const p = properties;
|
|
117
|
+
fbq("track", "Search", { search_string: p == null ? void 0 : p.search_term }, options);
|
|
118
|
+
} else if (name === "trial_begin") {
|
|
119
|
+
const p = properties;
|
|
120
|
+
fbq("track", "StartTrial", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }, options);
|
|
121
|
+
} else if (name === "submit_application") {
|
|
122
|
+
fbq("track", "SubmitApplication", {}, options);
|
|
123
|
+
} else if (name === "subscribe") {
|
|
124
|
+
const p = properties;
|
|
125
|
+
fbq("track", "Subscribe", { currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value }, options);
|
|
126
|
+
} else if (name === "view_item") {
|
|
127
|
+
const p = properties;
|
|
128
|
+
fbq(
|
|
129
|
+
"track",
|
|
130
|
+
"ViewContent",
|
|
131
|
+
{ currency: p == null ? void 0 : p.currency, value: p == null ? void 0 : p.value, ...mapItems(p == null ? void 0 : p.items) },
|
|
132
|
+
options
|
|
133
|
+
);
|
|
134
|
+
} else {
|
|
135
|
+
fbq("trackCustom", name, properties, options);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
139
|
+
0 && (module.exports = {
|
|
140
|
+
mapAndSendFbqEvent,
|
|
141
|
+
normalize
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=fbq.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/track/fbq.ts"],"sourcesContent":["import type { EventName, TrackName, TrackProperties, Item } from './types';\nexport type Content = { id: string; quantity: number; [key: string]: unknown };\n\n/**\n * reference: https://developers.facebook.com/docs/meta-pixel/advanced/advanced-matching\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\n */\nexport type MatchingParameters = {\n /** Email: Unhashed lowercase or hashed SHA-256 */\n em?: string;\n\n /** First Name: Lowercase letters */\n fn?: string;\n\n /** Last Name: Lowercase letters */\n ln?: string;\n\n /** Phone Number: Digits only including country code and area code */\n ph?: string;\n\n /**\n * External ID: Any unique ID from the advertiser, such as loyalty membership ID, user ID, and\n * external cookie ID.\n */\n external_id?: string;\n\n /** Gender: Single lowercase letter, f or m, if unknown, leave blank */\n ge?: 'f' | 'm' | '';\n\n /** Birthdate: Digits only with birth year, month, then day, YYYYMMDD */\n db?: number;\n\n /** City: Lowercase with any spaces removed, e.g. \"menlopark\" */\n ct?: string;\n\n /** State or Province: Lowercase two-letter state or province code, e.g. \"ca\" */\n st?: string;\n\n /** Zip or Postal Code: String */\n zp?: string;\n\n /** Country: Lowercase two-letter country code, e.g. \"us\" */\n country?: string;\n\n /** Client IP Address: Do not hash. */\n client_ip_address?: string;\n\n /** Client User Agent: Do not hash. */\n client_user_agent?: string;\n\n /**\n * Click ID: Do not hash.\n * The Facebook click ID value is stored in the _fbc browser cookie under your domain. See\n * Managing fbc and fbp Parameters for how to get this value or generate this value from a fbclid\n * query parameter.\n *\n * The format is fb.${subdomain_index}.${creation_time}.${fbclid}.\n */\n fbc?: string;\n\n /**\n * Browser ID: Do not hash.\n * The Facebook browser ID value is stored in the _fbp browser cookie under your domain. See\n * Managing fbc and fbp Parameters for how to get this value.\n *\n * The format is fb.${subdomain_index}.${creation_time}.${random_number}.\n */\n fbp?: string;\n\n /**\n * Subscription ID: Do not hash.\n * The subscription ID for the user in this transaction; it is similar to the order ID for an\n * individual product.\n */\n subscription_id?: string;\n\n /**\n * Facebook Login ID: Do not hash.\n * The ID issued by Meta when a person first logs into an instance of an app. This is also known\n * as App-Scoped ID.\n */\n fb_login_id?: number;\n\n /**\n * Lead ID: Do not hash.\n * The ID associated with a lead generated by [Meta's Lead Ads](https://developers.facebook.com/docs/marketing-api/guides/lead-ads).\n */\n lead_id?: number;\n\n /**\n * Install ID: Do not hash.\n * Your install ID. This field represents unique application installation instances.\n * Note: This parameter is for app events only.\n */\n anon_id?: string;\n\n /**\n * Your mobile advertiser ID, the advertising ID from an Android device or the Advertising\n * Identifier (IDFA) from an Apple device.\n */\n madid?: string;\n\n /**\n * Page ID: Do not hash.\n * Your Page ID. Specifies the page ID associated with the event. Use the Facebook page ID of the\n * page associated with the bot.\n */\n page_id?: string;\n\n /**\n * Page Scoped User ID: Do not hash.\n * Specifies the page-scoped user ID associated with the messenger bot that logs the event. Use\n * the page-scoped user ID provided to your webhook.\n */\n page_scoped_user_id?: string;\n\n /**\n * Do not hash.\n * Click ID generated by Meta for ads that click to WhatsApp.\n */\n ctwa_clid?: string;\n\n /**\n * Do not hash.\n * Instagram Account ID that is associated with the business.\n */\n ig_account_id?: string;\n\n /**\n * Do not hash.\n * Users who interact with Instagram are identified by Instagram-Scoped User IDs (IGSID). IGSID\n * can be obtained from this webhook.\n */\n ig_sid?: string;\n};\n\n/**\n * You can include the following predefined object properties with any custom events, and any\n * standard events that support them. Format your parameter object data using JSON. Learn more about\n * event parameters with Blueprint.\n */\nexport type ObjectProperties = {\n content_category?: string;\n content_ids?: string[];\n content_name?: string;\n\n /**\n * Either product or product_group based on the content_ids or contents being passed. If the IDs\n * being passed in content_ids or contents parameter are IDs of products, then the value should be\n * product. If product group IDs are being passed, then the value should be product_group.\n *\n * If no content_type is provided, Meta will match the event to every item that has the same ID,\n * independent of its type.\n */\n content_type?: 'product' | 'product_group' | (string & {});\n contents?: Content[];\n delivery_category?: 'in_store' | 'curbside' | 'home_delivery';\n currency?: string;\n num_items?: number;\n predicted_ltv?: number;\n search_string?: string;\n\n /** Used with the CompleteRegistration event, to show the status of the registration. */\n status?: boolean;\n value?: number;\n};\n\n/**\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/payload-helper\n */\nexport type StandardEvents = {\n AddPaymentInfo: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n value?: number;\n };\n AddToCart: {\n content_ids?: string[];\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents\n currency?: string;\n value?: number;\n };\n AddToWishlist: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n value?: number;\n };\n CompleteRegistration: {\n currency?: string;\n value?: number;\n method?: string;\n };\n Contact: {};\n CustomizeProduct: {};\n Donate: {};\n FindLocation: {};\n InitiateCheckout: {\n content_ids?: string[];\n contents?: Content[];\n currency?: string;\n num_items?: number;\n value?: number;\n };\n Lead: {\n currency?: string;\n value?: number;\n };\n Purchase: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency: string; // required\n num_items?: number;\n value: number; // required\n };\n Schedule: {};\n Search: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency?: string;\n search_string?: string;\n value?: number;\n };\n StartTrial: {\n currency?: string;\n predicted_ltv?: number;\n value?: number;\n };\n SubmitApplication: {};\n Subscribe: {\n currency?: string;\n predicted_ltv?: number;\n value?: number;\n };\n ViewContent: {\n content_ids?: string[]; // Required for Advantage+ catalog ads: contents or content_ids\n content_type?: string;\n contents?: Content[]; // Required for Advantage+ catalog ads: contents or content_ids\n currency?: string;\n value?: number;\n };\n};\n\ntype JSONValue =\n | null\n | string\n | number\n | boolean\n | Array<JSONValue>\n | { [value: string]: JSONValue };\n\nexport type PixelId = `${number}`;\n\n/**\n * reference: https://developers.facebook.com/docs/meta-pixel/reference#standard-events\n *\n * We determine if events are identical based on their ID and name. So, for an event to be deduplicated:\n * - In corresponding events, a Meta Pixel's eventID must match the Conversion API's event_id.\n * - In corresponding events, a Meta Pixel's event must match the Conversion API's event_name.\n *\n * reference: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters\n */\nexport interface Fbq {\n /**\n * reference: https://stackoverflow.com/questions/62304291/sending-user-data-parameters-via-pixel\n *\n * Call init the normal default way first:\n * `fbq('init', 'XXXXX')`\n *\n * And at a later point in time, when you have obtained additional user data, you can call init\n * again basically enriching the already running fbq instance with additional data:\n * `fbq('init', 'XXXXX', { external_id: 1234, em: 'abc@abc.com' } )`\n *\n * Only caveat is that you have to send an event after this additional init call, otherwise the\n * provided data will not be sent to Facebook.\n */\n fbq(type: 'init', pixelId: PixelId, parameters?: MatchingParameters): void;\n\n /** Enable Manual Only mode. (value = false) */\n fbq(type: 'set', key: 'autoConfig', value: boolean, pixelId: PixelId): void;\n\n fbq<T extends keyof StandardEvents>(\n type: 'track',\n event: T,\n properties?: StandardEvents[T] & ObjectProperties,\n options?: { eventID?: string }\n ): void;\n\n fbq(\n type: 'trackCustom',\n event: string,\n properties?: Record<string, JSONValue> & ObjectProperties,\n options?: { eventID?: string }\n ): void;\n\n /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */\n fbq<T extends keyof StandardEvents>(\n type: 'trackSingle',\n pixelId: PixelId,\n event: T,\n properties?: StandardEvents[T] & ObjectProperties,\n options?: { eventID?: string }\n ): void;\n\n /** https://developers.facebook.com/docs/meta-pixel/guides/track-multiple-events/ */\n fbq(\n type: 'trackSingleCustom',\n pixelId: PixelId,\n event: string,\n properties?: Record<string, JSONValue> & ObjectProperties,\n options?: { eventID?: string }\n ): void;\n}\n\n/**\n * Please download this CSV filefor examples of properly normalized and hashed data for the\n * parameters below.\n */\nexport function normalize(parameters: MatchingParameters): MatchingParameters {\n return {\n ...parameters,\n em: parameters.em?.toLowerCase().trim(),\n ph: parameters.ph?.replace(/[\\+\\-\\(\\)\\s]/g, '').replace(/^0+/, ''),\n zp: parameters.zp?.split('-').at(0)?.trim(),\n fn: parameters.fn?.toLowerCase().trim(),\n ln: parameters.ln?.toLowerCase().trim(),\n ct: parameters.ct?.toLowerCase().replace(/[s/-]/g, '').trim(),\n st: parameters.st\n ?.toLowerCase()\n .replace(/[s/-/,.]/g, '')\n .trim(),\n country: parameters.country?.toLowerCase().replace(/[s/-]/g, '').trim(),\n };\n}\n\nfunction mapItems(items?: Item[]): ObjectProperties {\n if (!items) return {};\n const categories = Array.from(new Set(items.map((i) => i.item_category).filter(Boolean)));\n const contents = items.map(({ item_id, quantity, ...others }) => ({\n id: item_id!,\n quantity: quantity ?? 1,\n ...Object.fromEntries(\n Object.entries(others).map(([key, value]) => [key.replace('item_', ''), value])\n ),\n }));\n\n return {\n content_category: categories.length === 1 ? categories.at(0) : undefined,\n contents,\n content_ids: contents.map((c) => c.id),\n num_items: items.reduce((acc, i) => acc + (i.quantity ?? 1), 0),\n };\n}\n\nexport function mapAndSendFbqEvent<T extends EventName>(\n fbq: Fbq['fbq'],\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n options?: { eventID?: string }\n) {\n if (name === 'add_payment_info') {\n const p = properties as TrackProperties<'add_payment_info'> | undefined;\n fbq(\n 'track',\n 'AddPaymentInfo',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'add_to_cart') {\n const p = properties as TrackProperties<'add_to_cart'> | undefined;\n fbq(\n 'track',\n 'AddToCart',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'add_to_wishlist') {\n const p = properties as TrackProperties<'add_to_wishlist'> | undefined;\n fbq(\n 'track',\n 'AddToWishlist',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'login') {\n const p = properties as TrackProperties<'login'> | undefined;\n fbq('track', 'CompleteRegistration', { method: p?.method }, options);\n } else if (name === 'contact') {\n fbq('track', 'Contact', {}, options);\n } else if (name === 'customize_product') {\n fbq('track', 'CustomizeProduct', {}, options);\n } else if (name === 'donate') {\n fbq('track', 'Donate', {}, options);\n } else if (name === 'find_location') {\n fbq('track', 'FindLocation', {}, options);\n } else if (name === 'begin_checkout') {\n const p = properties as TrackProperties<'begin_checkout'> | undefined;\n fbq(\n 'track',\n 'InitiateCheckout',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else if (name === 'generate_lead') {\n const p = properties as TrackProperties<'generate_lead'> | undefined;\n fbq('track', 'Lead', { currency: p?.currency, value: p?.value }, options);\n } else if (name === 'purchase') {\n const p = properties as TrackProperties<'purchase'> | undefined;\n fbq(\n 'track',\n 'Purchase',\n p ? { currency: p?.currency, value: p?.value, ...mapItems(p?.items) } : undefined,\n options\n );\n } else if (name === 'schedule') {\n fbq('track', 'Schedule', {}, options);\n } else if (name === 'search') {\n const p = properties as TrackProperties<'search'> | undefined;\n fbq('track', 'Search', { search_string: p?.search_term }, options);\n } else if (name === 'trial_begin') {\n const p = properties as TrackProperties<'trial_begin'> | undefined;\n fbq('track', 'StartTrial', { currency: p?.currency, value: p?.value }, options);\n } else if (name === 'submit_application') {\n fbq('track', 'SubmitApplication', {}, options);\n } else if (name === 'subscribe') {\n const p = properties as TrackProperties<'subscribe'> | undefined;\n fbq('track', 'Subscribe', { currency: p?.currency, value: p?.value }, options);\n } else if (name === 'view_item') {\n const p = properties as TrackProperties<'view_item'> | undefined;\n fbq(\n 'track',\n 'ViewContent',\n { currency: p?.currency, value: p?.value, ...mapItems(p?.items) },\n options\n );\n } else {\n fbq('trackCustom', name, properties, options);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkUO,SAAS,UAAU,YAAoD;AAlU9E;AAmUE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,KAAI,gBAAW,OAAX,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,QAAQ,iBAAiB,IAAI,QAAQ,OAAO;AAAA,IAC/D,KAAI,sBAAW,OAAX,mBAAe,MAAM,KAAK,GAAG,OAA7B,mBAAiC;AAAA,IACrC,KAAI,gBAAW,OAAX,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,cAAc;AAAA,IACjC,KAAI,gBAAW,OAAX,mBAAe,cAAc,QAAQ,UAAU,IAAI;AAAA,IACvD,KAAI,gBAAW,OAAX,mBACA,cACD,QAAQ,aAAa,IACrB;AAAA,IACH,UAAS,gBAAW,YAAX,mBAAoB,cAAc,QAAQ,UAAU,IAAI;AAAA,EACnE;AACF;AAEA,SAAS,SAAS,OAAkC;AAClD,MAAI,CAAC,MAAO,QAAO,CAAC;AACpB,QAAM,aAAa,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,aA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