@lidofinance/analytics-matomo 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +7 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +7 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -42,12 +42,10 @@ const $ef5c629b17efc154$export$e5ed1c22a80aba4b = ()=>{
|
|
|
42
42
|
return typeof window !== "undefined" && window._paq !== undefined;
|
|
43
43
|
};
|
|
44
44
|
const $ef5c629b17efc154$var$getCrossDomainCookieClientSide = (key)=>{
|
|
45
|
-
var _document_cookie_match;
|
|
46
45
|
const defaultValue = null;
|
|
47
46
|
if (typeof window === "undefined") return defaultValue;
|
|
48
47
|
const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`);
|
|
49
|
-
|
|
50
|
-
return (_document_cookie_match_ = (_document_cookie_match = document.cookie.match(cookieMatcher)) === null || _document_cookie_match === void 0 ? void 0 : _document_cookie_match[2]) !== null && _document_cookie_match_ !== void 0 ? _document_cookie_match_ : defaultValue;
|
|
48
|
+
return document.cookie.match(cookieMatcher)?.[2] ?? defaultValue;
|
|
51
49
|
};
|
|
52
50
|
const $ef5c629b17efc154$export$83c2c3def90d3b5a = ()=>{
|
|
53
51
|
if (typeof window === "undefined") return false;
|
|
@@ -59,10 +57,9 @@ const $ef5c629b17efc154$export$83c2c3def90d3b5a = ()=>{
|
|
|
59
57
|
return false;
|
|
60
58
|
};
|
|
61
59
|
const $ef5c629b17efc154$export$cecaccc605742066 = (apiMethod, ...args)=>{
|
|
62
|
-
var _window__paq;
|
|
63
60
|
if (!$ef5c629b17efc154$export$e5ed1c22a80aba4b()) (0, $8ec118068c18cb0c$export$6ec25100f86fa29d)();
|
|
64
61
|
if (typeof window === "undefined" || !$ef5c629b17efc154$export$83c2c3def90d3b5a()) return;
|
|
65
|
-
window
|
|
62
|
+
window?._paq?.push([
|
|
66
63
|
apiMethod,
|
|
67
64
|
...args
|
|
68
65
|
]);
|
|
@@ -78,7 +75,6 @@ const $ef5c629b17efc154$export$3e8733322718eb9 = ()=>{
|
|
|
78
75
|
};
|
|
79
76
|
|
|
80
77
|
|
|
81
|
-
var $8ec118068c18cb0c$var$_window;
|
|
82
78
|
// Need if we tried to init matomo manually without cookie,
|
|
83
79
|
// and use it after accepting the cookie policy
|
|
84
80
|
let $8ec118068c18cb0c$var$futureInitMatomoHost = undefined;
|
|
@@ -89,21 +85,19 @@ const $8ec118068c18cb0c$var$injectMatomoScript = (matomoHost)=>{
|
|
|
89
85
|
}));
|
|
90
86
|
};
|
|
91
87
|
const $8ec118068c18cb0c$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
92
|
-
var _window___env__, _window__paq;
|
|
93
88
|
if (typeof window === "undefined") // SSR not supported!
|
|
94
89
|
return;
|
|
95
90
|
if (!(0, $ef5c629b17efc154$export$83c2c3def90d3b5a)()) {
|
|
96
91
|
if (matomoHost) $8ec118068c18cb0c$var$futureInitMatomoHost = matomoHost;
|
|
97
92
|
return;
|
|
98
93
|
}
|
|
99
|
-
const _matomoHost = $8ec118068c18cb0c$var$futureInitMatomoHost || matomoHost ||
|
|
94
|
+
const _matomoHost = $8ec118068c18cb0c$var$futureInitMatomoHost || matomoHost || window?.__env__?.matomoHost || undefined;
|
|
100
95
|
if (!_matomoHost) // Where Do I send analytics?
|
|
101
96
|
return;
|
|
102
97
|
if (window._paq) // window._paq has been initialized
|
|
103
98
|
return;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
window === null || window === void 0 ? void 0 : (_window__paq = window._paq) === null || _window__paq === void 0 ? void 0 : _window__paq.push([
|
|
99
|
+
window._paq ??= [];
|
|
100
|
+
window?._paq?.push([
|
|
107
101
|
"requireCookieConsent"
|
|
108
102
|
], [
|
|
109
103
|
"trackPageView"
|
|
@@ -134,12 +128,10 @@ var $b6335fbce4f6ccb6$exports = {};
|
|
|
134
128
|
|
|
135
129
|
$parcel$export($b6335fbce4f6ccb6$exports, "wrapWithEventTrack", function () { return $b6335fbce4f6ccb6$export$e8f57ad64147d191; });
|
|
136
130
|
|
|
137
|
-
const $b6335fbce4f6ccb6$export$e8f57ad64147d191 = (event, fn)=>{
|
|
138
|
-
return event ? (...args)=>{
|
|
131
|
+
const $b6335fbce4f6ccb6$export$e8f57ad64147d191 = (event, fn)=>event ? (...args)=>{
|
|
139
132
|
(0, $ef5c629b17efc154$export$cecaccc605742066)("trackEvent", ...event);
|
|
140
|
-
return fn
|
|
133
|
+
return fn?.(...args);
|
|
141
134
|
} : fn;
|
|
142
|
-
};
|
|
143
135
|
|
|
144
136
|
|
|
145
137
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;AAGO,MAAM,4CAA2B;AACjC,MAAM,4CAA0B;AAEhC,MAAM,4CAAsB;IACjC;IACA;CACD;AAEM,MAAM,4CAAkB,IAAe;IAC5C,OAAO,OAAO,WAAW,eAAe,OAAO,IAAI,KAAK;AAC1D;AAEA,MAAM,uDAAiC,CAAC,MAA+B;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;AAGO,MAAM,4CAA2B;AACjC,MAAM,4CAA0B;AAEhC,MAAM,4CAAsB;IACjC;IACA;CACD;AAEM,MAAM,4CAAkB,IAAe;IAC5C,OAAO,OAAO,WAAW,eAAe,OAAO,IAAI,KAAK;AAC1D;AAEA,MAAM,uDAAiC,CAAC,MAA+B;IACrE,MAAM,eAAe,IAAI;IAEzB,IAAI,OAAO,WAAW,aACpB,OAAO;IAGT,MAAM,gBAAgB,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,QAAQ,CAAC;IACtD,OAAO,AAAC,SAAS,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,IAAe;AAClE;AAEO,MAAM,4CAA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mC;IACnC;IAGF,OAAO,IAAI,KAAK,EAAE;IAElB,QAAQ,MAAM,KACZ;QAAC;KAAuB,EACxB;QAAC;KAAgB,EACjB;QAAC;KAAqB,EACtB;QAAC;QAAiB,IAAI,IAAI,eAAe,aAAa,IAAI;KAAC,EAC3D;QAAC;QAAa;KAAI,EAClB;QAAC;QAAc;YAAC,CAAC,EAAE,EAAE,CAAA,GAAA,wCAAQ,IAAI,CAAC;SAAC;KAAC,EACpC;QAAC;KAA2B;IAG9B,yCAAmB;AACrB;;AD5DA;;;;;;;AIAA;AAGO,MAAM,4CAAqB,CAAyB,OAA+B,KACxF,QACI,CAAC,GAAG,OAAe;QACjB,CAAA,GAAA,yCAAU,AAAD,EAAE,iBAAiB;QAC5B,OAAO,QAAQ;IACjB,IACA,EAAE;;;;;AJFR,mBAAmB;AACnB,CAAA,GAAA,yCAAS","sources":["packages/analytics/matomo/src/index.ts","packages/analytics/matomo/src/init.ts","packages/analytics/matomo/src/utils.ts","packages/analytics/matomo/src/type.ts","packages/analytics/matomo/src/decoratorts.ts"],"sourcesContent":["import { initMatomo } from './init'\n\nexport * from './type'\nexport * from './decoratorts'\nexport * from './utils'\nexport * from './init'\n\n// Run after import\ninitMatomo()\n","import { getDomain, checkCookieAllowed } 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\n// Need if we tried to init matomo manually without cookie,\n// and use it after accepting the cookie policy\nlet futureInitMatomoHost: string | undefined = undefined\n\nconst injectMatomoScript = (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 if (!checkCookieAllowed()) {\n if (matomoHost) {\n futureInitMatomoHost = matomoHost\n }\n return\n }\n\n const _matomoHost = futureInitMatomoHost || matomoHost || window?.__env__?.matomoHost || undefined\n\n if (!_matomoHost) {\n // Where Do I send analytics?\n return\n }\n\n if (window._paq) {\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 injectMatomoScript(_matomoHost)\n}\n","import { MatomoEventType } from './type'\nimport { initMatomo } from './init'\n\nexport const COOKIE_ALLOWED_VALUE_YES = 'yes'\nexport const COOKIE_ALLOWED_MAIN_KEY = 'cookie-allowed'\n\nexport const COOKIE_ALLOWED_KEYS = [\n 'LIDO_WIDGET__COOKIES_ALLOWED', // will be deprecated soon\n COOKIE_ALLOWED_MAIN_KEY,\n]\n\nexport const matomoAvailable = (): boolean => {\n return typeof window !== 'undefined' && window._paq !== undefined\n}\n\nconst getCrossDomainCookieClientSide = (key: string): string | null => {\n const defaultValue = null\n\n if (typeof window === 'undefined') {\n return defaultValue\n }\n\n const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`)\n return (document.cookie.match(cookieMatcher)?.[2] as string) ?? defaultValue\n}\n\nexport const checkCookieAllowed = (): boolean => {\n if (typeof window === 'undefined') {\n return false\n }\n\n for (const key of COOKIE_ALLOWED_KEYS) {\n const cookieValue = getCrossDomainCookieClientSide(key)\n const cookieAllowed = !!(cookieValue && cookieValue === COOKIE_ALLOWED_VALUE_YES)\n\n if (cookieAllowed) {\n return cookieAllowed\n }\n }\n\n return false\n}\n\nexport const callMatomo = (apiMethod: string, ...args: unknown[]): void => {\n if (!matomoAvailable()) {\n initMatomo()\n }\n\n if (typeof window === 'undefined' || !checkCookieAllowed()) {\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 trackVisibleContentImpressions = (checkOnScroll = true, timeIntervalInMs = 750): void => {\n callMatomo('trackVisibleContentImpressions', checkOnScroll, timeIntervalInMs)\n}\n\nexport const getDomain = () => {\n return location.hostname.split('.').slice(-2).join('.')\n}\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"],"names":[],"version":3,"file":"index.cjs.map"}
|
package/dist/index.mjs
CHANGED
|
@@ -26,12 +26,10 @@ const $427566b8f1d3367d$export$e5ed1c22a80aba4b = ()=>{
|
|
|
26
26
|
return typeof window !== "undefined" && window._paq !== undefined;
|
|
27
27
|
};
|
|
28
28
|
const $427566b8f1d3367d$var$getCrossDomainCookieClientSide = (key)=>{
|
|
29
|
-
var _document_cookie_match;
|
|
30
29
|
const defaultValue = null;
|
|
31
30
|
if (typeof window === "undefined") return defaultValue;
|
|
32
31
|
const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`);
|
|
33
|
-
|
|
34
|
-
return (_document_cookie_match_ = (_document_cookie_match = document.cookie.match(cookieMatcher)) === null || _document_cookie_match === void 0 ? void 0 : _document_cookie_match[2]) !== null && _document_cookie_match_ !== void 0 ? _document_cookie_match_ : defaultValue;
|
|
32
|
+
return document.cookie.match(cookieMatcher)?.[2] ?? defaultValue;
|
|
35
33
|
};
|
|
36
34
|
const $427566b8f1d3367d$export$83c2c3def90d3b5a = ()=>{
|
|
37
35
|
if (typeof window === "undefined") return false;
|
|
@@ -43,10 +41,9 @@ const $427566b8f1d3367d$export$83c2c3def90d3b5a = ()=>{
|
|
|
43
41
|
return false;
|
|
44
42
|
};
|
|
45
43
|
const $427566b8f1d3367d$export$cecaccc605742066 = (apiMethod, ...args)=>{
|
|
46
|
-
var _window__paq;
|
|
47
44
|
if (!$427566b8f1d3367d$export$e5ed1c22a80aba4b()) (0, $76adf94c93f4a7f4$export$6ec25100f86fa29d)();
|
|
48
45
|
if (typeof window === "undefined" || !$427566b8f1d3367d$export$83c2c3def90d3b5a()) return;
|
|
49
|
-
window
|
|
46
|
+
window?._paq?.push([
|
|
50
47
|
apiMethod,
|
|
51
48
|
...args
|
|
52
49
|
]);
|
|
@@ -62,7 +59,6 @@ const $427566b8f1d3367d$export$3e8733322718eb9 = ()=>{
|
|
|
62
59
|
};
|
|
63
60
|
|
|
64
61
|
|
|
65
|
-
var $76adf94c93f4a7f4$var$_window;
|
|
66
62
|
// Need if we tried to init matomo manually without cookie,
|
|
67
63
|
// and use it after accepting the cookie policy
|
|
68
64
|
let $76adf94c93f4a7f4$var$futureInitMatomoHost = undefined;
|
|
@@ -73,21 +69,19 @@ const $76adf94c93f4a7f4$var$injectMatomoScript = (matomoHost)=>{
|
|
|
73
69
|
}));
|
|
74
70
|
};
|
|
75
71
|
const $76adf94c93f4a7f4$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
76
|
-
var _window___env__, _window__paq;
|
|
77
72
|
if (typeof window === "undefined") // SSR not supported!
|
|
78
73
|
return;
|
|
79
74
|
if (!(0, $427566b8f1d3367d$export$83c2c3def90d3b5a)()) {
|
|
80
75
|
if (matomoHost) $76adf94c93f4a7f4$var$futureInitMatomoHost = matomoHost;
|
|
81
76
|
return;
|
|
82
77
|
}
|
|
83
|
-
const _matomoHost = $76adf94c93f4a7f4$var$futureInitMatomoHost || matomoHost ||
|
|
78
|
+
const _matomoHost = $76adf94c93f4a7f4$var$futureInitMatomoHost || matomoHost || window?.__env__?.matomoHost || undefined;
|
|
84
79
|
if (!_matomoHost) // Where Do I send analytics?
|
|
85
80
|
return;
|
|
86
81
|
if (window._paq) // window._paq has been initialized
|
|
87
82
|
return;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
window === null || window === void 0 ? void 0 : (_window__paq = window._paq) === null || _window__paq === void 0 ? void 0 : _window__paq.push([
|
|
83
|
+
window._paq ??= [];
|
|
84
|
+
window?._paq?.push([
|
|
91
85
|
"requireCookieConsent"
|
|
92
86
|
], [
|
|
93
87
|
"trackPageView"
|
|
@@ -118,12 +112,10 @@ var $dfa3db2a6cffa71c$exports = {};
|
|
|
118
112
|
|
|
119
113
|
$parcel$export($dfa3db2a6cffa71c$exports, "wrapWithEventTrack", function () { return $dfa3db2a6cffa71c$export$e8f57ad64147d191; });
|
|
120
114
|
|
|
121
|
-
const $dfa3db2a6cffa71c$export$e8f57ad64147d191 = (event, fn)=>{
|
|
122
|
-
return event ? (...args)=>{
|
|
115
|
+
const $dfa3db2a6cffa71c$export$e8f57ad64147d191 = (event, fn)=>event ? (...args)=>{
|
|
123
116
|
(0, $427566b8f1d3367d$export$cecaccc605742066)("trackEvent", ...event);
|
|
124
|
-
return fn
|
|
117
|
+
return fn?.(...args);
|
|
125
118
|
} : fn;
|
|
126
|
-
};
|
|
127
119
|
|
|
128
120
|
|
|
129
121
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;AEAA;AAGO,MAAM,4CAA2B;AACjC,MAAM,4CAA0B;AAEhC,MAAM,4CAAsB;IACjC;IACA;CACD;AAEM,MAAM,4CAAkB,IAAe;IAC5C,OAAO,OAAO,WAAW,eAAe,OAAO,IAAI,KAAK;AAC1D;AAEA,MAAM,uDAAiC,CAAC,MAA+B;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;AEAA;AAGO,MAAM,4CAA2B;AACjC,MAAM,4CAA0B;AAEhC,MAAM,4CAAsB;IACjC;IACA;CACD;AAEM,MAAM,4CAAkB,IAAe;IAC5C,OAAO,OAAO,WAAW,eAAe,OAAO,IAAI,KAAK;AAC1D;AAEA,MAAM,uDAAiC,CAAC,MAA+B;IACrE,MAAM,eAAe,IAAI;IAEzB,IAAI,OAAO,WAAW,aACpB,OAAO;IAGT,MAAM,gBAAgB,IAAI,OA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zB;IACF,CAAC;IAED,MAAM,cAAc,8CAAwB,cAAc,QAAQ,SAAS,cAAc;IAEzF,IAAI,CAAC,aACH,6BAA6B;IAC7B;IAGF,IAAI,OAAO,IAAI,EACb,mCAAmC;IACnC;IAGF,OAAO,IAAI,KAAK,EAAE;IAElB,QAAQ,MAAM,KACZ;QAAC;KAAuB,EACxB;QAAC;KAAgB,EACjB;QAAC;KAAqB,EACtB;QAAC;QAAiB,IAAI,IAAI,eAAe,aAAa,IAAI;KAAC,EAC3D;QAAC;QAAa;KAAI,EAClB;QAAC;QAAc;YAAC,CAAC,EAAE,EAAE,CAAA,GAAA,wCAAQ,IAAI,CAAC;SAAC;KAAC,EACpC;QAAC;KAA2B;IAG9B,yCAAmB;AACrB;;AD5DA;;;;;;;AIAA;AAGO,MAAM,4CAAqB,CAAyB,OAA+B,KACxF,QACI,CAAC,GAAG,OAAe;QACjB,CAAA,GAAA,yCAAU,AAAD,EAAE,iBAAiB;QAC5B,OAAO,QAAQ;IACjB,IACA,EAAE;;;;;AJFR,mBAAmB;AACnB,CAAA,GAAA,yCAAS","sources":["packages/analytics/matomo/src/index.ts","packages/analytics/matomo/src/init.ts","packages/analytics/matomo/src/utils.ts","packages/analytics/matomo/src/type.ts","packages/analytics/matomo/src/decoratorts.ts"],"sourcesContent":["import { initMatomo } from './init'\n\nexport * from './type'\nexport * from './decoratorts'\nexport * from './utils'\nexport * from './init'\n\n// Run after import\ninitMatomo()\n","import { getDomain, checkCookieAllowed } 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\n// Need if we tried to init matomo manually without cookie,\n// and use it after accepting the cookie policy\nlet futureInitMatomoHost: string | undefined = undefined\n\nconst injectMatomoScript = (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 if (!checkCookieAllowed()) {\n if (matomoHost) {\n futureInitMatomoHost = matomoHost\n }\n return\n }\n\n const _matomoHost = futureInitMatomoHost || matomoHost || window?.__env__?.matomoHost || undefined\n\n if (!_matomoHost) {\n // Where Do I send analytics?\n return\n }\n\n if (window._paq) {\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 injectMatomoScript(_matomoHost)\n}\n","import { MatomoEventType } from './type'\nimport { initMatomo } from './init'\n\nexport const COOKIE_ALLOWED_VALUE_YES = 'yes'\nexport const COOKIE_ALLOWED_MAIN_KEY = 'cookie-allowed'\n\nexport const COOKIE_ALLOWED_KEYS = [\n 'LIDO_WIDGET__COOKIES_ALLOWED', // will be deprecated soon\n COOKIE_ALLOWED_MAIN_KEY,\n]\n\nexport const matomoAvailable = (): boolean => {\n return typeof window !== 'undefined' && window._paq !== undefined\n}\n\nconst getCrossDomainCookieClientSide = (key: string): string | null => {\n const defaultValue = null\n\n if (typeof window === 'undefined') {\n return defaultValue\n }\n\n const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`)\n return (document.cookie.match(cookieMatcher)?.[2] as string) ?? defaultValue\n}\n\nexport const checkCookieAllowed = (): boolean => {\n if (typeof window === 'undefined') {\n return false\n }\n\n for (const key of COOKIE_ALLOWED_KEYS) {\n const cookieValue = getCrossDomainCookieClientSide(key)\n const cookieAllowed = !!(cookieValue && cookieValue === COOKIE_ALLOWED_VALUE_YES)\n\n if (cookieAllowed) {\n return cookieAllowed\n }\n }\n\n return false\n}\n\nexport const callMatomo = (apiMethod: string, ...args: unknown[]): void => {\n if (!matomoAvailable()) {\n initMatomo()\n }\n\n if (typeof window === 'undefined' || !checkCookieAllowed()) {\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 trackVisibleContentImpressions = (checkOnScroll = true, timeIntervalInMs = 750): void => {\n callMatomo('trackVisibleContentImpressions', checkOnScroll, timeIntervalInMs)\n}\n\nexport const getDomain = () => {\n return location.hostname.split('.').slice(-2).join('.')\n}\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"],"names":[],"version":3,"file":"index.mjs.map"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Matomo analytics",
|
|
4
4
|
"repository": "git@github.com:lidofinance/warehouse.git",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.24.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@lidofinance/config-prettier": "~0.
|
|
27
|
+
"@lidofinance/config-prettier": "~0.24.0",
|
|
28
28
|
"@types/jest": "^29.2.4",
|
|
29
29
|
"jest": "^29.3.1",
|
|
30
30
|
"ts-jest": "^29.0.3",
|