@shware/analytics 0.1.16 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/index.cjs.map +1 -1
  2. package/dist/index.d.cts +3 -1
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/next/index.cjs +102 -5
  6. package/dist/next/index.cjs.map +1 -1
  7. package/dist/next/index.d.cts +21 -2
  8. package/dist/next/index.d.ts +21 -2
  9. package/dist/next/index.mjs +89 -4
  10. package/dist/next/index.mjs.map +1 -1
  11. package/dist/react-router/index.cjs +91 -4
  12. package/dist/react-router/index.cjs.map +1 -1
  13. package/dist/react-router/index.d.cts +21 -2
  14. package/dist/react-router/index.d.ts +21 -2
  15. package/dist/react-router/index.mjs +88 -3
  16. package/dist/react-router/index.mjs.map +1 -1
  17. package/dist/schema/index.d.cts +8 -8
  18. package/dist/schema/index.d.ts +8 -8
  19. package/dist/setup/index.cjs.map +1 -1
  20. package/dist/setup/index.d.cts +3 -1
  21. package/dist/setup/index.d.ts +3 -1
  22. package/dist/setup/index.mjs.map +1 -1
  23. package/dist/track/fbq.cjs +143 -0
  24. package/dist/track/fbq.cjs.map +1 -0
  25. package/dist/track/fbq.d.cts +278 -0
  26. package/dist/track/fbq.d.ts +278 -0
  27. package/dist/track/fbq.mjs +117 -0
  28. package/dist/track/fbq.mjs.map +1 -0
  29. package/dist/track/{ga.cjs → gtag.cjs} +5 -5
  30. package/dist/track/gtag.cjs.map +1 -0
  31. package/dist/track/gtag.d.cts +463 -0
  32. package/dist/track/gtag.d.ts +463 -0
  33. package/dist/track/{ga.mjs → gtag.mjs} +2 -2
  34. package/dist/track/gtag.mjs.map +1 -0
  35. package/dist/track/index.cjs.map +1 -1
  36. package/dist/track/index.d.cts +3 -2
  37. package/dist/track/index.d.ts +3 -2
  38. package/dist/track/index.mjs.map +1 -1
  39. package/dist/{types/index.cjs → track/types.cjs} +2 -2
  40. package/dist/track/types.cjs.map +1 -0
  41. package/dist/track/types.d.cts +87 -0
  42. package/dist/track/types.d.ts +87 -0
  43. package/dist/track/types.mjs +1 -0
  44. package/dist/visitor/index.cjs.map +1 -1
  45. package/dist/visitor/index.d.cts +1 -1
  46. package/dist/visitor/index.d.ts +1 -1
  47. package/dist/visitor/index.mjs.map +1 -1
  48. package/dist/visitor/types.cjs +19 -0
  49. package/dist/visitor/types.cjs.map +1 -0
  50. package/dist/visitor/types.d.cts +16 -0
  51. package/dist/visitor/types.d.ts +16 -0
  52. package/dist/visitor/types.mjs +1 -0
  53. package/dist/visitor/types.mjs.map +1 -0
  54. package/dist/web/index.cjs.map +1 -1
  55. package/dist/web/index.d.cts +2 -1
  56. package/dist/web/index.d.ts +2 -1
  57. package/dist/web/index.mjs.map +1 -1
  58. package/package.json +1 -1
  59. package/dist/track/ga.cjs.map +0 -1
  60. package/dist/track/ga.d.cts +0 -4
  61. package/dist/track/ga.d.ts +0 -4
  62. package/dist/track/ga.mjs.map +0 -1
  63. package/dist/types/index.cjs.map +0 -1
  64. package/dist/types/index.d.cts +0 -327
  65. package/dist/types/index.d.ts +0 -327
  66. package/dist/types/index.mjs +0 -1
  67. /package/dist/{types/index.mjs.map → track/types.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { setupAnalytics } from './setup/index';\nexport { track } from './track/index';\nexport { getVisitor, setVisitor } from './visitor/index';\nexport { createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from './schema/index';\nexport { type VisitorProperties, type TrackProperties, type TrackTags } from './types/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,mBAAsB;AACtB,qBAAuC;AACvC,oBAAiF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { setupAnalytics } from './setup/index';\nexport { track } from './track/index';\nexport { getVisitor, setVisitor } from './visitor/index';\nexport { createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from './schema/index';\nexport type { TrackProperties, TrackTags } from './track/types';\nexport type { VisitorProperties } from './visitor/types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,mBAAsB;AACtB,qBAAuC;AACvC,oBAAiF;","names":[]}
package/dist/index.d.cts CHANGED
@@ -2,6 +2,8 @@ export { setupAnalytics } from './setup/index.cjs';
2
2
  export { track } from './track/index.cjs';
3
3
  export { getVisitor, setVisitor } from './visitor/index.cjs';
4
4
  export { createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from './schema/index.cjs';
5
- export { TrackProperties, TrackTags, VisitorProperties } from './types/index.cjs';
5
+ export { TrackProperties, TrackTags } from './track/types.cjs';
6
+ export { VisitorProperties } from './visitor/types.cjs';
6
7
  import 'axios';
7
8
  import 'zod';
9
+ import './track/gtag.cjs';
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ export { setupAnalytics } from './setup/index.js';
2
2
  export { track } from './track/index.js';
3
3
  export { getVisitor, setVisitor } from './visitor/index.js';
4
4
  export { createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from './schema/index.js';
5
- export { TrackProperties, TrackTags, VisitorProperties } from './types/index.js';
5
+ export { TrackProperties, TrackTags } from './track/types.js';
6
+ export { VisitorProperties } from './visitor/types.js';
6
7
  import 'axios';
7
8
  import 'zod';
9
+ import './track/gtag.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { setupAnalytics } from './setup/index';\nexport { track } from './track/index';\nexport { getVisitor, setVisitor } from './visitor/index';\nexport { createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from './schema/index';\nexport { type VisitorProperties, type TrackProperties, type TrackTags } from './types/index';\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,aAAa;AACtB,SAAS,YAAY,kBAAkB;AACvC,SAAS,wBAAwB,qBAAqB,2BAA2B;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { setupAnalytics } from './setup/index';\nexport { track } from './track/index';\nexport { getVisitor, setVisitor } from './visitor/index';\nexport { createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from './schema/index';\nexport type { TrackProperties, TrackTags } from './track/types';\nexport type { VisitorProperties } from './visitor/types';\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,SAAS,aAAa;AACtB,SAAS,YAAY,kBAAkB;AACvC,SAAS,wBAAwB,qBAAqB,2BAA2B;","names":[]}
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  "use client";
3
+ var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
9
  var __export = (target, all) => {
8
10
  for (var name in all)
@@ -16,19 +18,46 @@ var __copyProps = (to, from, except, desc) => {
16
18
  }
17
19
  return to;
18
20
  };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
 
21
31
  // src/next/index.tsx
22
32
  var next_exports = {};
23
33
  __export(next_exports, {
24
- Analytics: () => Analytics
34
+ Analytics: () => Analytics,
35
+ sendFBEvent: () => sendFBEvent,
36
+ sendGAEvent: () => sendGAEvent
25
37
  });
26
38
  module.exports = __toCommonJS(next_exports);
39
+ var import_react = require("react");
27
40
  var import_navigation = require("next/navigation");
28
41
  var import_web_vitals = require("next/web-vitals");
29
- var import_react = require("react");
42
+ var import_script = __toESM(require("next/script"), 1);
30
43
  var import_track = require("../track/index.cjs");
31
- function Analytics() {
44
+ var import_fbq = require("../track/fbq.cjs");
45
+ var import_jsx_runtime = require("react/jsx-runtime");
46
+ function sendGAEvent(name, properties) {
47
+ if (!window.gtag) {
48
+ console.warn("GA has not been initialized");
49
+ return;
50
+ }
51
+ window.gtag("event", name, properties);
52
+ }
53
+ function sendFBEvent(name, properties, event_id) {
54
+ if (typeof window === "undefined" || !window.fbq) {
55
+ console.warn("fbq has not been initialized");
56
+ return;
57
+ }
58
+ (0, import_fbq.mapAndSendFbqEvent)(window.fbq, name, properties, { eventID: event_id });
59
+ }
60
+ function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }) {
32
61
  const pathname = (0, import_navigation.usePathname)();
33
62
  const params = (0, import_navigation.useSearchParams)();
34
63
  (0, import_react.useEffect)(() => {
@@ -57,10 +86,78 @@ function Analytics() {
57
86
  };
58
87
  (0, import_track.track)(metric.name, properties);
59
88
  });
60
- return null;
89
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
90
+ facebookAppId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("meta", { property: "fb:app_id", content: facebookAppId }),
91
+ gaId && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
92
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
93
+ import_script.default,
94
+ {
95
+ id: "gtag",
96
+ nonce,
97
+ src: `https://www.googletagmanager.com/gtag/js?id=${gaId}`
98
+ }
99
+ ),
100
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
101
+ import_script.default,
102
+ {
103
+ nonce,
104
+ id: "gtag-init",
105
+ dangerouslySetInnerHTML: {
106
+ __html: `
107
+ window.dataLayer = window.dataLayer || [];
108
+ function gtag(){dataLayer.push(arguments);}
109
+ gtag('js', new Date());
110
+ gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
111
+ `
112
+ }
113
+ }
114
+ )
115
+ ] }),
116
+ pixelId && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
117
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
118
+ import_script.default,
119
+ {
120
+ id: "pixel",
121
+ strategy: "afterInteractive",
122
+ dangerouslySetInnerHTML: {
123
+ __html: `
124
+ !(function (f, b, e, v, n, t, s) {
125
+ if (f.fbq) return;
126
+ n = f.fbq = function () {
127
+ n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
128
+ };
129
+ if (!f._fbq) f._fbq = n;
130
+ n.push = n;
131
+ n.loaded = !0;
132
+ n.version = '2.0';
133
+ n.queue = [];
134
+ t = b.createElement(e);
135
+ t.async = !0;
136
+ t.src = v;
137
+ s = b.getElementsByTagName(e)[0];
138
+ s.parentNode.insertBefore(t, s);
139
+ })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
140
+ fbq('init', '${pixelId}');
141
+ fbq('track', 'PageView');`
142
+ }
143
+ }
144
+ ),
145
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("noscript", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
146
+ "img",
147
+ {
148
+ width: "1",
149
+ height: "1",
150
+ style: { display: "none" },
151
+ src: `https://www.facebook.com/tr?id=${pixelId}&ev=PageView&noscript=1`
152
+ }
153
+ ) })
154
+ ] })
155
+ ] });
61
156
  }
