@lidofinance/analytics-matomo 0.6.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/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # @lidofinance/matomo
2
+
3
+ Matomo analytics. You can read about Matomo [there](https://matomo.org/).
4
+
5
+ ## Installation
6
+
7
+ `yarn add @lidofinance/analytics-matomo`
8
+
9
+ ## Usage
10
+
11
+ ### Init Matomo
12
+
13
+ #### Variant 1
14
+
15
+ 1. Make sure that `window` contains `__env__`;
16
+ 2. Make sure that `window.__env__` contains `matomoHost` something like `window.__env__.matomoHost='https://matomo.somedomain.com/'`;
17
+ 3. Just import any from `@lidofinance/analytics-matomo`, for example:
18
+
19
+ ---
20
+
21
+ ```ts
22
+ import { trackEvent } from '@lidofinance/analytics-matomo'
23
+ ```
24
+
25
+ If you can't provide `matomoHost` to `window.__env__` see `Variant 2`.
26
+
27
+ #### Variant 2
28
+
29
+ 1. Import `initMatomo` from `@lidofinance/analytics-matomo`;
30
+ 2. Run `initMatomo` with parameter `matomoHost: string` like below:
31
+
32
+ ---
33
+
34
+ ```ts
35
+ import { initMatomo } from '@lidofinance/analytics-matomo'
36
+
37
+ initMatomo('https://matomo.somedomain.com/')
38
+
39
+ // some code
40
+ ```
41
+
42
+ ### Track event
43
+
44
+ ```ts
45
+ import { callMatomo, trackEvent, wrapWithEventTrack } from '@lidofinance/analytics-matomo'
46
+
47
+ const matomoSomeEvent: MatomoEventType = [
48
+ 'Some_Stacking_Widget',
49
+ 'Push "Some" button',
50
+ 'some_widget_some_button_clicked',
51
+ ]
52
+
53
+ // Variant 1
54
+ callMatomo('trackEvent', ...matomoSomeEvent)
55
+
56
+ // Variant 2
57
+ trackEvent(...matomoSomeEvent)
58
+
59
+ // Variant 3: through the decorator
60
+ const someHandler = wrapWithEventTrack(matomoSomeEvent, (arg1, arg2) => {
61
+ // some function
62
+ })
63
+
64
+ someHandler('some_value1', 'some_value2')
65
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,112 @@
1
+ function $parcel$exportWildcard(dest, source) {
2
+ Object.keys(source).forEach(function(key) {
3
+ if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
4
+ return;
5
+ }
6
+
7
+ Object.defineProperty(dest, key, {
8
+ enumerable: true,
9
+ get: function get() {
10
+ return source[key];
11
+ }
12
+ });
13
+ });
14
+
15
+ return dest;
16
+ }
17
+ function $parcel$export(e, n, v, s) {
18
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
19
+ }
20
+ var $6b3e3d225028b1eb$exports = {};
21
+
22
+
23
+ var $b6335fbce4f6ccb6$exports = {};
24
+
25
+ $parcel$export($b6335fbce4f6ccb6$exports, "wrapWithEventTrack", function () { return $b6335fbce4f6ccb6$export$e8f57ad64147d191; });
26
+ var $ef5c629b17efc154$exports = {};
27
+
28
+ $parcel$export($ef5c629b17efc154$exports, "matomoAvailable", function () { return $ef5c629b17efc154$export$e5ed1c22a80aba4b; });
29
+ $parcel$export($ef5c629b17efc154$exports, "callMatomo", function () { return $ef5c629b17efc154$export$cecaccc605742066; });
30
+ $parcel$export($ef5c629b17efc154$exports, "trackEvent", function () { return $ef5c629b17efc154$export$73d0a139caca1fee; });
31
+ $parcel$export($ef5c629b17efc154$exports, "getDomain", function () { return $ef5c629b17efc154$export$3e8733322718eb9; });
32
+ const $ef5c629b17efc154$export$e5ed1c22a80aba4b = typeof window !== "undefined" && window._paq !== undefined;
33
+ const $ef5c629b17efc154$export$cecaccc605742066 = (apiMethod, ...args)=>{
34
+ var ref;
35
+ if (typeof window === "undefined") return;
36
+ window === null || window === void 0 ? void 0 : (ref = window._paq) === null || ref === void 0 ? void 0 : ref.push([
37
+ apiMethod,
38
+ ...args
39
+ ]);
40
+ };
41
+ const $ef5c629b17efc154$export$73d0a139caca1fee = (...event)=>{
42
+ $ef5c629b17efc154$export$cecaccc605742066("trackEvent", ...event);
43
+ };
44
+ const $ef5c629b17efc154$export$3e8733322718eb9 = ()=>{
45
+ return location.hostname.split(".").slice(-2).join(".");
46
+ };
47
+
48
+
49
+ const $b6335fbce4f6ccb6$export$e8f57ad64147d191 = (event, fn)=>{
50
+ return event ? (...args)=>{
51
+ (0, $ef5c629b17efc154$export$cecaccc605742066)("trackEvent", ...event);
52
+ return fn === null || fn === void 0 ? void 0 : fn(...args);
53
+ } : fn;
54
+ };
55
+
56
+
57
+
58
+ var $8ec118068c18cb0c$exports = {};
59
+
60
+ $parcel$export($8ec118068c18cb0c$exports, "initMatomo", function () { return $8ec118068c18cb0c$export$6ec25100f86fa29d; });
61
+
62
+ var $8ec118068c18cb0c$var$_window;
63
+ const $8ec118068c18cb0c$var$injectMatomaScript = (matomoHost)=>{
64
+ document.documentElement.appendChild(Object.assign(document.createElement("script"), {
65
+ async: true,
66
+ src: new URL("/matomo.js", matomoHost).href
67
+ }));
68
+ };
69
+ const $8ec118068c18cb0c$export$6ec25100f86fa29d = (matomoHost)=>{
70
+ var ref, ref1;
71
+ if (typeof window === "undefined") // SSR not supported!
72
+ return;
73
+ const _matomoHost = matomoHost || (window === null || window === void 0 ? void 0 : (ref = window.__env__) === null || ref === void 0 ? void 0 : ref.matomoHost) || undefined;
74
+ if (!_matomoHost) // Where Do I send analytics?
75
+ return;
76
+ if ("_paq" in window) // window._paq has been initialized
77
+ return;
78
+ var __paq;
79
+ (__paq = ($8ec118068c18cb0c$var$_window = window)._paq) !== null && __paq !== void 0 ? __paq : $8ec118068c18cb0c$var$_window._paq = [];
80
+ window === null || window === void 0 ? void 0 : (ref1 = window._paq) === null || ref1 === void 0 ? void 0 : ref1.push([
81
+ "requireCookieConsent"
82
+ ], [
83
+ "trackPageView"
84
+ ], [
85
+ "enableLinkTracking"
86
+ ], [
87
+ "setTrackerUrl",
88
+ new URL("/matomo.php", _matomoHost).href
89
+ ], [
90
+ "setSiteId",
91
+ "1"
92
+ ], [
93
+ "setDomains",
94
+ [
95
+ `*.${(0, $ef5c629b17efc154$export$3e8733322718eb9)()}`
96
+ ]
97
+ ], [
98
+ "enableCrossDomainLinking"
99
+ ]);
100
+ $8ec118068c18cb0c$var$injectMatomaScript(_matomoHost);
101
+ };
102
+ // Run after import
103
+ $8ec118068c18cb0c$export$6ec25100f86fa29d();
104
+
105
+
106
+ $parcel$exportWildcard(module.exports, $6b3e3d225028b1eb$exports);
107
+ $parcel$exportWildcard(module.exports, $b6335fbce4f6ccb6$exports);
108
+ $parcel$exportWildcard(module.exports, $ef5c629b17efc154$exports);
109
+ $parcel$exportWildcard(module.exports, $8ec118068c18cb0c$exports);
110
+
111
+
112
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;AGEO,MAAM,yCAAe,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;AAElF,MAAM,yCAAU,GAAG,CAAC,SAAiB,EAAE,GAAG,IAAI,AAAW,GAAW;QAKzE,GAAY;IAJZ,IAAI,OAAO,MAAM,KAAK,WAAW,EAC/B,OAAM;IAGR,MAAM,aAAN,MAAM,WAAM,GAAZ,KAAA,CAAY,GAAZ,CAAA,GAAY,GAAZ,MAAM,CAAE,IAAI,cAAZ,GAAY,WAAA,GAAZ,KAAA,CAAY,GAAZ,GAAY,CAAE,IAAI,CAAC;QAAC,SAAS;WAAK,IAAI;KAAC,CAAC,CAAA;CACzC;AAEM,MAAM,yCAAU,GAAG,CAAC,GAAG,KAAK,AAAiB,GAAW;IAC7D,yCAAU,CAAC,YAAY,KAAK,KAAK,CAAC;CACnC;AAEM,MAAM,wCAAS,GAAG,IAAM;IAC7B,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;CACxD;;ADlBD;AAGO,MAAM,yCAAkB,GAAG,CAAyB,KAA6B,EAAE,EAAqB;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,IAAI,CAChB;QAAC,sBAAsB;KAAC,EACxB;QAAC,eAAe;KAAC,EACjB;QAAC,oBAAoB;KAAC,EACtB;QAAC,eAAe;QAAE,IAAI,GAAG,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC,IAAI;KAAC,EAC3D;QAAC,WAAW;QAAE,GAAG;KAAC,EAClB;QAAC,YAAY;QAAE;YAAC,CAAC,EAAE,EAAE,CAAA,GAAA,wCAAS,CAAA,EAAE,CAAC,CAAC;SAAC;KAAC,EACpC;QAAC,0BAA0B;KAAC,CAC7B,CAAA;IAED,wCAAkB,CAAC,WAAW,CAAC;CAChC;AAED,mBAAmB;AACnB,yCAAU,EAAE;;","sources":["packages/analytics/matomo/src/index.ts","packages/analytics/matomo/src/type.ts","packages/analytics/matomo/src/decoratorts.ts","packages/analytics/matomo/src/utils.ts","packages/analytics/matomo/src/init.ts"],"sourcesContent":["export * from './type'\nexport * from './decoratorts'\nexport * from './utils'\nexport * from './init'\n","export type MatomoEventType = [category: string, action: string, name: string]\n","import { MatomoEventType } from './type'\nimport { callMatomo } from './utils'\n\nexport const wrapWithEventTrack = <A extends unknown[], R>(event: MatomoEventType | void, fn: (...args: A) => R) =>\n event\n ? (...args: A): R => {\n callMatomo('trackEvent', ...event)\n return fn?.(...args)\n }\n : fn\n","import { MatomoEventType } from './type'\n\nexport const matomoAvailable = typeof window !== 'undefined' && window._paq !== undefined\n\nexport const callMatomo = (apiMethod: string, ...args: unknown[]): void => {\n if (typeof window === 'undefined') {\n return\n }\n\n window?._paq?.push([apiMethod, ...args])\n}\n\nexport const trackEvent = (...event: MatomoEventType): void => {\n callMatomo('trackEvent', ...event)\n}\n\nexport const getDomain = () => {\n return location.hostname.split('.').slice(-2).join('.')\n}\n","import { getDomain } from './utils'\n\ndeclare global {\n interface Window {\n _paq: undefined | [string, ...unknown[]][]\n __env__: { matomoHost: string } & Record<string | number | symbol, unknown>\n }\n}\n\nconst injectMatomaScript = (matomoHost: string) => {\n document.documentElement.appendChild(\n Object.assign(document.createElement('script'), {\n async: true,\n src: new URL('/matomo.js', matomoHost).href,\n }),\n )\n}\n\nexport const initMatomo = (matomoHost?: string): void => {\n if (typeof window === 'undefined') {\n // SSR not supported!\n return\n }\n\n const _matomoHost = matomoHost || window?.__env__?.matomoHost || undefined\n\n if (!_matomoHost) {\n // Where Do I send analytics?\n return\n }\n\n if ('_paq' in window) {\n // window._paq has been initialized\n return\n }\n\n window._paq ??= []\n\n window?._paq?.push(\n ['requireCookieConsent'],\n ['trackPageView'],\n ['enableLinkTracking'],\n ['setTrackerUrl', new URL('/matomo.php', _matomoHost).href],\n ['setSiteId', '1'],\n ['setDomains', [`*.${getDomain()}`]],\n ['enableCrossDomainLinking'],\n )\n\n injectMatomaScript(_matomoHost)\n}\n\n// Run after import\ninitMatomo()\n"],"names":[],"version":3,"file":"index.cjs.map"}
@@ -0,0 +1,17 @@
1
+ export type MatomoEventType = [category: string, action: string, name: string];
2
+ export const matomoAvailable: boolean;
3
+ export const callMatomo: (apiMethod: string, ...args: unknown[]) => void;
4
+ export const trackEvent: (category: string, action: string, name: string) => void;
5
+ export const getDomain: () => string;
6
+ export const wrapWithEventTrack: <A extends unknown[], R>(event: MatomoEventType | void, fn: (...args: A) => R) => (...args: A) => R;
7
+ declare global {
8
+ interface Window {
9
+ _paq: undefined | [string, ...unknown[]][];
10
+ __env__: {
11
+ matomoHost: string;
12
+ } & Record<string | number | symbol, unknown>;
13
+ }
14
+ }
15
+ export const initMatomo: (matomoHost?: string) => void;
16
+
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAAA,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;ACE9E,OAAO,MAAM,wBAA4E,CAAA;AAEzF,OAAO,MAAM,wBAAyB,MAAM,WAAW,OAAO,EAAE,KAAG,IAMlE,CAAA;AAED,OAAO,MAAM,gEAA0C,IAEtD,CAAA;AAED,OAAO,MAAM,uBAEZ,CAAA;ACfD,OAAO,MAAM,oDAAqD,eAAe,GAAG,IAAI,6CAMhF,CAAA;ACPR,QAAQ,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,EAAE,SAAS,GAAG,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAAA;QAC1C,OAAO,EAAE;YAAE,UAAU,EAAE,MAAM,CAAA;SAAE,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAA;KAC5E;CACF;AAWD,OAAO,MAAM,0BAA2B,MAAM,KAAG,IA+BhD,CAAA","sources":["packages/analytics/matomo/src/src/type.ts","packages/analytics/matomo/src/src/utils.ts","packages/analytics/matomo/src/src/decoratorts.ts","packages/analytics/matomo/src/src/init.ts","packages/analytics/matomo/src/src/index.ts","packages/analytics/matomo/src/index.ts"],"sourcesContent":[null,null,null,null,null,"export * from './type'\nexport * from './decoratorts'\nexport * from './utils'\nexport * from './init'\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.mjs ADDED
@@ -0,0 +1,93 @@
1
+ function $parcel$export(e, n, v, s) {
2
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
3
+ }
4
+ var $ca05ace152e51327$exports = {};
5
+
6
+
7
+ var $dfa3db2a6cffa71c$exports = {};
8
+
9
+ $parcel$export($dfa3db2a6cffa71c$exports, "wrapWithEventTrack", function () { return $dfa3db2a6cffa71c$export$e8f57ad64147d191; });
10
+ var $427566b8f1d3367d$exports = {};
11
+
12
+ $parcel$export($427566b8f1d3367d$exports, "matomoAvailable", function () { return $427566b8f1d3367d$export$e5ed1c22a80aba4b; });
13
+ $parcel$export($427566b8f1d3367d$exports, "callMatomo", function () { return $427566b8f1d3367d$export$cecaccc605742066; });
14
+ $parcel$export($427566b8f1d3367d$exports, "trackEvent", function () { return $427566b8f1d3367d$export$73d0a139caca1fee; });
15
+ $parcel$export($427566b8f1d3367d$exports, "getDomain", function () { return $427566b8f1d3367d$export$3e8733322718eb9; });
16
+ const $427566b8f1d3367d$export$e5ed1c22a80aba4b = typeof window !== "undefined" && window._paq !== undefined;
17
+ const $427566b8f1d3367d$export$cecaccc605742066 = (apiMethod, ...args)=>{
18
+ var ref;
19
+ if (typeof window === "undefined") return;
20
+ window === null || window === void 0 ? void 0 : (ref = window._paq) === null || ref === void 0 ? void 0 : ref.push([
21
+ apiMethod,
22
+ ...args
23
+ ]);
24
+ };
25
+ const $427566b8f1d3367d$export$73d0a139caca1fee = (...event)=>{
26
+ $427566b8f1d3367d$export$cecaccc605742066("trackEvent", ...event);
27
+ };
28
+ const $427566b8f1d3367d$export$3e8733322718eb9 = ()=>{
29
+ return location.hostname.split(".").slice(-2).join(".");
30
+ };
31
+
32
+
33
+ const $dfa3db2a6cffa71c$export$e8f57ad64147d191 = (event, fn)=>{
34
+ return event ? (...args)=>{
35
+ (0, $427566b8f1d3367d$export$cecaccc605742066)("trackEvent", ...event);
36
+ return fn === null || fn === void 0 ? void 0 : fn(...args);
37
+ } : fn;
38
+ };
39
+
40
+
41
+
42
+ var $76adf94c93f4a7f4$exports = {};
43
+
44
+ $parcel$export($76adf94c93f4a7f4$exports, "initMatomo", function () { return $76adf94c93f4a7f4$export$6ec25100f86fa29d; });
45
+
46
+ var $76adf94c93f4a7f4$var$_window;
47
+ const $76adf94c93f4a7f4$var$injectMatomaScript = (matomoHost)=>{
48
+ document.documentElement.appendChild(Object.assign(document.createElement("script"), {
49
+ async: true,
50
+ src: new URL("/matomo.js", matomoHost).href
51
+ }));
52
+ };
53
+ const $76adf94c93f4a7f4$export$6ec25100f86fa29d = (matomoHost)=>{
54
+ var ref, ref1;
55
+ if (typeof window === "undefined") // SSR not supported!
56
+ return;
57
+ const _matomoHost = matomoHost || (window === null || window === void 0 ? void 0 : (ref = window.__env__) === null || ref === void 0 ? void 0 : ref.matomoHost) || undefined;
58
+ if (!_matomoHost) // Where Do I send analytics?
59
+ return;
60
+ if ("_paq" in window) // window._paq has been initialized
61
+ return;
62
+ var __paq;
63
+ (__paq = ($76adf94c93f4a7f4$var$_window = window)._paq) !== null && __paq !== void 0 ? __paq : $76adf94c93f4a7f4$var$_window._paq = [];
64
+ window === null || window === void 0 ? void 0 : (ref1 = window._paq) === null || ref1 === void 0 ? void 0 : ref1.push([
65
+ "requireCookieConsent"
66
+ ], [
67
+ "trackPageView"
68
+ ], [
69
+ "enableLinkTracking"
70
+ ], [
71
+ "setTrackerUrl",
72
+ new URL("/matomo.php", _matomoHost).href
73
+ ], [
74
+ "setSiteId",
75
+ "1"
76
+ ], [
77
+ "setDomains",
78
+ [
79
+ `*.${(0, $427566b8f1d3367d$export$3e8733322718eb9)()}`
80
+ ]
81
+ ], [
82
+ "enableCrossDomainLinking"
83
+ ]);
84
+ $76adf94c93f4a7f4$var$injectMatomaScript(_matomoHost);
85
+ };
86
+ // Run after import
87
+ $76adf94c93f4a7f4$export$6ec25100f86fa29d();
88
+
89
+
90
+
91
+
92
+ export {$dfa3db2a6cffa71c$export$e8f57ad64147d191 as wrapWithEventTrack, $427566b8f1d3367d$export$e5ed1c22a80aba4b as matomoAvailable, $427566b8f1d3367d$export$cecaccc605742066 as callMatomo, $427566b8f1d3367d$export$73d0a139caca1fee as trackEvent, $427566b8f1d3367d$export$3e8733322718eb9 as getDomain, $76adf94c93f4a7f4$export$6ec25100f86fa29d as initMatomo};
93
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;AGEO,MAAM,yCAAe,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;AAElF,MAAM,yCAAU,GAAG,CAAC,SAAiB,EAAE,GAAG,IAAI,AAAW,GAAW;QAKzE,GAAY;IAJZ,IAAI,OAAO,MAAM,KAAK,WAAW,EAC/B,OAAM;IAGR,MAAM,aAAN,MAAM,WAAM,GAAZ,KAAA,CAAY,GAAZ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AAS,GAAf,KAAA,CAAe,GAAf,CAAA,GAAe,GAAf,MAAM,CAAE,OAAO,cAAf,GAAe,WAAA,GAAf,KAAA,CAAe,GAAf,GAAe,CAAE,UAAU,AAAZ,CAAA,IAAgB,SAAS;IAE1E,IAAI,CAAC,WAAW,EACd,6BAA6B;IAC7B,OAAM;IAGR,IAAI,MAAM,IAAI,MAAM,EAClB,mCAAmC;IACnC,OAAM;;IAGR,UAAA,6BAAM,GAAN,MAAM,EAAC,IAAI,yCAAX,6BAAM,CAAC,IAAI,GAAK,EAAE;IAElB,MAAM,aAAN,MAAM,WAAM,GAAZ,KAAA,CAAY,GAAZ,CAAA,IAAY,GAAZ,MAAM,CAAE,IAAI,cAAZ,IAAY,WAAA,GAAZ,KAAA,CAAY,GAAZ,IAAY,CAAE,IAAI,CAChB;QAAC,sBAAsB;KAAC,EACxB;QAAC,eAAe;KAAC,EACjB;QAAC,oBAAoB;KAAC,EACtB;QAAC,eAAe;QAAE,IAAI,GAAG,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC,IAAI;KAAC,EAC3D;QAAC,WAAW;QAAE,GAAG;KAAC,EAClB;QAAC,YAAY;QAAE;YAAC,CAAC,EAAE,EAAE,CAAA,GAAA,wCAAS,CAAA,EAAE,CAAC,CAAC;SAAC;KAAC,EACpC;QAAC,0BAA0B;KAAC,CAC7B,CAAA;IAED,wCAAkB,CAAC,WAAW,CAAC;CAChC;AAED,mBAAmB;AACnB,yCAAU,EAAE;;","sources":["packages/analytics/matomo/src/index.ts","packages/analytics/matomo/src/type.ts","packages/analytics/matomo/src/decoratorts.ts","packages/analytics/matomo/src/utils.ts","packages/analytics/matomo/src/init.ts"],"sourcesContent":["export * from './type'\nexport * from './decoratorts'\nexport * from './utils'\nexport * from './init'\n","export type MatomoEventType = [category: string, action: string, name: string]\n","import { MatomoEventType } from './type'\nimport { callMatomo } from './utils'\n\nexport const wrapWithEventTrack = <A extends unknown[], R>(event: MatomoEventType | void, fn: (...args: A) => R) =>\n event\n ? (...args: A): R => {\n callMatomo('trackEvent', ...event)\n return fn?.(...args)\n }\n : fn\n","import { MatomoEventType } from './type'\n\nexport const matomoAvailable = typeof window !== 'undefined' && window._paq !== undefined\n\nexport const callMatomo = (apiMethod: string, ...args: unknown[]): void => {\n if (typeof window === 'undefined') {\n return\n }\n\n window?._paq?.push([apiMethod, ...args])\n}\n\nexport const trackEvent = (...event: MatomoEventType): void => {\n callMatomo('trackEvent', ...event)\n}\n\nexport const getDomain = () => {\n return location.hostname.split('.').slice(-2).join('.')\n}\n","import { getDomain } from './utils'\n\ndeclare global {\n interface Window {\n _paq: undefined | [string, ...unknown[]][]\n __env__: { matomoHost: string } & Record<string | number | symbol, unknown>\n }\n}\n\nconst injectMatomaScript = (matomoHost: string) => {\n document.documentElement.appendChild(\n Object.assign(document.createElement('script'), {\n async: true,\n src: new URL('/matomo.js', matomoHost).href,\n }),\n )\n}\n\nexport const initMatomo = (matomoHost?: string): void => {\n if (typeof window === 'undefined') {\n // SSR not supported!\n return\n }\n\n const _matomoHost = matomoHost || window?.__env__?.matomoHost || undefined\n\n if (!_matomoHost) {\n // Where Do I send analytics?\n return\n }\n\n if ('_paq' in window) {\n // window._paq has been initialized\n return\n }\n\n window._paq ??= []\n\n window?._paq?.push(\n ['requireCookieConsent'],\n ['trackPageView'],\n ['enableLinkTracking'],\n ['setTrackerUrl', new URL('/matomo.php', _matomoHost).href],\n ['setSiteId', '1'],\n ['setDomains', [`*.${getDomain()}`]],\n ['enableCrossDomainLinking'],\n )\n\n injectMatomaScript(_matomoHost)\n}\n\n// Run after import\ninitMatomo()\n"],"names":[],"version":3,"file":"index.mjs.map"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@lidofinance/analytics-matomo",
3
+ "description": "Matomo analytics",
4
+ "repository": "git@github.com:lidofinance/warehouse.git",
5
+ "license": "MIT",
6
+ "version": "0.6.0",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "engines": {
11
+ "node": ">= 16",
12
+ "browsers": "> 0.5%, last 2 versions, not dead"
13
+ },
14
+ "source": "./src/index.ts",
15
+ "main": "dist/index.cjs",
16
+ "module": "dist/index.mjs",
17
+ "types": "dist/index.d.ts",
18
+ "scripts": {
19
+ "build": "parcel build",
20
+ "format": "prettier --check src",
21
+ "format:fix": "yarn format --write",
22
+ "types": "tsc --noEmit",
23
+ "test": "jest"
24
+ },
25
+ "peerDependencies": {},
26
+ "devDependencies": {
27
+ "@lidofinance/config-prettier": "~0.6.0",
28
+ "@types/jest": "^28.0.0",
29
+ "jest": "^28.0.0",
30
+ "ts-jest": "^28.0.0",
31
+ "jest-environment-jsdom": "^28.0.0"
32
+ }
33
+ }