@shware/analytics 3.0.9 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,206 @@
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/tanstack/index.tsx
21
+ var tanstack_exports = {};
22
+ __export(tanstack_exports, {
23
+ Analytics: () => Analytics
24
+ });
25
+ module.exports = __toCommonJS(tanstack_exports);
26
+ var import_react = require("react");
27
+ var import_react_router = require("@tanstack/react-router");
28
+ var import_web_vitals = require("web-vitals");
29
+ var import_use_click_id_persistence = require("../hooks/use-click-id-persistence.cjs");
30
+ var import_use_outbound_click_analytics = require("../hooks/use-outbound-click-analytics.cjs");
31
+ var import_use_web_analytics = require("../hooks/use-web-analytics.cjs");
32
+ var import_track = require("../track/index.cjs");
33
+ var import_jsx_runtime = require("react/jsx-runtime");
34
+ function useReportWebVitals(reportWebVitalsFn) {
35
+ (0, import_react.useEffect)(() => {
36
+ (0, import_web_vitals.onCLS)(reportWebVitalsFn);
37
+ (0, import_web_vitals.onLCP)(reportWebVitalsFn);
38
+ (0, import_web_vitals.onINP)(reportWebVitalsFn);
39
+ (0, import_web_vitals.onFCP)(reportWebVitalsFn);
40
+ (0, import_web_vitals.onTTFB)(reportWebVitalsFn);
41
+ }, [reportWebVitalsFn]);
42
+ }
43
+ function Analytics({
44
+ gaId,
45
+ nonce,
46
+ debugMode,
47
+ metaPixelId,
48
+ redditPixelId,
49
+ linkedInPartnerId,
50
+ hotjarId,
51
+ facebookAppId,
52
+ reportWebVitals = true
53
+ }) {
54
+ (0, import_use_click_id_persistence.useClickIdPersistence)();
55
+ const { pathname } = (0, import_react_router.useLocation)();
56
+ (0, import_use_web_analytics.useWebAnalytics)(pathname);
57
+ (0, import_use_outbound_click_analytics.useOutboundClickAnalytics)();
58
+ useReportWebVitals((metric) => {
59
+ if (!reportWebVitals) return;
60
+ const properties = {
61
+ id: metric.id,
62
+ rating: metric.rating,
63
+ value: metric.value,
64
+ delta: metric.delta,
65
+ navigation_type: metric.navigationType,
66
+ non_interaction: true
67
+ // avoids affecting bounce rate.
68
+ };
69
+ (0, import_track.track)(metric.name, properties);
70
+ });
71
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
72
+ facebookAppId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("meta", { property: "fb:app_id", content: facebookAppId }),
73
+ gaId && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
74
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
75
+ "script",
76
+ {
77
+ async: true,
78
+ id: "gtag",
79
+ nonce,
80
+ src: `https://www.googletagmanager.com/gtag/js?id=${gaId}`
81
+ }
82
+ ),
83
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
84
+ "script",
85
+ {
86
+ async: true,
87
+ nonce,
88
+ id: "gtag-init",
89
+ dangerouslySetInnerHTML: {
90
+ __html: `
91
+ window.dataLayer = window.dataLayer || [];
92
+ function gtag(){dataLayer.push(arguments);}
93
+ gtag('js', new Date());
94
+ gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
95
+ `
96
+ }
97
+ }
98
+ )
99
+ ] }),
100
+ metaPixelId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
101
+ "script",
102
+ {
103
+ async: true,
104
+ id: "meta-pixel",
105
+ dangerouslySetInnerHTML: {
106
+ __html: `
107
+ !(function (f, b, e, v, n, t, s) {
108
+ if (f.fbq) return;
109
+ n = f.fbq = function () {
110
+ n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
111
+ };
112
+ if (!f._fbq) f._fbq = n;
113
+ n.push = n;
114
+ n.loaded = !0;
115
+ n.version = '2.0';
116
+ n.queue = [];
117
+ t = b.createElement(e);
118
+ t.async = !0;
119
+ t.src = v;
120
+ s = b.getElementsByTagName(e)[0];
121
+ s.parentNode.insertBefore(t, s);
122
+ })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
123
+ fbq('init', '${metaPixelId}');
124
+ fbq('track', 'PageView');`
125
+ }
126
+ }
127
+ ),
128
+ redditPixelId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
129
+ "script",
130
+ {
131
+ async: true,
132
+ id: "reddit-pixel",
133
+ dangerouslySetInnerHTML: {
134
+ __html: `
135
+ !function(w,d) {
136
+ if(!w.rdt) {
137
+ var p = w.rdt = function() {
138
+ p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)
139
+ };
140
+ p.callQueue = [];
141
+ var t = d.createElement("script");
142
+ t.src = "https://www.redditstatic.com/ads/pixel.js";
143
+ t.async = !0;
144
+ var s = d.getElementsByTagName("script")[0];
145
+ s.parentNode.insertBefore(t,s)
146
+ }
147
+ }(window, document);
148
+ rdt('init', '${redditPixelId}');
149
+ rdt('track', 'PageVisit');`
150
+ }
151
+ }
152
+ ),
153
+ linkedInPartnerId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
154
+ "script",
155
+ {
156
+ async: true,
157
+ id: "linkedin-insight-tag",
158
+ dangerouslySetInnerHTML: {
159
+ __html: `
160
+ _linkedin_partner_id = "${linkedInPartnerId}";
161
+ window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
162
+ window._linkedin_data_partner_ids.push(_linkedin_partner_id);
163
+
164
+ (function(l) {
165
+ if (!l){
166
+ window.lintrk = function(a,b){
167
+ window.lintrk.q.push([a,b])
168
+ };
169
+ window.lintrk.q=[]
170
+ }
171
+ var s = document.getElementsByTagName("script")[0];
172
+ var b = document.createElement("script");
173
+ b.type = "text/javascript";b.async = true;
174
+ b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
175
+ s.parentNode.insertBefore(b, s);
176
+ })(window.lintrk);
177
+ `
178
+ }
179
+ }
180
+ ),
181
+ hotjarId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
182
+ "script",
183
+ {
184
+ async: true,
185
+ id: "hotjar",
186
+ dangerouslySetInnerHTML: {
187
+ __html: `
188
+ (function(h,o,t,j,a,r){
189
+ h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
190
+ h._hjSettings={hjid:${hotjarId},hjsv:6};
191
+ a=o.getElementsByTagName('head')[0];
192
+ r=o.createElement('script');r.async=1;
193
+ r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
194
+ a.appendChild(r);
195
+ })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
196
+ `
197
+ }
198
+ }
199
+ )
200
+ ] });
201
+ }
202
+ // Annotate the CommonJS export names for ESM import in node:
203
+ 0 && (module.exports = {
204
+ Analytics
205
+ });
206
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/tanstack/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from '@tanstack/react-router';\nimport { type Metric, onCLS, onFCP, onINP, onLCP, onTTFB } from 'web-vitals';\nimport { useClickIdPersistence } from '../hooks/use-click-id-persistence';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { track } from '../track/index';\nimport type { PixelId as MetaPixelId } from '../track/fbq';\nimport type { GaId, GtmId } from '../track/gtag';\nimport type { PixelId as RedditPixelId } from '../track/rdt';\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\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n metaPixelId?: MetaPixelId;\n redditPixelId?: RedditPixelId;\n linkedInPartnerId?: `${number}`;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n metaPixelId,\n redditPixelId,\n linkedInPartnerId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n useClickIdPersistence();\n\n const { pathname } = useLocation();\n useWebAnalytics(pathname);\n useOutboundClickAnalytics();\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 {metaPixelId && (\n <script\n async\n id=\"meta-pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '${metaPixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {redditPixelId && (\n <script\n async\n id=\"reddit-pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n !function(w,d) {\n if(!w.rdt) {\n var p = w.rdt = function() {\n p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)\n };\n p.callQueue = [];\n var t = d.createElement(\"script\");\n t.src = \"https://www.redditstatic.com/ads/pixel.js\";\n t.async = !0;\n var s = d.getElementsByTagName(\"script\")[0];\n s.parentNode.insertBefore(t,s)\n }\n }(window, document);\n rdt('init', '${redditPixelId}');\n rdt('track', 'PageVisit');`,\n }}\n />\n )}\n {linkedInPartnerId && (\n <script\n async\n id=\"linkedin-insight-tag\"\n dangerouslySetInnerHTML={{\n __html: `\n _linkedin_partner_id = \"${linkedInPartnerId}\";\n window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];\n window._linkedin_data_partner_ids.push(_linkedin_partner_id);\n\n (function(l) {\n if (!l){\n window.lintrk = function(a,b){\n window.lintrk.q.push([a,b])\n };\n window.lintrk.q=[]\n }\n var s = document.getElementsByTagName(\"script\")[0];\n var b = document.createElement(\"script\");\n b.type = \"text/javascript\";b.async = true;\n b.src = \"https://snap.licdn.com/li.lms-analytics/insight.min.js\";\n s.parentNode.insertBefore(b, s);\n })(window.lintrk);\n `,\n }}\n />\n )}\n {hotjarId && (\n <script\n async\n id=\"hotjar\"\n dangerouslySetInnerHTML={{\n __html: `\n (function(h,o,t,j,a,r){\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\n h._hjSettings={hjid:${hotjarId},hjsv:6};\n a=o.getElementsByTagName('head')[0];\n r=o.createElement('script');r.async=1;\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\n a.appendChild(r);\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\n `,\n }}\n />\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,0BAA4B;AAC5B,wBAAgE;AAChE,sCAAsC;AACtC,0CAA0C;AAC1C,+BAAgC;AAChC,mBAAsB;AA8DE;AAvDxB,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;AAeO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AACpB,GAAU;AACR,6DAAsB;AAEtB,QAAM,EAAE,SAAS,QAAI,iCAAY;AACjC,gDAAgB,QAAQ;AACxB,qEAA0B;AAE1B,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,4BAAM,OAAO,MAAM,UAAU;AAAA,EAC/B,CAAC;AAED,SACE,4EACG;AAAA,qBAAiB,4CAAC,UAAK,UAAS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AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA,oCAGgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOlC;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":[]}
@@ -0,0 +1,22 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { PixelId } from '../track/fbq.cjs';
3
+ import { GaId, GtmId } from '../track/gtag.cjs';
4
+ import { PixelId as PixelId$1 } from '../track/rdt.cjs';
5
+ import '../track/types.cjs';
6
+
7
+ type HotjarId = `${number}`;
8
+ interface Props {
9
+ gaId?: GaId;
10
+ gtmId?: GtmId;
11
+ metaPixelId?: PixelId;
12
+ redditPixelId?: PixelId$1;
13
+ linkedInPartnerId?: `${number}`;
14
+ hotjarId?: HotjarId;
15
+ facebookAppId?: string;
16
+ nonce?: string;
17
+ debugMode?: boolean;
18
+ reportWebVitals?: boolean;
19
+ }
20
+ declare function Analytics({ gaId, nonce, debugMode, metaPixelId, redditPixelId, linkedInPartnerId, hotjarId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
21
+
22
+ export { Analytics };
@@ -0,0 +1,22 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { PixelId } from '../track/fbq.js';
3
+ import { GaId, GtmId } from '../track/gtag.js';
4
+ import { PixelId as PixelId$1 } from '../track/rdt.js';
5
+ import '../track/types.js';
6
+
7
+ type HotjarId = `${number}`;
8
+ interface Props {
9
+ gaId?: GaId;
10
+ gtmId?: GtmId;
11
+ metaPixelId?: PixelId;
12
+ redditPixelId?: PixelId$1;
13
+ linkedInPartnerId?: `${number}`;
14
+ hotjarId?: HotjarId;
15
+ facebookAppId?: string;
16
+ nonce?: string;
17
+ debugMode?: boolean;
18
+ reportWebVitals?: boolean;
19
+ }
20
+ declare function Analytics({ gaId, nonce, debugMode, metaPixelId, redditPixelId, linkedInPartnerId, hotjarId, facebookAppId, reportWebVitals, }: Props): react_jsx_runtime.JSX.Element;
21
+
22
+ export { Analytics };
@@ -0,0 +1,181 @@
1
+ // src/tanstack/index.tsx
2
+ import { useEffect } from "react";
3
+ import { useLocation } from "@tanstack/react-router";
4
+ import { onCLS, onFCP, onINP, onLCP, onTTFB } from "web-vitals";
5
+ import { useClickIdPersistence } from "../hooks/use-click-id-persistence.mjs";
6
+ import { useOutboundClickAnalytics } from "../hooks/use-outbound-click-analytics.mjs";
7
+ import { useWebAnalytics } from "../hooks/use-web-analytics.mjs";
8
+ import { track } from "../track/index.mjs";
9
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
+ function useReportWebVitals(reportWebVitalsFn) {
11
+ useEffect(() => {
12
+ onCLS(reportWebVitalsFn);
13
+ onLCP(reportWebVitalsFn);
14
+ onINP(reportWebVitalsFn);
15
+ onFCP(reportWebVitalsFn);
16
+ onTTFB(reportWebVitalsFn);
17
+ }, [reportWebVitalsFn]);
18
+ }
19
+ function Analytics({
20
+ gaId,
21
+ nonce,
22
+ debugMode,
23
+ metaPixelId,
24
+ redditPixelId,
25
+ linkedInPartnerId,
26
+ hotjarId,
27
+ facebookAppId,
28
+ reportWebVitals = true
29
+ }) {
30
+ useClickIdPersistence();
31
+ const { pathname } = useLocation();
32
+ useWebAnalytics(pathname);
33
+ useOutboundClickAnalytics();
34
+ useReportWebVitals((metric) => {
35
+ if (!reportWebVitals) return;
36
+ const properties = {
37
+ id: metric.id,
38
+ rating: metric.rating,
39
+ value: metric.value,
40
+ delta: metric.delta,
41
+ navigation_type: metric.navigationType,
42
+ non_interaction: true
43
+ // avoids affecting bounce rate.
44
+ };
45
+ track(metric.name, properties);
46
+ });
47
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
48
+ facebookAppId && /* @__PURE__ */ jsx("meta", { property: "fb:app_id", content: facebookAppId }),
49
+ gaId && /* @__PURE__ */ jsxs(Fragment, { children: [
50
+ /* @__PURE__ */ jsx(
51
+ "script",
52
+ {
53
+ async: true,
54
+ id: "gtag",
55
+ nonce,
56
+ src: `https://www.googletagmanager.com/gtag/js?id=${gaId}`
57
+ }
58
+ ),
59
+ /* @__PURE__ */ jsx(
60
+ "script",
61
+ {
62
+ async: true,
63
+ nonce,
64
+ id: "gtag-init",
65
+ dangerouslySetInnerHTML: {
66
+ __html: `
67
+ window.dataLayer = window.dataLayer || [];
68
+ function gtag(){dataLayer.push(arguments);}
69
+ gtag('js', new Date());
70
+ gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
71
+ `
72
+ }
73
+ }
74
+ )
75
+ ] }),
76
+ metaPixelId && /* @__PURE__ */ jsx(
77
+ "script",
78
+ {
79
+ async: true,
80
+ id: "meta-pixel",
81
+ dangerouslySetInnerHTML: {
82
+ __html: `
83
+ !(function (f, b, e, v, n, t, s) {
84
+ if (f.fbq) return;
85
+ n = f.fbq = function () {
86
+ n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
87
+ };
88
+ if (!f._fbq) f._fbq = n;
89
+ n.push = n;
90
+ n.loaded = !0;
91
+ n.version = '2.0';
92
+ n.queue = [];
93
+ t = b.createElement(e);
94
+ t.async = !0;
95
+ t.src = v;
96
+ s = b.getElementsByTagName(e)[0];
97
+ s.parentNode.insertBefore(t, s);
98
+ })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
99
+ fbq('init', '${metaPixelId}');
100
+ fbq('track', 'PageView');`
101
+ }
102
+ }
103
+ ),
104
+ redditPixelId && /* @__PURE__ */ jsx(
105
+ "script",
106
+ {
107
+ async: true,
108
+ id: "reddit-pixel",
109
+ dangerouslySetInnerHTML: {
110
+ __html: `
111
+ !function(w,d) {
112
+ if(!w.rdt) {
113
+ var p = w.rdt = function() {
114
+ p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)
115
+ };
116
+ p.callQueue = [];
117
+ var t = d.createElement("script");
118
+ t.src = "https://www.redditstatic.com/ads/pixel.js";
119
+ t.async = !0;
120
+ var s = d.getElementsByTagName("script")[0];
121
+ s.parentNode.insertBefore(t,s)
122
+ }
123
+ }(window, document);
124
+ rdt('init', '${redditPixelId}');
125
+ rdt('track', 'PageVisit');`
126
+ }
127
+ }
128
+ ),
129
+ linkedInPartnerId && /* @__PURE__ */ jsx(
130
+ "script",
131
+ {
132
+ async: true,
133
+ id: "linkedin-insight-tag",
134
+ dangerouslySetInnerHTML: {
135
+ __html: `
136
+ _linkedin_partner_id = "${linkedInPartnerId}";
137
+ window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
138
+ window._linkedin_data_partner_ids.push(_linkedin_partner_id);
139
+
140
+ (function(l) {
141
+ if (!l){
142
+ window.lintrk = function(a,b){
143
+ window.lintrk.q.push([a,b])
144
+ };
145
+ window.lintrk.q=[]
146
+ }
147
+ var s = document.getElementsByTagName("script")[0];
148
+ var b = document.createElement("script");
149
+ b.type = "text/javascript";b.async = true;
150
+ b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
151
+ s.parentNode.insertBefore(b, s);
152
+ })(window.lintrk);
153
+ `
154
+ }
155
+ }
156
+ ),
157
+ hotjarId && /* @__PURE__ */ jsx(
158
+ "script",
159
+ {
160
+ async: true,
161
+ id: "hotjar",
162
+ dangerouslySetInnerHTML: {
163
+ __html: `
164
+ (function(h,o,t,j,a,r){
165
+ h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
166
+ h._hjSettings={hjid:${hotjarId},hjsv:6};
167
+ a=o.getElementsByTagName('head')[0];
168
+ r=o.createElement('script');r.async=1;
169
+ r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
170
+ a.appendChild(r);
171
+ })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
172
+ `
173
+ }
174
+ }
175
+ )
176
+ ] });
177
+ }
178
+ export {
179
+ Analytics
180
+ };
181
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/tanstack/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation } from '@tanstack/react-router';\nimport { type Metric, onCLS, onFCP, onINP, onLCP, onTTFB } from 'web-vitals';\nimport { useClickIdPersistence } from '../hooks/use-click-id-persistence';\nimport { useOutboundClickAnalytics } from '../hooks/use-outbound-click-analytics';\nimport { useWebAnalytics } from '../hooks/use-web-analytics';\nimport { track } from '../track/index';\nimport type { PixelId as MetaPixelId } from '../track/fbq';\nimport type { GaId, GtmId } from '../track/gtag';\nimport type { PixelId as RedditPixelId } from '../track/rdt';\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\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n metaPixelId?: MetaPixelId;\n redditPixelId?: RedditPixelId;\n linkedInPartnerId?: `${number}`;\n hotjarId?: HotjarId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n reportWebVitals?: boolean;\n}\n\nexport function Analytics({\n gaId,\n nonce,\n debugMode,\n metaPixelId,\n redditPixelId,\n linkedInPartnerId,\n hotjarId,\n facebookAppId,\n reportWebVitals = true,\n}: Props) {\n useClickIdPersistence();\n\n const { pathname } = useLocation();\n useWebAnalytics(pathname);\n useOutboundClickAnalytics();\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 {metaPixelId && (\n <script\n async\n id=\"meta-pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '${metaPixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n )}\n {redditPixelId && (\n <script\n async\n id=\"reddit-pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n !function(w,d) {\n if(!w.rdt) {\n var p = w.rdt = function() {\n p.sendEvent ? p.sendEvent.apply(p,arguments) : p.callQueue.push(arguments)\n };\n p.callQueue = [];\n var t = d.createElement(\"script\");\n t.src = \"https://www.redditstatic.com/ads/pixel.js\";\n t.async = !0;\n var s = d.getElementsByTagName(\"script\")[0];\n s.parentNode.insertBefore(t,s)\n }\n }(window, document);\n rdt('init', '${redditPixelId}');\n rdt('track', 'PageVisit');`,\n }}\n />\n )}\n {linkedInPartnerId && (\n <script\n async\n id=\"linkedin-insight-tag\"\n dangerouslySetInnerHTML={{\n __html: `\n _linkedin_partner_id = \"${linkedInPartnerId}\";\n window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];\n window._linkedin_data_partner_ids.push(_linkedin_partner_id);\n\n (function(l) {\n if (!l){\n window.lintrk = function(a,b){\n window.lintrk.q.push([a,b])\n };\n window.lintrk.q=[]\n }\n var s = document.getElementsByTagName(\"script\")[0];\n var b = document.createElement(\"script\");\n b.type = \"text/javascript\";b.async = true;\n b.src = \"https://snap.licdn.com/li.lms-analytics/insight.min.js\";\n s.parentNode.insertBefore(b, s);\n })(window.lintrk);\n `,\n }}\n />\n )}\n {hotjarId && (\n <script\n async\n id=\"hotjar\"\n dangerouslySetInnerHTML={{\n __html: `\n (function(h,o,t,j,a,r){\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\n h._hjSettings={hjid:${hotjarId},hjsv:6};\n a=o.getElementsByTagName('head')[0];\n r=o.createElement('script');r.async=1;\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\n a.appendChild(r);\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\n `,\n }}\n />\n )}\n </>\n );\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAsB,OAAO,OAAO,OAAO,OAAO,cAAc;AAChE,SAAS,6BAA6B;AACtC,SAAS,iCAAiC;AAC1C,SAAS,uBAAuB;AAChC,SAAS,aAAa;AA8DE,SAEhB,UAFgB,KAEhB,YAFgB;AAvDxB,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;AAeO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AACpB,GAAU;AACR,wBAAsB;AAEtB,QAAM,EAAE,SAAS,IAAI,YAAY;AACjC,kBAAgB,QAAQ;AACxB,4BAA0B;AAE1B,qBAAmB,CAAC,WAAW;AAC7B,QAAI,CAAC,gBAAiB;AACtB,UAAM,aAAa;AAAA,MACjB,IAAI,OAAO;AAAA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AiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAkB7C;AAAA;AAAA,IACF;AAAA,IAED,YACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAK;AAAA,QACL,IAAG;AAAA,QACH,yBAAyB;AAAA,UACvB,QAAQ;AAAA;AAAA;AAAA,oCAGgB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAOlC;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/analytics",
3
- "version": "3.0.9",
3
+ "version": "3.1.1",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,6 +46,11 @@
46
46
  "import": "./dist/react-router/index.mjs",
47
47
  "require": "./dist/react-router/index.cjs"
48
48
  },
49
+ "./tanstack": {
50
+ "types": "./dist/tanstack/index.d.ts",
51
+ "import": "./dist/tanstack/index.mjs",
52
+ "require": "./dist/tanstack/index.cjs"
53
+ },
49
54
  "./third-parties": {
50
55
  "types": "./dist/third-parties/index.d.ts",
51
56
  "import": "./dist/third-parties/index.mjs",
@@ -74,18 +79,19 @@
74
79
  "@repo/typescript-config": "0.0.0"
75
80
  },
76
81
  "peerDependencies": {
77
- "@react-native-firebase/analytics": "^23.3.1",
78
- "expo-application": "7.0.7",
79
- "expo-clipboard": "^8.0.7",
80
- "expo-crypto": "^15.0.7",
81
- "expo-device": "^8.0.9",
82
- "expo-localization": "^17.0.7",
83
- "expo-sqlite": "^16.0.8",
84
- "expo-tracking-transparency": "^6.0.7",
82
+ "@react-native-firebase/analytics": "^23.7.0",
83
+ "@tanstack/react-router": "^1.132.0",
84
+ "expo-application": "^7.0.8",
85
+ "expo-clipboard": "^8.0.8",
86
+ "expo-crypto": "^15.0.8",
87
+ "expo-device": "^8.0.10",
88
+ "expo-localization": "^17.0.8",
89
+ "expo-sqlite": "^16.0.10",
90
+ "expo-tracking-transparency": "^6.0.8",
85
91
  "facebook-nodejs-business-sdk": "^23",
86
92
  "next": "^15",
87
93
  "react": "^19",
88
- "react-native": "^0.81.4",
94
+ "react-native": "^0.81.5",
89
95
  "react-native-fbsdk-next": "^13.4.1",
90
96
  "react-native-url-polyfill": "^3",
91
97
  "react-router": "^7"
@@ -94,6 +100,9 @@
94
100
  "@react-native-firebase/analytics": {
95
101
  "optional": true
96
102
  },
103
+ "@tanstack/react-router": {
104
+ "optional": true
105
+ },
97
106
  "expo-application": {
98
107
  "optional": true
99
108
  },