62
157
  // Annotate the CommonJS export names for ESM import in node:
63
158
  0 && (module.exports = {
64
- Analytics
159
+ Analytics,
160
+ sendFBEvent,
161
+ sendGAEvent
65
162
  });
66
163
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { useEffect } from 'react';\nimport { track } from '../track/index';\n\nexport function Analytics() {\n const pathname = usePathname();\n const params = useSearchParams();\n\n useEffect(() => {\n const properties = {\n pathname,\n referrer: document.referrer,\n gclid: params.get('gclid'),\n fbclid: params.get('fbclid'),\n utm_source: params.get('utm_source'),\n utm_medium: params.get('utm_medium'),\n utm_campaign: params.get('utm_campaign'),\n utm_term: params.get('utm_term'),\n utm_content: params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name as Lowercase<string>, properties);\n });\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,wBAA6C;AAC7C,wBAAmC;AACnC,mBAA0B;AAC1B,mBAAsB;AAEf,SAAS,YAAY;AAC1B,QAAM,eAAW,+BAAY;AAC7B,QAAM,aAAS,mCAAgB;AAE/B,8BAAU,MAAM;AACd,UAAM,aAAa;AAAA,MACjB;AAAA,MACA,UAAU,SAAS;AAAA,MACnB,OAAO,OAAO,IAAI,OAAO;AAAA,MACzB,QAAQ,OAAO,IAAI,QAAQ;AAAA,MAC3B,YAAY,OAAO,IAAI,YAAY;AAAA,MACnC,YAAY,OAAO,IAAI,YAAY;AAAA,MACnC,cAAc,OAAO,IAAI,cAAc;AAAA,MACvC,UAAU,OAAO,IAAI,UAAU;AAAA,MAC/B,aAAa,OAAO,IAAI,aAAa;AAAA,IACvC;AAEA,4BAAM,aAAa,YAAY,EAAE,0BAA0B,MAAM,CAAC;AAAA,EACpE,GAAG,CAAC,UAAU,MAAM,CAAC;AAErB,4CAAmB,CAAC,WAAW;AAC7B,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,MAA2B,UAAU;AAAA,EACpD,CAAC;AAED,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport Script from 'next/script';\nimport { track } from '../track/index';\nimport { mapAndSendFbqEvent } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { Fbq, PixelId } from '../track/fbq';\n\ndeclare global {\n interface Window extends Gtag, Fbq {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (!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 mapAndSendFbqEvent(window.fbq, name, properties, { eventID: event_id });\n}\n\nexport function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }: Props) {\n const pathname = usePathname();\n const params = useSearchParams();\n\n useEffect(() => {\n const properties = {\n pathname,\n referrer: document.referrer,\n gclid: params.get('gclid'),\n fbclid: params.get('fbclid'),\n utm_source: params.get('utm_source'),\n utm_medium: params.get('utm_medium'),\n utm_campaign: params.get('utm_campaign'),\n utm_term: params.get('utm_term'),\n utm_content: params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, 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 <noscript>\n <img\n width=\"1\"\n height=\"1\"\n style={{ display: 'none' }}\n src={`https://www.facebook.com/tr?id=${pixelId}&ev=PageView&noscript=1`}\n />\n </noscript>\n </>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA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,MAAM,UAAU;AAAA,EAC/B,CAAC;AAED,SACE,4EACG;AAAA,qBAAiB,4CAAC,UAAK,UAAS,aAAY,SAAS,eAAe;AAAA,IACpE,QACC,4EACE;AAAA;AAAA,QAAC,cAAAA;AAAA,QAAA;AAAA,UACC,IAAG;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,4EACE;AAAA;AAAA,QAAC,cAAAA;AAAA,QAAA;AAAA,UACC,IAAG;AAAA,UACH,UAAS;AAAA,UACT,yBAAyB;AAAA,YACvB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAiBO,OAAO;AAAA;AAAA,UAExB;AAAA;AAAA,MACF;AAAA,MACA,4CAAC,cACC;AAAA,QAAC;AAAA;AAAA,UACC,OAAM;AAAA,UACN,QAAO;AAAA,UACP,OAAO,EAAE,SAAS,OAAO;AAAA,UACzB,KAAK,kCAAkC,OAAO;AAAA;AAAA,MAChD,GACF;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":["Script"]}
@@ -1,3 +1,22 @@
1
- declare function Analytics(): null;
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { EventName, TrackName, TrackProperties } from '../track/types.cjs';
3
+ import { Gtag, GaId, GtmId } from '../track/gtag.cjs';
4
+ import { Fbq, PixelId } from '../track/fbq.cjs';
2
5
 
3
- export { Analytics };
6
+ declare global {
7
+ interface Window extends Gtag, Fbq {
8
+ }
9
+ }
10
+ interface Props {
11
+ gaId?: GaId;
12
+ gtmId?: GtmId;
13
+ pixelId?: PixelId;
14
+ facebookAppId?: string;
15
+ nonce?: string;
16
+ debugMode?: boolean;
17
+ }
18
+ declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
19
+ declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): void;
20
+ declare function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }: Props): react_jsx_runtime.JSX.Element;
21
+
22
+ export { Analytics, sendFBEvent, sendGAEvent };
@@ -1,3 +1,22 @@
1
- declare function Analytics(): null;
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { EventName, TrackName, TrackProperties } from '../track/types.js';
3
+ import { Gtag, GaId, GtmId } from '../track/gtag.js';
4
+ import { Fbq, PixelId } from '../track/fbq.js';
2
5
 
3
- export { Analytics };
6
+ declare global {
7
+ interface Window extends Gtag, Fbq {
8
+ }
9
+ }
10
+ interface Props {
11
+ gaId?: GaId;
12
+ gtmId?: GtmId;
13
+ pixelId?: PixelId;
14
+ facebookAppId?: string;
15
+ nonce?: string;
16
+ debugMode?: boolean;
17
+ }
18
+ declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
19
+ declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): void;
20
+ declare function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }: Props): react_jsx_runtime.JSX.Element;
21
+
22
+ export { Analytics, sendFBEvent, sendGAEvent };
@@ -1,11 +1,28 @@
1
1
  "use client";
