@shware/analytics 2.1.3 → 2.1.4
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/link/index.cjs +6 -2
- package/dist/link/index.cjs.map +1 -1
- package/dist/link/index.d.cts +1 -1
- package/dist/link/index.d.ts +1 -1
- package/dist/link/index.mjs +6 -2
- package/dist/link/index.mjs.map +1 -1
- package/dist/next/index.cjs +20 -14
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.mjs +20 -14
- package/dist/next/index.mjs.map +1 -1
- package/dist/react-router/index.cjs +19 -13
- package/dist/react-router/index.cjs.map +1 -1
- package/dist/react-router/index.mjs +19 -13
- 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/link/index.cjs
CHANGED
|
@@ -30,8 +30,12 @@ async function createLink(dto) {
|
|
|
30
30
|
return response.data;
|
|
31
31
|
}
|
|
32
32
|
async function getLink(id) {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
try {
|
|
34
|
+
const response = await import_setup.config.http.get(`/links/${id}`);
|
|
35
|
+
return response.data;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
41
|
0 && (module.exports = {
|
package/dist/link/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/link/index.ts"],"sourcesContent":["import { config } from '../setup/index';\nimport type { CreateLinkDTO } from '../schema/index';\n\nexport interface Link extends CreateLinkDTO {\n id: string;\n created_at: string;\n}\n\nexport async function createLink(dto: CreateLinkDTO) {\n const response = await config.http.post<Link>('/links', dto);\n return response.data;\n}\n\nexport async function getLink(id: string) {\n const response = await config.http.get<Link>(`/links/${id}`);\n
|
|
1
|
+
{"version":3,"sources":["../../src/link/index.ts"],"sourcesContent":["import { config } from '../setup/index';\nimport type { CreateLinkDTO } from '../schema/index';\n\nexport interface Link extends CreateLinkDTO {\n id: string;\n created_at: string;\n}\n\nexport async function createLink(dto: CreateLinkDTO) {\n const response = await config.http.post<Link>('/links', dto);\n return response.data;\n}\n\nexport async function getLink(id: string): Promise<Link | null> {\n try {\n const response = await config.http.get<Link>(`/links/${id}`);\n return response.data;\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuB;AAQvB,eAAsB,WAAW,KAAoB;AACnD,QAAM,WAAW,MAAM,oBAAO,KAAK,KAAW,UAAU,GAAG;AAC3D,SAAO,SAAS;AAClB;AAEA,eAAsB,QAAQ,IAAkC;AAC9D,MAAI;AACF,UAAM,WAAW,MAAM,oBAAO,KAAK,IAAU,UAAU,EAAE,EAAE;AAC3D,WAAO,SAAS;AAAA,EAClB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/link/index.d.cts
CHANGED
|
@@ -6,6 +6,6 @@ interface Link extends CreateLinkDTO {
|
|
|
6
6
|
created_at: string;
|
|
7
7
|
}
|
|
8
8
|
declare function createLink(dto: CreateLinkDTO): Promise<Link>;
|
|
9
|
-
declare function getLink(id: string): Promise<Link>;
|
|
9
|
+
declare function getLink(id: string): Promise<Link | null>;
|
|
10
10
|
|
|
11
11
|
export { type Link, createLink, getLink };
|
package/dist/link/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ interface Link extends CreateLinkDTO {
|
|
|
6
6
|
created_at: string;
|
|
7
7
|
}
|
|
8
8
|
declare function createLink(dto: CreateLinkDTO): Promise<Link>;
|
|
9
|
-
declare function getLink(id: string): Promise<Link>;
|
|
9
|
+
declare function getLink(id: string): Promise<Link | null>;
|
|
10
10
|
|
|
11
11
|
export { type Link, createLink, getLink };
|
package/dist/link/index.mjs
CHANGED
|
@@ -5,8 +5,12 @@ async function createLink(dto) {
|
|
|
5
5
|
return response.data;
|
|
6
6
|
}
|
|
7
7
|
async function getLink(id) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
try {
|
|
9
|
+
const response = await config.http.get(`/links/${id}`);
|
|
10
|
+
return response.data;
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
10
14
|
}
|
|
11
15
|
export {
|
|
12
16
|
createLink,
|
package/dist/link/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/link/index.ts"],"sourcesContent":["import { config } from '../setup/index';\nimport type { CreateLinkDTO } from '../schema/index';\n\nexport interface Link extends CreateLinkDTO {\n id: string;\n created_at: string;\n}\n\nexport async function createLink(dto: CreateLinkDTO) {\n const response = await config.http.post<Link>('/links', dto);\n return response.data;\n}\n\nexport async function getLink(id: string) {\n const response = await config.http.get<Link>(`/links/${id}`);\n
|
|
1
|
+
{"version":3,"sources":["../../src/link/index.ts"],"sourcesContent":["import { config } from '../setup/index';\nimport type { CreateLinkDTO } from '../schema/index';\n\nexport interface Link extends CreateLinkDTO {\n id: string;\n created_at: string;\n}\n\nexport async function createLink(dto: CreateLinkDTO) {\n const response = await config.http.post<Link>('/links', dto);\n return response.data;\n}\n\nexport async function getLink(id: string): Promise<Link | null> {\n try {\n const response = await config.http.get<Link>(`/links/${id}`);\n return response.data;\n } catch {\n return null;\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc;AAQvB,eAAsB,WAAW,KAAoB;AACnD,QAAM,WAAW,MAAM,OAAO,KAAK,KAAW,UAAU,GAAG;AAC3D,SAAO,SAAS;AAClB;AAEA,eAAsB,QAAQ,IAAkC;AAC9D,MAAI;AACF,UAAM,WAAW,MAAM,OAAO,KAAK,IAAU,UAAU,EAAE,EAAE;AAC3D,WAAO,SAAS;AAAA,EAClB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/next/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ var import_navigation = require("next/navigation");
|
|
|
40
40
|
var import_script = __toESM(require("next/script"), 1);
|
|
41
41
|
var import_web_vitals = require("next/web-vitals");
|
|
42
42
|
var import_react = require("react");
|
|
43
|
+
var import_link = require("../link/index.cjs");
|
|
43
44
|
var import_fbq = require("../track/fbq.cjs");
|
|
44
45
|
var import_track = require("../track/index.cjs");
|
|
45
46
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -74,21 +75,26 @@ function Analytics({
|
|
|
74
75
|
}) {
|
|
75
76
|
const pathname = (0, import_navigation.usePathname)();
|
|
76
77
|
(0, import_react.useEffect)(() => {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
const trackUTM = async () => {
|
|
79
|
+
const params = new URLSearchParams(document.location.search);
|
|
80
|
+
let link = null;
|
|
81
|
+
if (params.has("s")) link = await (0, import_link.getLink)(params.get("s"));
|
|
82
|
+
const properties = {
|
|
83
|
+
pathname,
|
|
84
|
+
referrer: document.referrer,
|
|
85
|
+
fbclid: params.get("fbclid"),
|
|
86
|
+
gclid: params.get("gclid"),
|
|
87
|
+
gad_source: params.get("gad_source"),
|
|
88
|
+
gad_campaignid: params.get("gad_campaignid"),
|
|
89
|
+
utm_source: (link == null ? void 0 : link.utm_source) ?? params.get("utm_source"),
|
|
90
|
+
utm_medium: (link == null ? void 0 : link.utm_medium) ?? params.get("utm_medium"),
|
|
91
|
+
utm_campaign: (link == null ? void 0 : link.utm_campaign) ?? params.get("utm_campaign"),
|
|
92
|
+
utm_term: (link == null ? void 0 : link.utm_term) ?? params.get("utm_term"),
|
|
93
|
+
utm_content: (link == null ? void 0 : link.utm_content) ?? params.get("utm_content")
|
|
94
|
+
};
|
|
95
|
+
(0, import_track.track)("page_view", properties, { enableThirdPartyTracking: false });
|
|
90
96
|
};
|
|
91
|
-
(
|
|
97
|
+
trackUTM();
|
|
92
98
|
}, [pathname]);
|
|
93
99
|
(0, import_web_vitals.useReportWebVitals)((metric) => {
|
|
94
100
|
if (!reportWebVitals) return;
|
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 { 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 params = new URLSearchParams(document.location.search);\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\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 <>\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 )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wBAA4B;AAC5B,oBAAmB;AACnB,wB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AA;AAAA,QAExB;AAAA;AAAA,IACF,GACF;AAAA,KAEJ;AAEJ;","names":["Script"]}
|
package/dist/next/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { usePathname } from "next/navigation";
|
|
|
5
5
|
import Script from "next/script";
|
|
6
6
|
import { useReportWebVitals } from "next/web-vitals";
|
|
7
7
|
import { useEffect } from "react";
|
|
8
|
+
import { getLink } from "../link/index.mjs";
|
|
8
9
|
import { mapFBEvent } from "../track/fbq.mjs";
|
|
9
10
|
import { track } from "../track/index.mjs";
|
|
10
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -39,21 +40,26 @@ function Analytics({
|
|
|
39
40
|
}) {
|
|
40
41
|
const pathname = usePathname();
|
|
41
42
|
useEffect(() => {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
const trackUTM = async () => {
|
|
44
|
+
const params = new URLSearchParams(document.location.search);
|
|
45
|
+
let link = null;
|
|
46
|
+
if (params.has("s")) link = await getLink(params.get("s"));
|
|
47
|
+
const properties = {
|
|
48
|
+
pathname,
|
|
49
|
+
referrer: document.referrer,
|
|
50
|
+
fbclid: params.get("fbclid"),
|
|
51
|
+
gclid: params.get("gclid"),
|
|
52
|
+
gad_source: params.get("gad_source"),
|
|
53
|
+
gad_campaignid: params.get("gad_campaignid"),
|
|
54
|
+
utm_source: (link == null ? void 0 : link.utm_source) ?? params.get("utm_source"),
|
|
55
|
+
utm_medium: (link == null ? void 0 : link.utm_medium) ?? params.get("utm_medium"),
|
|
56
|
+
utm_campaign: (link == null ? void 0 : link.utm_campaign) ?? params.get("utm_campaign"),
|
|
57
|
+
utm_term: (link == null ? void 0 : link.utm_term) ?? params.get("utm_term"),
|
|
58
|
+
utm_content: (link == null ? void 0 : link.utm_content) ?? params.get("utm_content")
|
|
59
|
+
};
|
|
60
|
+
track("page_view", properties, { enableThirdPartyTracking: false });
|
|
55
61
|
};
|
|
56
|
-
|
|
62
|
+
trackUTM();
|
|
57
63
|
}, [pathname]);
|
|
58
64
|
useReportWebVitals((metric) => {
|
|
59
65
|
if (!reportWebVitals) return;
|
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 { 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 params = new URLSearchParams(document.location.search);\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\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 <>\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 )}\n </>\n );\n}\n"],"mappings":";;;AAEA,SAAS,mBAAmB;AAC5B,OAAO,YAA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A,6BAiBO,OAAO;AAAA;AAAA,QAExB;AAAA;AAAA,IACF,GACF;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -28,6 +28,7 @@ module.exports = __toCommonJS(react_router_exports);
|
|
|
28
28
|
var import_react = require("react");
|
|
29
29
|
var import_react_router = require("react-router");
|
|
30
30
|
var import_web_vitals = require("web-vitals");
|
|
31
|
+
var import_link = require("../link/index.cjs");
|
|
31
32
|
var import_fbq = require("../track/fbq.cjs");
|
|
32
33
|
var import_track = require("../track/index.cjs");
|
|
33
34
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -72,20 +73,25 @@ function Analytics({
|
|
|
72
73
|
const { pathname } = (0, import_react_router.useLocation)();
|
|
73
74
|
const [params] = (0, import_react_router.useSearchParams)();
|
|
74
75
|
(0, import_react.useEffect)(() => {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
const trackUTM = async () => {
|
|
77
|
+
let link = null;
|
|
78
|
+
if (params.has("s")) link = await (0, import_link.getLink)(params.get("s"));
|
|
79
|
+
const properties = {
|
|
80
|
+
pathname,
|
|
81
|
+
referrer: document.referrer,
|
|
82
|
+
fbclid: params.get("fbclid"),
|
|
83
|
+
gclid: params.get("gclid"),
|
|
84
|
+
gad_source: params.get("gad_source"),
|
|
85
|
+
gad_campaignid: params.get("gad_campaignid"),
|
|
86
|
+
utm_source: (link == null ? void 0 : link.utm_source) ?? params.get("utm_source"),
|
|
87
|
+
utm_medium: (link == null ? void 0 : link.utm_medium) ?? params.get("utm_medium"),
|
|
88
|
+
utm_campaign: (link == null ? void 0 : link.utm_campaign) ?? params.get("utm_campaign"),
|
|
89
|
+
utm_term: (link == null ? void 0 : link.utm_term) ?? params.get("utm_term"),
|
|
90
|
+
utm_content: (link == null ? void 0 : link.utm_content) ?? params.get("utm_content")
|
|
91
|
+
};
|
|
92
|
+
(0, import_track.track)("page_view", properties, { enableThirdPartyTracking: false });
|
|
87
93
|
};
|
|
88
|
-
(
|
|
94
|
+
trackUTM();
|
|
89
95
|
}, [pathname, params]);
|
|
90
96
|
useReportWebVitals((metric) => {
|
|
91
97
|
if (!reportWebVitals) return;
|
|
@@ -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 { 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 properties = {\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\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 <>\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 </>\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;AAmHE;AA9GxB,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;AAgBO,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;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iB;AAAA;AAAA,IACnB;AACA,4BAAM,OAAO,MAAM,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,2EACE;AAAA,MAAC;AAAA;AAAA,QACC,IAAG;AAAA,QACH,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAiBO,OAAO;AAAA;AAAA,QAExB;AAAA;AAAA,IACF,GACF;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
import { useLocation, useSearchParams } from "react-router";
|
|
4
4
|
import { onLCP, onCLS, onINP, onFCP, onTTFB } from "web-vitals";
|
|
5
|
+
import { getLink } from "../link/index.mjs";
|
|
5
6
|
import { mapFBEvent } from "../track/fbq.mjs";
|
|
6
7
|
import { track } from "../track/index.mjs";
|
|
7
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -46,20 +47,25 @@ function Analytics({
|
|
|
46
47
|
const { pathname } = useLocation();
|
|
47
48
|
const [params] = useSearchParams();
|
|
48
49
|
useEffect(() => {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
const trackUTM = async () => {
|
|
51
|
+
let link = null;
|
|
52
|
+
if (params.has("s")) link = await getLink(params.get("s"));
|
|
53
|
+
const properties = {
|
|
54
|
+
pathname,
|
|
55
|
+
referrer: document.referrer,
|
|
56
|
+
fbclid: params.get("fbclid"),
|
|
57
|
+
gclid: params.get("gclid"),
|
|
58
|
+
gad_source: params.get("gad_source"),
|
|
59
|
+
gad_campaignid: params.get("gad_campaignid"),
|
|
60
|
+
utm_source: (link == null ? void 0 : link.utm_source) ?? params.get("utm_source"),
|
|
61
|
+
utm_medium: (link == null ? void 0 : link.utm_medium) ?? params.get("utm_medium"),
|
|
62
|
+
utm_campaign: (link == null ? void 0 : link.utm_campaign) ?? params.get("utm_campaign"),
|
|
63
|
+
utm_term: (link == null ? void 0 : link.utm_term) ?? params.get("utm_term"),
|
|
64
|
+
utm_content: (link == null ? void 0 : link.utm_content) ?? params.get("utm_content")
|
|
65
|
+
};
|
|
66
|
+
track("page_view", properties, { enableThirdPartyTracking: false });
|
|
61
67
|
};
|
|
62
|
-
|
|
68
|
+
trackUTM();
|
|
63
69
|
}, [pathname, params]);
|
|
64
70
|
useReportWebVitals((metric) => {
|
|
65
71
|
if (!reportWebVitals) return;
|
|
@@ -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 { 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 properties = {\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\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 <>\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 </>\n )}\n </>\n );\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,aAAa,uBAAuB;AAC7C,SAAS,OAAO,OAAO,OAAO,OAAO,cAA2B;AAChE,SAAS,eAA0B;AACnC,SAAS,kBAAkB;AAC3B,SAAS,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AA,QACH,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAiBO,OAAO;AAAA;AAAA,QAExB;AAAA;AAAA,IACF,GACF;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";
|
|
17
16
|
ios: "ios";
|
|
18
17
|
android: "android";
|
|
19
18
|
web: "web";
|
|
20
19
|
macos: "macos";
|
|
21
20
|
windows: "windows";
|
|
22
21
|
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";
|
|
68
67
|
ios: "ios";
|
|
69
68
|
android: "android";
|
|
70
69
|
web: "web";
|
|
71
70
|
macos: "macos";
|
|
72
71
|
windows: "windows";
|
|
73
72
|
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";
|
|
17
16
|
ios: "ios";
|
|
18
17
|
android: "android";
|
|
19
18
|
web: "web";
|
|
20
19
|
macos: "macos";
|
|
21
20
|
windows: "windows";
|
|
22
21
|
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";
|
|
68
67
|
ios: "ios";
|
|
69
68
|
android: "android";
|
|
70
69
|
web: "web";
|
|
71
70
|
macos: "macos";
|
|
72
71
|
windows: "windows";
|
|
73
72
|
linux: "linux";
|
|
73
|
+
unknown: "unknown";
|
|
74
74
|
}>>;
|
|
75
75
|
device: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
76
76
|
device_id: z.ZodMiniOptional<z.ZodMiniString<string>>;
|