@shware/analytics 2.4.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/use-page-view-analytics.cjs +67 -0
- package/dist/hooks/use-page-view-analytics.cjs.map +1 -0
- package/dist/hooks/use-page-view-analytics.d.cts +3 -0
- package/dist/hooks/use-page-view-analytics.d.ts +3 -0
- package/dist/hooks/use-page-view-analytics.mjs +42 -0
- package/dist/hooks/use-page-view-analytics.mjs.map +1 -0
- package/dist/next/index.cjs +2 -5
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.mjs +2 -5
- package/dist/next/index.mjs.map +1 -1
- package/dist/react-router/index.cjs +2 -5
- package/dist/react-router/index.cjs.map +1 -1
- package/dist/react-router/index.mjs +3 -6
- package/dist/react-router/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
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/hooks/use-page-view-analytics.ts
|
|
21
|
+
var use_page_view_analytics_exports = {};
|
|
22
|
+
__export(use_page_view_analytics_exports, {
|
|
23
|
+
usePageViewAnalytics: () => usePageViewAnalytics
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(use_page_view_analytics_exports);
|
|
26
|
+
var import_react = require("react");
|
|
27
|
+
var import_track = require("../track.cjs");
|
|
28
|
+
var import_use_previous = require("./use-previous.cjs");
|
|
29
|
+
function usePageViewAnalytics(pathname) {
|
|
30
|
+
const prevPathname = (0, import_use_previous.usePrevious)(pathname);
|
|
31
|
+
const session = (0, import_react.useRef)({ start: performance.now(), total: 0, isActive: true });
|
|
32
|
+
(0, import_react.useEffect)(() => {
|
|
33
|
+
const handler = () => {
|
|
34
|
+
if (document.hidden) {
|
|
35
|
+
session.current.total += (performance.now() - session.current.start) / 1e3;
|
|
36
|
+
session.current.isActive = false;
|
|
37
|
+
} else {
|
|
38
|
+
session.current.start = performance.now();
|
|
39
|
+
session.current.isActive = true;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
document.addEventListener("visibilitychange", handler);
|
|
43
|
+
return () => document.removeEventListener("visibilitychange", handler);
|
|
44
|
+
}, []);
|
|
45
|
+
(0, import_react.useEffect)(() => {
|
|
46
|
+
if (!prevPathname) {
|
|
47
|
+
session.current = { start: performance.now(), total: 0, isActive: true };
|
|
48
|
+
}
|
|
49
|
+
let duration = session.current.total;
|
|
50
|
+
if (session.current.isActive) {
|
|
51
|
+
duration += (performance.now() - session.current.start) / 1e3;
|
|
52
|
+
}
|
|
53
|
+
const properties = {
|
|
54
|
+
pathname,
|
|
55
|
+
referrer: document.referrer,
|
|
56
|
+
previous_pathname: prevPathname ?? void 0,
|
|
57
|
+
previous_pathname_duration: prevPathname ? Number(duration.toFixed(2)) : void 0
|
|
58
|
+
};
|
|
59
|
+
(0, import_track.track)("page_view", properties, { enableThirdPartyTracking: false });
|
|
60
|
+
session.current = { start: performance.now(), total: 0, isActive: true };
|
|
61
|
+
}, [pathname]);
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
usePageViewAnalytics
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=use-page-view-analytics.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-page-view-analytics.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { track } from '../track';\nimport { usePrevious } from './use-previous';\n\nexport function usePageViewAnalytics(pathname: string) {\n const prevPathname = usePrevious(pathname);\n const session = useRef({ start: performance.now(), total: 0, isActive: true });\n\n useEffect(() => {\n const handler = () => {\n if (document.hidden) {\n session.current.total += (performance.now() - session.current.start) / 1000;\n session.current.isActive = false;\n } else {\n session.current.start = performance.now();\n session.current.isActive = true;\n }\n };\n document.addEventListener('visibilitychange', handler);\n return () => document.removeEventListener('visibilitychange', handler);\n }, []);\n\n useEffect(() => {\n if (!prevPathname) {\n session.current = { start: performance.now(), total: 0, isActive: true };\n }\n\n let duration = session.current.total;\n if (session.current.isActive) {\n duration += (performance.now() - session.current.start) / 1000;\n }\n\n const properties = {\n pathname,\n referrer: document.referrer,\n previous_pathname: prevPathname ?? undefined,\n previous_pathname_duration: prevPathname ? Number(duration.toFixed(2)) : undefined,\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n\n // reset session\n session.current = { start: performance.now(), total: 0, isActive: true };\n }, [pathname]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;AAClC,mBAAsB;AACtB,0BAA4B;AAErB,SAAS,qBAAqB,UAAkB;AACrD,QAAM,mBAAe,iCAAY,QAAQ;AACzC,QAAM,cAAU,qBAAO,EAAE,OAAO,YAAY,IAAI,GAAG,OAAO,GAAG,UAAU,KAAK,CAAC;AAE7E,8BAAU,MAAM;AACd,UAAM,UAAU,MAAM;AACpB,UAAI,SAAS,QAAQ;AACnB,gBAAQ,QAAQ,UAAU,YAAY,IAAI,IAAI,QAAQ,QAAQ,SAAS;AACvE,gBAAQ,QAAQ,WAAW;AAAA,MAC7B,OAAO;AACL,gBAAQ,QAAQ,QAAQ,YAAY,IAAI;AACxC,gBAAQ,QAAQ,WAAW;AAAA,MAC7B;AAAA,IACF;AACA,aAAS,iBAAiB,oBAAoB,OAAO;AACrD,WAAO,MAAM,SAAS,oBAAoB,oBAAoB,OAAO;AAAA,EACvE,GAAG,CAAC,CAAC;AAEL,8BAAU,MAAM;AACd,QAAI,CAAC,cAAc;AACjB,cAAQ,UAAU,EAAE,OAAO,YAAY,IAAI,GAAG,OAAO,GAAG,UAAU,KAAK;AAAA,IACzE;AAEA,QAAI,WAAW,QAAQ,QAAQ;AAC/B,QAAI,QAAQ,QAAQ,UAAU;AAC5B,mBAAa,YAAY,IAAI,IAAI,QAAQ,QAAQ,SAAS;AAAA,IAC5D;AAEA,UAAM,aAAa;AAAA,MACjB;AAAA,MACA,UAAU,SAAS;AAAA,MACnB,mBAAmB,gBAAgB;AAAA,MACnC,4BAA4B,eAAe,OAAO,SAAS,QAAQ,CAAC,CAAC,IAAI;AAAA,IAC3E;AAEA,4BAAM,aAAa,YAAY,EAAE,0BAA0B,MAAM,CAAC;AAGlE,YAAQ,UAAU,EAAE,OAAO,YAAY,IAAI,GAAG,OAAO,GAAG,UAAU,KAAK;AAAA,EACzE,GAAG,CAAC,QAAQ,CAAC;AACf;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/hooks/use-page-view-analytics.ts
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { track } from "../track.mjs";
|
|
4
|
+
import { usePrevious } from "./use-previous.mjs";
|
|
5
|
+
function usePageViewAnalytics(pathname) {
|
|
6
|
+
const prevPathname = usePrevious(pathname);
|
|
7
|
+
const session = useRef({ start: performance.now(), total: 0, isActive: true });
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const handler = () => {
|
|
10
|
+
if (document.hidden) {
|
|
11
|
+
session.current.total += (performance.now() - session.current.start) / 1e3;
|
|
12
|
+
session.current.isActive = false;
|
|
13
|
+
} else {
|
|
14
|
+
session.current.start = performance.now();
|
|
15
|
+
session.current.isActive = true;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
document.addEventListener("visibilitychange", handler);
|
|
19
|
+
return () => document.removeEventListener("visibilitychange", handler);
|
|
20
|
+
}, []);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!prevPathname) {
|
|
23
|
+
session.current = { start: performance.now(), total: 0, isActive: true };
|
|
24
|
+
}
|
|
25
|
+
let duration = session.current.total;
|
|
26
|
+
if (session.current.isActive) {
|
|
27
|
+
duration += (performance.now() - session.current.start) / 1e3;
|
|
28
|
+
}
|
|
29
|
+
const properties = {
|
|
30
|
+
pathname,
|
|
31
|
+
referrer: document.referrer,
|
|
32
|
+
previous_pathname: prevPathname ?? void 0,
|
|
33
|
+
previous_pathname_duration: prevPathname ? Number(duration.toFixed(2)) : void 0
|
|
34
|
+
};
|
|
35
|
+
track("page_view", properties, { enableThirdPartyTracking: false });
|
|
36
|
+
session.current = { start: performance.now(), total: 0, isActive: true };
|
|
37
|
+
}, [pathname]);
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
usePageViewAnalytics
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=use-page-view-analytics.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-page-view-analytics.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { track } from '../track';\nimport { usePrevious } from './use-previous';\n\nexport function usePageViewAnalytics(pathname: string) {\n const prevPathname = usePrevious(pathname);\n const session = useRef({ start: performance.now(), total: 0, isActive: true });\n\n useEffect(() => {\n const handler = () => {\n if (document.hidden) {\n session.current.total += (performance.now() - session.current.start) / 1000;\n session.current.isActive = false;\n } else {\n session.current.start = performance.now();\n session.current.isActive = true;\n }\n };\n document.addEventListener('visibilitychange', handler);\n return () => document.removeEventListener('visibilitychange', handler);\n }, []);\n\n useEffect(() => {\n if (!prevPathname) {\n session.current = { start: performance.now(), total: 0, isActive: true };\n }\n\n let duration = session.current.total;\n if (session.current.isActive) {\n duration += (performance.now() - session.current.start) / 1000;\n }\n\n const properties = {\n pathname,\n referrer: document.referrer,\n previous_pathname: prevPathname ?? undefined,\n previous_pathname_duration: prevPathname ? Number(duration.toFixed(2)) : undefined,\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n\n // reset session\n session.current = { start: performance.now(), total: 0, isActive: true };\n }, [pathname]);\n}\n"],"mappings":";AAAA,SAAS,WAAW,cAAc;AAClC,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAErB,SAAS,qBAAqB,UAAkB;AACrD,QAAM,eAAe,YAAY,QAAQ;AACzC,QAAM,UAAU,OAAO,EAAE,OAAO,YAAY,IAAI,GAAG,OAAO,GAAG,UAAU,KAAK,CAAC;AAE7E,YAAU,MAAM;AACd,UAAM,UAAU,MAAM;AACpB,UAAI,SAAS,QAAQ;AACnB,gBAAQ,QAAQ,UAAU,YAAY,IAAI,IAAI,QAAQ,QAAQ,SAAS;AACvE,gBAAQ,QAAQ,WAAW;AAAA,MAC7B,OAAO;AACL,gBAAQ,QAAQ,QAAQ,YAAY,IAAI;AACxC,gBAAQ,QAAQ,WAAW;AAAA,MAC7B;AAAA,IACF;AACA,aAAS,iBAAiB,oBAAoB,OAAO;AACrD,WAAO,MAAM,SAAS,oBAAoB,oBAAoB,OAAO;AAAA,EACvE,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,QAAI,CAAC,cAAc;AACjB,cAAQ,UAAU,EAAE,OAAO,YAAY,IAAI,GAAG,OAAO,GAAG,UAAU,KAAK;AAAA,IACzE;AAEA,QAAI,WAAW,QAAQ,QAAQ;AAC/B,QAAI,QAAQ,QAAQ,UAAU;AAC5B,mBAAa,YAAY,IAAI,IAAI,QAAQ,QAAQ,SAAS;AAAA,IAC5D;AAEA,UAAM,aAAa;AAAA,MACjB;AAAA,MACA,UAAU,SAAS;AAAA,MACnB,mBAAmB,gBAAgB;AAAA,MACnC,4BAA4B,eAAe,OAAO,SAAS,QAAQ,CAAC,CAAC,IAAI;AAAA,IAC3E;AAEA,UAAM,aAAa,YAAY,EAAE,0BAA0B,MAAM,CAAC;AAGlE,YAAQ,UAAU,EAAE,OAAO,YAAY,IAAI,GAAG,OAAO,GAAG,UAAU,KAAK;AAAA,EACzE,GAAG,CAAC,QAAQ,CAAC;AACf;","names":[]}
|
package/dist/next/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ module.exports = __toCommonJS(next_exports);
|
|
|
39
39
|
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
|
-
var
|
|
42
|
+
var import_use_page_view_analytics = require("../hooks/use-page-view-analytics.cjs");
|
|
43
43
|
var import_fbq = require("../track/fbq.cjs");
|
|
44
44
|
var import_track = require("../track/index.cjs");
|
|
45
45
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -74,10 +74,7 @@ function Analytics({
|
|
|
74
74
|
reportWebVitals = true
|
|
75
75
|
}) {
|
|
76
76
|
const pathname = (0, import_navigation.usePathname)();
|
|
77
|
-
(0,
|
|
78
|
-
const properties = { pathname, referrer: document.referrer };
|
|
79
|
-
(0, import_track.track)("page_view", properties, { enableThirdPartyTracking: false });
|
|
80
|
-
}, [pathname]);
|
|
77
|
+
(0, import_use_page_view_analytics.usePageViewAnalytics)(pathname);
|
|
81
78
|
(0, import_web_vitals.useReportWebVitals)((metric) => {
|
|
82
79
|
if (!reportWebVitals) return;
|
|
83
80
|
const properties = {
|
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 {
|
|
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 { usePageViewAnalytics } from '../hooks/use-page-view-analytics';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { GaId, Gtag, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ntype HotjarId = `${number}`;\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (!window.gtag) {\n console.warn('GA has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const pathname = usePathname();\n usePageViewAnalytics(pathname);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {gaId && (\n <>\n <Script\n id=\"gtag\"\n nonce={nonce}\n src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <Script\n nonce={nonce}\n id=\"gtag-init\"\n dangerouslySetInnerHTML={{\n __html: `\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '${gaId}'${debugMode ? \" ,{ 'debug_mode': true }\" : ''});\n `,\n }}\n />\n </>\n )}\n {pixelId && (\n <Script\n id=\"pixel\"\n strategy=\"afterInteractive\"\n dangerouslySetInnerHTML={{\n __html: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '${pixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {hotjarId && (\n <Script\n id=\"hotjar\"\n strategy=\"afterInteractive\"\n dangerouslySetInnerHTML={{\n __html: `\n (function(h,o,t,j,a,r){\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\n h._hjSettings={hjid:${hotjarId},hjsv:6};\n a=o.getElementsByTagName('head')[0];\n r=o.createElement('script');r.async=1;\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\n a.appendChild(r);\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\n `,\n }}\n />\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAA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AAG;AAAA,UACH;AAAA,UACA,KAAK,+CAA+C,IAAI;AAAA;AAAA,MAC1D;AAAA,MACA;AAAA,QAAC,cAAAA;AAAA,QAAA;AAAA,UACC;AAAA,UACA,IAAG;AAAA,UACH,yBAAyB;AAAA,YACvB,QAAQ;AAAA;AAAA;AAAA;AAAA,gCAIU,IAAI,IAAI,YAAY,6BAA6B,EAAE;AAAA;AAAA,UAEvE;AAAA;AAAA,MACF;AAAA,OACF;AAAA,IAED,WACC;AAAA,MAAC,cAAAA;AAAA,MAAA;AAAA,QACC,IAAG;AAAA,QACH,UAAS;AAAA,QACT,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAiBO,OAAO;AAAA;AAAA,QAExB;AAAA;AAAA,IACF;AAAA,IAED,YACC;AAAA,MAAC,cAAAA;AAAA,MAAA;AAAA,QACC,IAAG;AAAA,QACH,UAAS;AAAA,QACT,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA,oCAGgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOlC;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":["Script"]}
|
package/dist/next/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { usePathname } from "next/navigation";
|
|
5
5
|
import Script from "next/script";
|
|
6
6
|
import { useReportWebVitals } from "next/web-vitals";
|
|
7
|
-
import {
|
|
7
|
+
import { usePageViewAnalytics } from "../hooks/use-page-view-analytics.mjs";
|
|
8
8
|
import { mapFBEvent } from "../track/fbq.mjs";
|
|
9
9
|
import { track } from "../track/index.mjs";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -39,10 +39,7 @@ function Analytics({
|
|
|
39
39
|
reportWebVitals = true
|
|
40
40
|
}) {
|
|
41
41
|
const pathname = usePathname();
|
|
42
|
-
|
|
43
|
-
const properties = { pathname, referrer: document.referrer };
|
|
44
|
-
track("page_view", properties, { enableThirdPartyTracking: false });
|
|
45
|
-
}, [pathname]);
|
|
42
|
+
usePageViewAnalytics(pathname);
|
|
46
43
|
useReportWebVitals((metric) => {
|
|
47
44
|
if (!reportWebVitals) return;
|
|
48
45
|
const properties = {
|
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 {
|
|
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 { usePageViewAnalytics } from '../hooks/use-page-view-analytics';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { GaId, Gtag, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ntype HotjarId = `${number}`;\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (!window.gtag) {\n console.warn('GA has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const pathname = usePathname();\n usePageViewAnalytics(pathname);\n\n useReportWebVitals((metric) => {\n if (!reportWebVitals) return;\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {gaId && (\n <>\n <Script\n id=\"gtag\"\n nonce={nonce}\n src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <Script\n nonce={nonce}\n id=\"gtag-init\"\n dangerouslySetInnerHTML={{\n __html: `\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '${gaId}'${debugMode ? \" ,{ 'debug_mode': true }\" : ''});\n `,\n }}\n />\n </>\n )}\n {pixelId && (\n <Script\n id=\"pixel\"\n strategy=\"afterInteractive\"\n dangerouslySetInnerHTML={{\n __html: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '${pixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {hotjarId && (\n <Script\n id=\"hotjar\"\n strategy=\"afterInteractive\"\n dangerouslySetInnerHTML={{\n __html: `\n (function(h,o,t,j,a,r){\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\n h._hjSettings={hjid:${hotjarId},hjsv:6};\n a=o.getElementsByTagName('head')[0];\n r=o.createElement('script');r.async=1;\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\n a.appendChild(r);\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\n `,\n }}\n />\n )}\n </>\n );\n}\n"],"mappings":";;;AAEA,SAAS,mBAAmB;AAC5B,OAAO,YAAY;AACnB,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AA+EE,SAEhB,UAFgB,KAEhB,YAFgB;AAzDjB,SAAS,YACd,MACA,YACA;AACA,MAAI,CAAC,OAAO,MAAM;AAChB,YAAQ,KAAK,6BAA6B;AAC1C;AAAA,EACF;AACA,SAAO,KAAK,SAAS,MAAM,UAAU;AACvC;AAEO,SAAS,YACd,MACA,YACA,UACA;AACA,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;AAChD,YAAQ,KAAK,8BAA8B;AAC3C;AAAA,EACF;AACA,QAAM,EAAE,IAAI,IAAI;AAChB,QAAM,UAAU,EAAE,SAAS,SAAS;AACpC,QAAM,CAAC,MAAM,aAAa,iBAAiB,IAAI,WAAW,MAAM,UAAU;AAC1E,MAAI,SAAS,SAAS;AACpB,QAAI,MAAM,aAAa,mBAAmB,OAAO;AAAA,EACnD,OAAO;AACL,QAAI,MAAM,aAAa,mBAAmB,OAAO;AAAA,EACnD;AACF;AAEO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AACpB,GAAU;AACR,QAAM,WAAW,YAAY;AAC7B,uBAAqB,QAAQ;AAE7B,qBAAmB,CAAC,WAAW;AAC7B,QAAI,CAAC,gBAAiB;AACtB,UAAM,aAAa;AAAA,MACjB,IAAI,OAAO;AAAA,MACX,QAAQ,OAAO;AAAA,MACf,OAAO,OAAO;AAAA,MACd,OAAO,OAAO;AAAA,MACd,iBAAiB,OAAO;AAAA,MACxB,iBAAiB;AAAA;AAAA,IACnB;AACA,UAAM,OAAO,MAAM,UAAU;AAAA,EAC/B,CAAC;AAED,SACE,iCACG;AAAA,qBAAiB,oBAAC,UAAK,UAAS,aAAY,SAAS,eAAe;AAAA,IACpE,QACC,iCACE;AAAA;AAAA,QAAC;AAAA;AAAA,UACC,IAAG;AAAA,UACH;AAAA,UACA,KAAK,+CAA+C,IAAI;AAAA;AAAA,MAC1D;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,IAAG;AAAA,UACH,yBAAyB;AAAA,YACvB,QAAQ;AAAA;AAAA;AAAA;AAAA,gCAIU,IAAI,IAAI,YAAY,6BAA6B,EAAE;AAAA;AAAA,UAEvE;AAAA;AAAA,MACF;AAAA,OACF;AAAA,IAED,WACC;AAAA,MAAC;AAAA;AAAA,QACC,IAAG;AAAA,QACH,UAAS;AAAA,QACT,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAiBO,OAAO;AAAA;AAAA,QAExB;AAAA;AAAA,IACF;AAAA,IAED,YACC;AAAA,MAAC;AAAA;AAAA,QACC,IAAG;AAAA,QACH,UAAS;AAAA,QACT,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA,oCAGgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOlC;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -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_use_page_view_analytics = require("../hooks/use-page-view-analytics.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");
|
|
@@ -71,11 +72,7 @@ function Analytics({
|
|
|
71
72
|
reportWebVitals = true
|
|
72
73
|
}) {
|
|
73
74
|
const { pathname } = (0, import_react_router.useLocation)();
|
|
74
|
-
|
|
75
|
-
(0, import_react.useEffect)(() => {
|
|
76
|
-
const properties = { pathname, referrer: document.referrer };
|
|
77
|
-
(0, import_track.track)("page_view", properties, { enableThirdPartyTracking: false });
|
|
78
|
-
}, [pathname, params]);
|
|
75
|
+
(0, import_use_page_view_analytics.usePageViewAnalytics)(pathname);
|
|
79
76
|
useReportWebVitals((metric) => {
|
|
80
77
|
if (!reportWebVitals) return;
|
|
81
78
|
const properties = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation
|
|
1
|
+
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router';\nimport { type Metric, onCLS, onFCP, onINP, onLCP, onTTFB } from 'web-vitals';\nimport { usePageViewAnalytics } from '../hooks/use-page-view-analytics';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { GaId, Gtag, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ntype HotjarId = `${number}`;\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('gtag has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const { pathname } = useLocation();\n usePageViewAnalytics(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 async\n id=\"gtag\"\n nonce={nonce}\n src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <script\n async\n nonce={nonce}\n id=\"gtag-init\"\n dangerouslySetInnerHTML={{\n __html: `\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '${gaId}'${debugMode ? \" ,{ 'debug_mode': true }\" : ''});\n `,\n }}\n />\n </>\n )}\n {pixelId && (\n <script\n async\n id=\"pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '${pixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {hotjarId && (\n <script\n async\n id=\"hotjar\"\n dangerouslySetInnerHTML={{\n __html: `\n (function(h,o,t,j,a,r){\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\n h._hjSettings={hjid:${hotjarId},hjsv:6};\n a=o.getElementsByTagName('head')[0];\n r=o.createElement('script');r.async=1;\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\n a.appendChild(r);\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\n `,\n }}\n />\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,0BAA4B;AAC5B,wBAAgE;AAChE,qCAAqC;AACrC,iBAA2B;AAC3B,mBAAsB;AAyFE;AAlFxB,SAAS,mBAAmB,mBAA6C;AACvE,8BAAU,MAAM;AACd,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,kCAAO,iBAAiB;AAAA,EAC1B,GAAG,CAAC,iBAAiB,CAAC;AACxB;AAiBO,SAAS,YACd,MACA,YACA;AACA,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;AACjD,YAAQ,KAAK,+BAA+B;AAC5C;AAA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AA,gCAIU,IAAI,IAAI,YAAY,6BAA6B,EAAE;AAAA;AAAA,UAEvE;AAAA;AAAA,MACF;AAAA,OACF;AAAA,IAED,WACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAK;AAAA,QACL,IAAG;AAAA,QACH,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAiBO,OAAO;AAAA;AAAA,QAExB;AAAA;AAAA,IACF;AAAA,IAED,YACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAK;AAAA,QACL,IAAG;AAAA,QACH,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA,oCAGgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOlC;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":[]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/react-router/index.tsx
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
-
import { useLocation
|
|
3
|
+
import { useLocation } from "react-router";
|
|
4
4
|
import { onCLS, onFCP, onINP, onLCP, onTTFB } from "web-vitals";
|
|
5
|
+
import { usePageViewAnalytics } from "../hooks/use-page-view-analytics.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";
|
|
@@ -45,11 +46,7 @@ function Analytics({
|
|
|
45
46
|
reportWebVitals = true
|
|
46
47
|
}) {
|
|
47
48
|
const { pathname } = useLocation();
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
const properties = { pathname, referrer: document.referrer };
|
|
51
|
-
track("page_view", properties, { enableThirdPartyTracking: false });
|
|
52
|
-
}, [pathname, params]);
|
|
49
|
+
usePageViewAnalytics(pathname);
|
|
53
50
|
useReportWebVitals((metric) => {
|
|
54
51
|
if (!reportWebVitals) return;
|
|
55
52
|
const properties = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation
|
|
1
|
+
{"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from 'react-router';\nimport { type Metric, onCLS, onFCP, onINP, onLCP, onTTFB } from 'web-vitals';\nimport { usePageViewAnalytics } from '../hooks/use-page-view-analytics';\nimport { mapFBEvent } from '../track/fbq';\nimport { track } from '../track/index';\nimport type { Pixel, PixelId } from '../track/fbq';\nimport type { GaId, Gtag, GtmId } from '../track/gtag';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\ntype HotjarId = `${number}`;\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\ndeclare global {\n interface Window extends Gtag, Pixel {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('gtag has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n const { fbq } = window;\n const options = { eventID: event_id };\n const [type, fbEventName, fbEventProperties] = mapFBEvent(name, properties);\n if (type === 'track') {\n fbq(type, fbEventName, fbEventProperties, options);\n } else {\n fbq(type, fbEventName, fbEventProperties, options);\n }\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n pixelId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n const { pathname } = useLocation();\n usePageViewAnalytics(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 async\n id=\"gtag\"\n nonce={nonce}\n src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <script\n async\n nonce={nonce}\n id=\"gtag-init\"\n dangerouslySetInnerHTML={{\n __html: `\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '${gaId}'${debugMode ? \" ,{ 'debug_mode': true }\" : ''});\n `,\n }}\n />\n </>\n )}\n {pixelId && (\n <script\n async\n id=\"pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '${pixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {hotjarId && (\n <script\n async\n id=\"hotjar\"\n dangerouslySetInnerHTML={{\n __html: `\n (function(h,o,t,j,a,r){\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\n h._hjSettings={hjid:${hotjarId},hjsv:6};\n a=o.getElementsByTagName('head')[0];\n r=o.createElement('script');r.async=1;\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\n a.appendChild(r);\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\n `,\n }}\n />\n )}\n </>\n );\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAsB,OAAO,OAAO,OAAO,OAAO,cAAc;AAChE,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AAyFE,SAEhB,UAFgB,KAEhB,YAFgB;AAlFxB,SAAS,mBAAmB,mBAA6C;AACvE,YAAU,MAAM;AACd,UAAM,iBAAiB;AACvB,UAAM,iBAAiB;AACvB,UAAM,iBAAiB;AACvB,UAAM,iBAAiB;AACvB,WAAO,iBAAiB;AAAA,EAC1B,GAAG,CAAC,iBAAiB,CAAC;AACxB;AAiBO,SAAS,YACd,MACA,YACA;AACA,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,MAAM;AACjD,YAAQ,KAAK,+BAA+B;AAC5C;AAAA,EACF;AACA,SAAO,KAAK,SAAS,MAAM,UAAU;AACvC;AAEO,SAAS,YACd,MACA,YACA,UACA;AACA,MAAI,OAAO,WAAW,eAAe,CAAC,OAAO,KAAK;AAChD,YAAQ,KAAK,8BAA8B;AAC3C;AAAA,EACF;AACA,QAAM,EAAE,IAAI,IAAI;AAChB,QAAM,UAAU,EAAE,SAAS,SAAS;AACpC,QAAM,CAAC,MAAM,aAAa,iBAAiB,IAAI,WAAW,MAAM,UAAU;AAC1E,MAAI,SAAS,SAAS;AACpB,QAAI,MAAM,aAAa,mBAAmB,OAAO;AAAA,EACnD,OAAO;AACL,QAAI,MAAM,aAAa,mBAAmB,OAAO;AAAA,EACnD;AACF;AAEO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA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