2
2
 
3
3
  // src/next/index.tsx
4
+ import { useEffect } from "react";
4
5
  import { usePathname, useSearchParams } from "next/navigation";
5
6
  import { useReportWebVitals } from "next/web-vitals";
6
- import { useEffect } from "react";
7
+ import Script from "next/script";
7
8
  import { track } from "../track/index.mjs";
8
- function Analytics() {
9
+ import { mapAndSendFbqEvent } from "../track/fbq.mjs";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
+ function sendGAEvent(name, properties) {
12
+ if (!window.gtag) {
13
+ console.warn("GA has not been initialized");
14
+ return;
15
+ }
16
+ window.gtag("event", name, properties);
17
+ }
18
+ function sendFBEvent(name, properties, event_id) {
19
+ if (typeof window === "undefined" || !window.fbq) {
20
+ console.warn("fbq has not been initialized");
21
+ return;
22
+ }
23
+ mapAndSendFbqEvent(window.fbq, name, properties, { eventID: event_id });
24
+ }
25
+ function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }) {
9
26
  const pathname = usePathname();
10
27
  const params = useSearchParams();
11
28
  useEffect(() => {
@@ -34,9 +51,77 @@ function Analytics() {
34
51
  };
35
52
  track(metric.name, properties);
36
53
  });
37
- return null;
54
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
55
+ facebookAppId && /* @__PURE__ */ jsx("meta", { property: "fb:app_id", content: facebookAppId }),
56
+ gaId && /* @__PURE__ */ jsxs(Fragment, { children: [
57
+ /* @__PURE__ */ jsx(
58
+ Script,
59
+ {
60
+ id: "gtag",
61
+ nonce,
62
+ src: `https://www.googletagmanager.com/gtag/js?id=${gaId}`
63
+ }
64
+ ),
65
+ /* @__PURE__ */ jsx(
66
+ Script,
67
+ {
68
+ nonce,
69
+ id: "gtag-init",
70
+ dangerouslySetInnerHTML: {
71
+ __html: `
72
+ window.dataLayer = window.dataLayer || [];
73
+ function gtag(){dataLayer.push(arguments);}
74
+ gtag('js', new Date());
75
+ gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
76
+ `
77
+ }
78
+ }
79
+ )
80
+ ] }),
81
+ pixelId && /* @__PURE__ */ jsxs(Fragment, { children: [
82
+ /* @__PURE__ */ jsx(
83
+ Script,
84
+ {
85
+ id: "pixel",
86
+ strategy: "afterInteractive",
87
+ dangerouslySetInnerHTML: {
88
+ __html: `
89
+ !(function (f, b, e, v, n, t, s) {
90
+ if (f.fbq) return;
91
+ n = f.fbq = function () {
92
+ n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
93
+ };
94
+ if (!f._fbq) f._fbq = n;
95
+ n.push = n;
96
+ n.loaded = !0;
97
+ n.version = '2.0';
98
+ n.queue = [];
99
+ t = b.createElement(e);
100
+ t.async = !0;
101
+ t.src = v;
102
+ s = b.getElementsByTagName(e)[0];
103
+ s.parentNode.insertBefore(t, s);
104
+ })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
105
+ fbq('init', '${pixelId}');
106
+ fbq('track', 'PageView');`
107
+ }
108
+ }
109
+ ),
110
+ /* @__PURE__ */ jsx("noscript", { children: /* @__PURE__ */ jsx(
111
+ "img",
112
+ {
113
+ width: "1",
114
+ height: "1",
115
+ style: { display: "none" },
116
+ src: `https://www.facebook.com/tr?id=${pixelId}&ev=PageView&noscript=1`
117
+ }
118
+ ) })
119
+ ] })
120
+ ] });
38
121
  }
39
122
  export {
40
- Analytics
123
+ Analytics,
124
+ sendFBEvent,
125
+ sendGAEvent
41
126
  };
42
127
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport { useEffect } from 'react';\nimport { track } from '../track/index';\n\nexport function Analytics() {\n const pathname = usePathname();\n const params = useSearchParams();\n\n useEffect(() => {\n const properties = {\n pathname,\n referrer: document.referrer,\n gclid: params.get('gclid'),\n fbclid: params.get('fbclid'),\n utm_source: params.get('utm_source'),\n utm_medium: params.get('utm_medium'),\n utm_campaign: params.get('utm_campaign'),\n utm_term: params.get('utm_term'),\n utm_content: params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name as Lowercase<string>, properties);\n });\n\n return null;\n}\n"],"mappings":";;;AAEA,SAAS,aAAa,uBAAuB;AAC7C,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAEf,SAAS,YAAY;AAC1B,QAAM,WAAW,YAAY;AAC7B,QAAM,SAAS,gBAAgB;AAE/B,YAAU,MAAM;AACd,UAAM,aAAa;AAAA,MACjB;AAAA,MACA,UAAU,SAAS;AAAA,MACnB,OAAO,OAAO,IAAI,OAAO;AAAA,MACzB,QAAQ,OAAO,IAAI,QAAQ;AAAA,MAC3B,YAAY,OAAO,IAAI,YAAY;AAAA,MACnC,YAAY,OAAO,IAAI,YAAY;AAAA,MACnC,cAAc,OAAO,IAAI,cAAc;AAAA,MACvC,UAAU,OAAO,IAAI,UAAU;AAAA,MAC/B,aAAa,OAAO,IAAI,aAAa;AAAA,IACvC;AAEA,UAAM,aAAa,YAAY,EAAE,0BAA0B,MAAM,CAAC;AAAA,EACpE,GAAG,CAAC,UAAU,MAAM,CAAC;AAErB,qBAAmB,CAAC,WAAW;AAC7B,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,MAA2B,UAAU;AAAA,EACpD,CAAC;AAED,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/next/index.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { usePathname, useSearchParams } from 'next/navigation';\nimport { useReportWebVitals } from 'next/web-vitals';\nimport Script from 'next/script';\nimport { track } from '../track/index';\nimport { mapAndSendFbqEvent } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { Fbq, PixelId } from '../track/fbq';\n\ndeclare global {\n interface Window extends Gtag, Fbq {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (!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 mapAndSendFbqEvent(window.fbq, name, properties, { eventID: event_id });\n}\n\nexport function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }: Props) {\n const pathname = usePathname();\n const params = useSearchParams();\n\n useEffect(() => {\n const properties = {\n pathname,\n referrer: document.referrer,\n gclid: params.get('gclid'),\n fbclid: params.get('fbclid'),\n utm_source: params.get('utm_source'),\n utm_medium: params.get('utm_medium'),\n utm_campaign: params.get('utm_campaign'),\n utm_term: params.get('utm_term'),\n utm_content: params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, 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 <noscript>\n <img\n width=\"1\"\n height=\"1\"\n style={{ display: 'none' }}\n src={`https://www.facebook.com/tr?id=${pixelId}&ev=PageView&noscript=1`}\n />\n </noscript>\n </>\n )}\n </>\n );\n}\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B,SAAS,aAAa,uBAAuB;AAC7C,SAAS,0BAA0B;AACnC,OAAO,YAAY;AACnB,SAAS,aAAa;AACtB,SAAS,0BAA0B;AA2EX,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,qBAAmB,OAAO,KAAK,MAAM,YAAY,EAAE,SAAS,SAAS,CAAC;AACxE;AAEO,SAAS,UAAU,EAAE,MAAM,OAAO,WAAW,SAAS,cAAc,GAAU;AACnF,QAAM,WAAW,YAAY;AAC7B,QAAM,SAAS,gBAAgB;AAE/B,YAAU,MAAM;AACd,UAAM,a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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAiBO,OAAO;AAAA;AAAA,UAExB;AAAA;AAAA,MACF;AAAA,MACA,oBAAC,cACC;AAAA,QAAC;AAAA;AAAA,UACC,OAAM;AAAA,UACN,QAAO;AAAA,UACP,OAAO,EAAE,SAAS,OAAO;AAAA,UACzB,KAAK,kCAAkC,OAAO;AAAA;AAAA,MAChD,GACF;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":[]}
@@ -20,13 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/react-router/index.tsx
21
21
  var react_router_exports = {};
22
22
  __export(react_router_exports, {
23
- Analytics: () => Analytics
23
+ Analytics: () => Analytics,
24
+ sendFBEvent: () => sendFBEvent,
25
+ sendGAEvent: () => sendGAEvent
24
26
  });
25
27
  module.exports = __toCommonJS(react_router_exports);
26
28
  var import_react = require("react");
27
29
  var import_react_router = require("react-router");
28
30
  var import_web_vitals = require("web-vitals");
29
31
  var import_track = require("../track/index.cjs");
32
+ var import_fbq = require("../track/fbq.cjs");
33
+ var import_jsx_runtime = require("react/jsx-runtime");
30
34
  function useReportWebVitals(reportWebVitalsFn) {
31
35
  (0, import_react.useEffect)(() => {
32
36
  (0, import_web_vitals.onCLS)(reportWebVitalsFn);
@@ -37,7 +41,21 @@ function useReportWebVitals(reportWebVitalsFn) {
37
41
  (0, import_web_vitals.onTTFB)(reportWebVitalsFn);
38
42
  }, [reportWebVitalsFn]);
39
43
  }
40
- function Analytics() {
44
+ function sendGAEvent(name, properties) {
45
+ if (typeof window === "undefined" || !window.gtag) {
46
+ console.warn("gtag has not been initialized");
47
+ return;
48
+ }
49
+ window.gtag("event", name, properties);
50
+ }
51
+ function sendFBEvent(name, properties, event_id) {
52
+ if (typeof window === "undefined" || !window.fbq) {
53
+ console.warn("fbq has not been initialized");
54
+ return;
55
+ }
56
+ (0, import_fbq.mapAndSendFbqEvent)(window.fbq, name, properties, { eventID: event_id });
57
+ }
58
+ function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }) {
41
59
  const { pathname } = (0, import_react_router.useLocation)();
42
60
  const [params] = (0, import_react_router.useSearchParams)();
43
61
  (0, import_react.useEffect)(() => {
@@ -66,10 +84,79 @@ function Analytics() {
66
84
  };
67
85
  (0, import_track.track)(metric.name, properties);
68
86
  });
69
- return null;
87
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
88
+ facebookAppId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("meta", { property: "fb:app_id", content: facebookAppId }),
89
+ gaId && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
90
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
91
+ "script",
92
+ {
93
+ async: true,
94
+ id: "gtag",
95
+ nonce,
96
+ src: `https://www.googletagmanager.com/gtag/js?id=${gaId}`
97
+ }
98
+ ),
99
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
100
+ "script",
101
+ {
102
+ async: true,
103
+ nonce,
104
+ id: "gtag-init",
105
+ dangerouslySetInnerHTML: {
106
+ __html: `
107
+ window.dataLayer = window.dataLayer || [];
108
+ function gtag(){dataLayer.push(arguments);}
109
+ gtag('js', new Date());
110
+ gtag('config', '${gaId}'${debugMode ? " ,{ 'debug_mode': true }" : ""});
111
+ `
112
+ }
113
+ }
114
+ )
115
+ ] }),
116
+ pixelId && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
117
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
118
+ "script",
119
+ {
120
+ id: "pixel",
121
+ dangerouslySetInnerHTML: {
122
+ __html: `
123
+ !(function (f, b, e, v, n, t, s) {
124
+ if (f.fbq) return;
125
+ n = f.fbq = function () {
126
+ n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
127
+ };
128
+ if (!f._fbq) f._fbq = n;
129
+ n.push = n;
130
+ n.loaded = !0;
131
+ n.version = '2.0';
132
+ n.queue = [];
133
+ t = b.createElement(e);
134
+ t.async = !0;
135
+ t.src = v;
136
+ s = b.getElementsByTagName(e)[0];
137
+ s.parentNode.insertBefore(t, s);
138
+ })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');
139
+ fbq('init', '${pixelId}');
140
+ fbq('track', 'PageView');`
141
+ }
142
+ }
143
+ ),
144
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("noscript", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
145
+ "img",
146
+ {
147
+ width: "1",
148
+ height: "1",
149
+ style: { display: "none" },
150
+ src: `https://www.facebook.com/tr?id=${pixelId}&ev=PageView&noscript=1`
151
+ }
152
+ ) })
153
+ ] })
154
+ ] });
70
155
  }
71
156
  // Annotate the CommonJS export names for ESM import in node:
72
157
  0 && (module.exports = {
73
- Analytics
158
+ Analytics,
159
+ sendFBEvent,
160
+ sendGAEvent
74
161
  });
75
162
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation, useSearchParams } from 'react-router';\nimport { onLCP, onFID, onCLS, onINP, onFCP, onTTFB, type Metric } from 'web-vitals';\nimport { track } from '../track/index';\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onFID(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\nexport function Analytics() {\n const { pathname } = useLocation();\n const [params] = useSearchParams();\n\n useEffect(() => {\n const properties = {\n pathname,\n referrer: document.referrer,\n gclid: params.get('gclid'),\n fbclid: params.get('fbclid'),\n utm_source: params.get('utm_source'),\n utm_medium: params.get('utm_medium'),\n utm_campaign: params.get('utm_campaign'),\n utm_term: params.get('utm_term'),\n utm_content: params.get('utm_content'),\n };\n\n track('page_view', properties, { enableThirdPartyTracking: false });\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name as Lowercase<string>, properties);\n });\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,0BAA6C;AAC7C,wBAAuE;AACvE,mBAAsB;AAEtB,SAAS,mBAAmB,mBAA6C;AACvE,8BAAU,MAAM;AACd,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,kCAAO,iBAAiB;AAAA,EAC1B,GAAG,CAAC,iBAAiB,CAAC;AACxB;AAEO,SAAS,YAAY;AAC1B,QAAM,EAAE,SAAS,QAAI,iCAAY;AACjC,QAAM,CAAC,MAAM,QAAI,qCAAgB;AAEjC,8BAAU,MAAM;AACd,UAAM,aAAa;AAAA,MACjB;AAAA,MACA,UAAU,SAAS;AAAA,MACnB,OAAO,OAAO,IAAI,OAAO;AAAA,MACzB,QAAQ,OAAO,IAAI,QAAQ;AAAA,MAC3B,YAAY,OAAO,IAAI,YAAY;AAAA,MACnC,YAAY,OAAO,IAAI,YAAY;AAAA,MACnC,cAAc,OAAO,IAAI,cAAc;AAAA,MACvC,UAAU,OAAO,IAAI,UAAU;AAAA,MAC/B,aAAa,OAAO,IAAI,aAAa;AAAA,IACvC;AAEA,4BAAM,aAAa,YAAY,EAAE,0BAA0B,MAAM,CAAC;AAAA,EACpE,GAAG,CAAC,UAAU,MAAM,CAAC;AAErB,qBAAmB,CAAC,WAAW;AAC7B,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,MAA2B,UAAU;AAAA,EACpD,CAAC;AAED,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/react-router/index.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { useLocation, useSearchParams } from 'react-router';\nimport { onLCP, onFID, onCLS, onINP, onFCP, onTTFB, type Metric } from 'web-vitals';\nimport { track } from '../track/index';\nimport { mapAndSendFbqEvent } from '../track/fbq';\nimport type { Gtag, GaId, GtmId } from '../track/gtag';\nimport type { Fbq, PixelId } from '../track/fbq';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\n\nfunction useReportWebVitals(reportWebVitalsFn: (metric: Metric) => void) {\n useEffect(() => {\n onCLS(reportWebVitalsFn);\n onFID(reportWebVitalsFn);\n onLCP(reportWebVitalsFn);\n onINP(reportWebVitalsFn);\n onFCP(reportWebVitalsFn);\n onTTFB(reportWebVitalsFn);\n }, [reportWebVitalsFn]);\n}\n\ndeclare global {\n interface Window extends Gtag, Fbq {}\n}\n\ninterface Props {\n gaId?: GaId;\n gtmId?: GtmId;\n pixelId?: PixelId;\n facebookAppId?: string;\n nonce?: string;\n debugMode?: boolean;\n}\n\nexport function sendGAEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>\n) {\n if (typeof window === 'undefined' || !window.gtag) {\n console.warn('gtag has not been initialized');\n return;\n }\n window.gtag('event', name, properties);\n}\n\nexport function sendFBEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n event_id?: string\n) {\n if (typeof window === 'undefined' || !window.fbq) {\n console.warn('fbq has not been initialized');\n return;\n }\n mapAndSendFbqEvent(window.fbq, name, properties, { eventID: event_id });\n}\n\nexport function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }: Props) {\n const { pathname } = useLocation();\n const [params] = useSearchParams();\n\n useEffect(() => {\n const properties = {\n pathname,\n referrer: document.referrer,\n gclid: params.get('gclid'),\n fbclid: params.get('fbclid'),\n utm_source: params.get('utm_source'),\n utm_medium: params.get('utm_medium'),\n utm_campaign: params.get('utm_campaign'),\n utm_term: params.get('utm_term'),\n utm_content: params.get('utm_content'),\n };\n\n /**\n * Pixel:\n * Each time the Pixel loads, it automatically calls fbq('track', 'PageView') to track a\n * PageView standard event.\n */\n track('page_view', properties, { enableThirdPartyTracking: false });\n }, [pathname, params]);\n\n useReportWebVitals((metric) => {\n const properties = {\n id: metric.id,\n rating: metric.rating,\n value: metric.value,\n delta: metric.delta,\n navigation_type: metric.navigationType,\n non_interaction: true, // avoids affecting bounce rate.\n };\n track(metric.name, properties);\n });\n\n return (\n <>\n {facebookAppId && <meta property=\"fb:app_id\" content={facebookAppId} />}\n {gaId && (\n <>\n <script\n async\n id=\"gtag\"\n nonce={nonce}\n src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}\n />\n <script\n async\n nonce={nonce}\n id=\"gtag-init\"\n dangerouslySetInnerHTML={{\n __html: `\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '${gaId}'${debugMode ? \" ,{ 'debug_mode': true }\" : ''});\n `,\n }}\n />\n </>\n )}\n {pixelId && (\n <>\n <script\n id=\"pixel\"\n dangerouslySetInnerHTML={{\n __html: `\n !(function (f, b, e, v, n, t, s) {\n if (f.fbq) return;\n n = f.fbq = function () {\n n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);\n };\n if (!f._fbq) f._fbq = n;\n n.push = n;\n n.loaded = !0;\n n.version = '2.0';\n n.queue = [];\n t = b.createElement(e);\n t.async = !0;\n t.src = v;\n s = b.getElementsByTagName(e)[0];\n s.parentNode.insertBefore(t, s);\n })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js');\n fbq('init', '${pixelId}');\n fbq('track', 'PageView');`,\n }}\n />\n <noscript>\n <img\n width=\"1\"\n height=\"1\"\n style={{ display: 'none' }}\n src={`https://www.facebook.com/tr?id=${pixelId}&ev=PageView&noscript=1`}\n />\n </noscript>\n </>\n )}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,0BAA6C;AAC7C,wBAAuE;AACvE,mBAAsB;AACtB,iBAAmC;AA2FX;AAtFxB,SAAS,mBAAmB,mBAA6C;AACvE,8BAAU,MAAM;AACd,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,iCAAM,iBAAiB;AACvB,kCAAO,iBAAiB;AAAA,EAC1B,GAAG,CAAC,iBAAiB,CAAC;AACxB;AAeO,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,qCAAmB,OAAO,KAAK,MAAM,YAAY,EAAE,SAAS,SAAS,CAAC;AACxE;AAEO,SAAS,UAAU,EAAE,MAAM,OAAO,WAAW,SAAS,cAAc,GAAU;AACnF,QAAM,EAAE,SAAS,QAAI,iCAAY;AACjC,QAAM,CAAC,MAAM,QAAI,qCAAgB;AAEjC,8BAAU,MAAM;AACd,UAAM,aAAa;AAAA,MACjB;AAAA,MACA,UAAU,SAAS;AAAA,MACnB,OAAO,OAAO,IAAI,OAAO;AAAA,MACzB,QAAQ,OAAO,IAAI,QAAQ;AAAA,MAC3B,YAAY,OAAO,IAAI,YAAY;AAAA,MACnC,YAAY,OAAO,IAAI,YAAY;AA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ACP,OAAO,EAAE,SAAS,OAAO;AAAA,UACzB,KAAK,kCAAkC,OAAO;AAAA;AAAA,MAChD,GACF;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":[]}
@@ -1,3 +1,22 @@
1
- declare function Analytics(): null;
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Gtag, GaId, GtmId } from '../track/gtag.cjs';
3
+ import { Fbq, PixelId } from '../track/fbq.cjs';
4
+ import { EventName, TrackName, TrackProperties } from '../track/types.cjs';
2
5
 
3
- export { Analytics };
6
+ declare global {
7
+ interface Window extends Gtag, Fbq {
8
+ }
9
+ }
10
+ interface Props {
11
+ gaId?: GaId;
12
+ gtmId?: GtmId;
13
+ pixelId?: PixelId;
14
+ facebookAppId?: string;
15
+ nonce?: string;
16
+ debugMode?: boolean;
17
+ }
18
+ declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
19
+ declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): void;
20
+ declare function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }: Props): react_jsx_runtime.JSX.Element;
21
+
22
+ export { Analytics, sendFBEvent, sendGAEvent };
@@ -1,3 +1,22 @@
1
- declare function Analytics(): null;
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Gtag, GaId, GtmId } from '../track/gtag.js';
3
+ import { Fbq, PixelId } from '../track/fbq.js';
4
+ import { EventName, TrackName, TrackProperties } from '../track/types.js';
2
5
 
3
- export { Analytics };
6
+ declare global {
7
+ interface Window extends Gtag, Fbq {
8
+ }
9
+ }
10
+ interface Props {
11
+ gaId?: GaId;
12
+ gtmId?: GtmId;
13
+ pixelId?: PixelId;
14
+ facebookAppId?: string;
15
+ nonce?: string;
16
+ debugMode?: boolean;
17
+ }
18
+ declare function sendGAEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>): void;
19
+ declare function sendFBEvent<T extends EventName>(name: TrackName<T>, properties?: TrackProperties<T>, event_id?: string): void;
20
+ declare function Analytics({ gaId, nonce, debugMode, pixelId, facebookAppId }: Props): react_jsx_runtime.JSX.Element;
21
+
22
+ export { Analytics, sendFBEvent, sendGAEvent };