@lidofinance/analytics-matomo 0.9.0 → 0.11.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 +16 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +16 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -35,33 +35,33 @@ const $ef5c629b17efc154$export$69479293c4b47320 = "yes";
|
|
|
35
35
|
const $ef5c629b17efc154$export$ed61d9b9718a39c9 = "cookie-allowed";
|
|
36
36
|
const $ef5c629b17efc154$export$7567476bb64c3721 = [
|
|
37
37
|
"LIDO_WIDGET__COOKIES_ALLOWED",
|
|
38
|
-
$ef5c629b17efc154$export$ed61d9b9718a39c9
|
|
38
|
+
$ef5c629b17efc154$export$ed61d9b9718a39c9
|
|
39
39
|
];
|
|
40
40
|
const $ef5c629b17efc154$export$e5ed1c22a80aba4b = ()=>{
|
|
41
41
|
return typeof window !== "undefined" && window._paq !== undefined;
|
|
42
42
|
};
|
|
43
|
+
const $ef5c629b17efc154$var$getCrossDomainCookieClientSide = (key)=>{
|
|
44
|
+
var _document_cookie_match;
|
|
45
|
+
const defaultValue = null;
|
|
46
|
+
if (typeof window === "undefined") return defaultValue;
|
|
47
|
+
const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`);
|
|
48
|
+
var _document_cookie_match_;
|
|
49
|
+
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;
|
|
50
|
+
};
|
|
43
51
|
const $ef5c629b17efc154$export$83c2c3def90d3b5a = ()=>{
|
|
44
52
|
if (typeof window === "undefined") return false;
|
|
45
|
-
const getCrossDomainCookieClientSide = (key)=>{
|
|
46
|
-
var ref;
|
|
47
|
-
const defaultValue = null;
|
|
48
|
-
if (typeof window === "undefined") return defaultValue;
|
|
49
|
-
const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`);
|
|
50
|
-
var ref1;
|
|
51
|
-
return (ref1 = (ref = document.cookie.match(cookieMatcher)) === null || ref === void 0 ? void 0 : ref[2]) !== null && ref1 !== void 0 ? ref1 : defaultValue;
|
|
52
|
-
};
|
|
53
53
|
for (const key of $ef5c629b17efc154$export$7567476bb64c3721){
|
|
54
|
-
const cookieValue = getCrossDomainCookieClientSide(key);
|
|
54
|
+
const cookieValue = $ef5c629b17efc154$var$getCrossDomainCookieClientSide(key);
|
|
55
55
|
const cookieAllowed = !!(cookieValue && cookieValue === $ef5c629b17efc154$export$69479293c4b47320);
|
|
56
56
|
if (cookieAllowed) return cookieAllowed;
|
|
57
57
|
}
|
|
58
58
|
return false;
|
|
59
59
|
};
|
|
60
60
|
const $ef5c629b17efc154$export$cecaccc605742066 = (apiMethod, ...args)=>{
|
|
61
|
-
var
|
|
61
|
+
var _window__paq;
|
|
62
62
|
if (!$ef5c629b17efc154$export$e5ed1c22a80aba4b()) (0, $8ec118068c18cb0c$export$6ec25100f86fa29d)();
|
|
63
63
|
if (typeof window === "undefined" || !$ef5c629b17efc154$export$83c2c3def90d3b5a()) return;
|
|
64
|
-
window === null || window === void 0 ? void 0 : (
|
|
64
|
+
window === null || window === void 0 ? void 0 : (_window__paq = window._paq) === null || _window__paq === void 0 ? void 0 : _window__paq.push([
|
|
65
65
|
apiMethod,
|
|
66
66
|
...args
|
|
67
67
|
]);
|
|
@@ -85,21 +85,21 @@ const $8ec118068c18cb0c$var$injectMatomoScript = (matomoHost)=>{
|
|
|
85
85
|
}));
|
|
86
86
|
};
|
|
87
87
|
const $8ec118068c18cb0c$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
88
|
-
var
|
|
88
|
+
var _window___env__, _window__paq;
|
|
89
89
|
if (typeof window === "undefined") // SSR not supported!
|
|
90
90
|
return;
|
|
91
91
|
if (!(0, $ef5c629b17efc154$export$83c2c3def90d3b5a)()) {
|
|
92
92
|
if (matomoHost) $8ec118068c18cb0c$var$futureInitMatomoHost = matomoHost;
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
|
-
const _matomoHost = $8ec118068c18cb0c$var$futureInitMatomoHost || matomoHost || (window === null || window === void 0 ? void 0 : (
|
|
95
|
+
const _matomoHost = $8ec118068c18cb0c$var$futureInitMatomoHost || matomoHost || (window === null || window === void 0 ? void 0 : (_window___env__ = window.__env__) === null || _window___env__ === void 0 ? void 0 : _window___env__.matomoHost) || undefined;
|
|
96
96
|
if (!_matomoHost) // Where Do I send analytics?
|
|
97
97
|
return;
|
|
98
|
-
if (
|
|
98
|
+
if (window._paq) // window._paq has been initialized
|
|
99
99
|
return;
|
|
100
100
|
var __paq;
|
|
101
101
|
(__paq = ($8ec118068c18cb0c$var$_window = window)._paq) !== null && __paq !== void 0 ? __paq : $8ec118068c18cb0c$var$_window._paq = [];
|
|
102
|
-
window === null || window === void 0 ? void 0 : (
|
|
102
|
+
window === null || window === void 0 ? void 0 : (_window__paq = window._paq) === null || _window__paq === void 0 ? void 0 : _window__paq.push([
|
|
103
103
|
"requireCookieConsent"
|
|
104
104
|
], [
|
|
105
105
|
"trackPageView"
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;AAGO,MAAM,
|
|
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;QAQ7D;IAPR,MAAM,eAAe,IAAI;IAEzB,IAAI,OAAO,WAAW,a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A1BA,IAAI,OAAO,WAAW,aACpB,qBAAqB;IACrB;IAGF,IAAI,CAAC,CAAA,GAAA,yCAAiB,KAAK;QACzB,IAAI,YACF,6CAAuB;QAEzB;IACF,CAAC;IAED,MAAM,cAAc,8CAAwB,cAAc,CAAA,mBAAA,oBAAA,KAAA,IAAA,CAAA,kBAAA,OAAQ,OAAO,cAAf,6BAAA,KAAA,IAAA,gBAAiB,UAAF,AAAD,KAAiB;IAEzF,IAAI,CAAC,aACH,6BAA6B;IAC7B;IAGF,IAAI,OAAO,IAAI,EACb,mCAAmC;IACnC;;IAGF,UAAA,gCAAA,QAAO,6CAAP,8BAAO,OAAS,EAAE;IAElB,mBAAA,oBAAA,KAAA,IAAA,CAAA,eAAA,OAAQ,IAAI,cAAZ,0BAAA,KAAA,IAAA,aAAc,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;IACxF,OAAA,QACI,CAAC,GAAG,OAAe;QACjB,CAAA,GAAA,yCAAU,AAAD,EAAE,iBAAiB;QAC5B,OAAO,eAAA,gBAAA,KAAA,IAAA,MAAQ;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 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.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const trackEvent: (category: string, action: string, name: string) => voi
|
|
|
9
9
|
export const getDomain: () => string;
|
|
10
10
|
declare global {
|
|
11
11
|
interface Window {
|
|
12
|
-
_paq
|
|
12
|
+
_paq?: undefined | [string, ...unknown[]][];
|
|
13
13
|
__env__: {
|
|
14
14
|
matomoHost: string;
|
|
15
15
|
} & Record<string | number | symbol, unknown>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;ACG9E,OAAO,MAAM,gCAAgC,CAAA;AAC7C,OAAO,MAAM,0CAA0C,CAAA;AAEvD,OAAO,MAAM,6BAGZ,CAAA;AAED,OAAO,MAAM,uBAAsB,OAElC,CAAA;
|
|
1
|
+
{"mappings":"AAAA,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;ACG9E,OAAO,MAAM,gCAAgC,CAAA;AAC7C,OAAO,MAAM,0CAA0C,CAAA;AAEvD,OAAO,MAAM,6BAGZ,CAAA;AAED,OAAO,MAAM,uBAAsB,OAElC,CAAA;AAaD,OAAO,MAAM,0BAAyB,OAerC,CAAA;AAED,OAAO,MAAM,wBAAyB,MAAM,WAAW,OAAO,EAAE,KAAG,IAUlE,CAAA;AAED,OAAO,MAAM,gEAA0C,IAEtD,CAAA;AAED,OAAO,MAAM,uBAEZ,CAAA;AC3DD,QAAQ,MAAM,CAAC;IACb,UAAU,MAAM;QACd,IAAI,CAAC,EAAE,SAAS,GAAG,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAAA;QAC3C,OAAO,EAAE;YAAE,UAAU,EAAE,MAAM,CAAA;SAAE,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAA;KAC5E;CACF;AAeD,OAAO,MAAM,0BAA2B,MAAM,KAAG,IAsChD,CAAA;ACzDD,OAAO,MAAM,oDAAqD,eAAe,GAAG,IAAI,6CAMhF,CAAA","sources":["packages/analytics/matomo/src/src/type.ts","packages/analytics/matomo/src/src/utils.ts","packages/analytics/matomo/src/src/init.ts","packages/analytics/matomo/src/src/decoratorts.ts","packages/analytics/matomo/src/src/index.ts","packages/analytics/matomo/src/index.ts"],"sourcesContent":[null,null,null,null,null,"import { initMatomo } from './init'\n\nexport * from './type'\nexport * from './decoratorts'\nexport * from './utils'\nexport * from './init'\n\n// Run after import\ninitMatomo()\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.mjs
CHANGED
|
@@ -19,33 +19,33 @@ const $427566b8f1d3367d$export$69479293c4b47320 = "yes";
|
|
|
19
19
|
const $427566b8f1d3367d$export$ed61d9b9718a39c9 = "cookie-allowed";
|
|
20
20
|
const $427566b8f1d3367d$export$7567476bb64c3721 = [
|
|
21
21
|
"LIDO_WIDGET__COOKIES_ALLOWED",
|
|
22
|
-
$427566b8f1d3367d$export$ed61d9b9718a39c9
|
|
22
|
+
$427566b8f1d3367d$export$ed61d9b9718a39c9
|
|
23
23
|
];
|
|
24
24
|
const $427566b8f1d3367d$export$e5ed1c22a80aba4b = ()=>{
|
|
25
25
|
return typeof window !== "undefined" && window._paq !== undefined;
|
|
26
26
|
};
|
|
27
|
+
const $427566b8f1d3367d$var$getCrossDomainCookieClientSide = (key)=>{
|
|
28
|
+
var _document_cookie_match;
|
|
29
|
+
const defaultValue = null;
|
|
30
|
+
if (typeof window === "undefined") return defaultValue;
|
|
31
|
+
const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`);
|
|
32
|
+
var _document_cookie_match_;
|
|
33
|
+
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;
|
|
34
|
+
};
|
|
27
35
|
const $427566b8f1d3367d$export$83c2c3def90d3b5a = ()=>{
|
|
28
36
|
if (typeof window === "undefined") return false;
|
|
29
|
-
const getCrossDomainCookieClientSide = (key)=>{
|
|
30
|
-
var ref;
|
|
31
|
-
const defaultValue = null;
|
|
32
|
-
if (typeof window === "undefined") return defaultValue;
|
|
33
|
-
const cookieMatcher = new RegExp(`(^| )${key}=([^;]+)`);
|
|
34
|
-
var ref1;
|
|
35
|
-
return (ref1 = (ref = document.cookie.match(cookieMatcher)) === null || ref === void 0 ? void 0 : ref[2]) !== null && ref1 !== void 0 ? ref1 : defaultValue;
|
|
36
|
-
};
|
|
37
37
|
for (const key of $427566b8f1d3367d$export$7567476bb64c3721){
|
|
38
|
-
const cookieValue = getCrossDomainCookieClientSide(key);
|
|
38
|
+
const cookieValue = $427566b8f1d3367d$var$getCrossDomainCookieClientSide(key);
|
|
39
39
|
const cookieAllowed = !!(cookieValue && cookieValue === $427566b8f1d3367d$export$69479293c4b47320);
|
|
40
40
|
if (cookieAllowed) return cookieAllowed;
|
|
41
41
|
}
|
|
42
42
|
return false;
|
|
43
43
|
};
|
|
44
44
|
const $427566b8f1d3367d$export$cecaccc605742066 = (apiMethod, ...args)=>{
|
|
45
|
-
var
|
|
45
|
+
var _window__paq;
|
|
46
46
|
if (!$427566b8f1d3367d$export$e5ed1c22a80aba4b()) (0, $76adf94c93f4a7f4$export$6ec25100f86fa29d)();
|
|
47
47
|
if (typeof window === "undefined" || !$427566b8f1d3367d$export$83c2c3def90d3b5a()) return;
|
|
48
|
-
window === null || window === void 0 ? void 0 : (
|
|
48
|
+
window === null || window === void 0 ? void 0 : (_window__paq = window._paq) === null || _window__paq === void 0 ? void 0 : _window__paq.push([
|
|
49
49
|
apiMethod,
|
|
50
50
|
...args
|
|
51
51
|
]);
|
|
@@ -69,21 +69,21 @@ const $76adf94c93f4a7f4$var$injectMatomoScript = (matomoHost)=>{
|
|
|
69
69
|
}));
|
|
70
70
|
};
|
|
71
71
|
const $76adf94c93f4a7f4$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
72
|
-
var
|
|
72
|
+
var _window___env__, _window__paq;
|
|
73
73
|
if (typeof window === "undefined") // SSR not supported!
|
|
74
74
|
return;
|
|
75
75
|
if (!(0, $427566b8f1d3367d$export$83c2c3def90d3b5a)()) {
|
|
76
76
|
if (matomoHost) $76adf94c93f4a7f4$var$futureInitMatomoHost = matomoHost;
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
-
const _matomoHost = $76adf94c93f4a7f4$var$futureInitMatomoHost || matomoHost || (window === null || window === void 0 ? void 0 : (
|
|
79
|
+
const _matomoHost = $76adf94c93f4a7f4$var$futureInitMatomoHost || matomoHost || (window === null || window === void 0 ? void 0 : (_window___env__ = window.__env__) === null || _window___env__ === void 0 ? void 0 : _window___env__.matomoHost) || undefined;
|
|
80
80
|
if (!_matomoHost) // Where Do I send analytics?
|
|
81
81
|
return;
|
|
82
|
-
if (
|
|
82
|
+
if (window._paq) // window._paq has been initialized
|
|
83
83
|
return;
|
|
84
84
|
var __paq;
|
|
85
85
|
(__paq = ($76adf94c93f4a7f4$var$_window = window)._paq) !== null && __paq !== void 0 ? __paq : $76adf94c93f4a7f4$var$_window._paq = [];
|
|
86
|
-
window === null || window === void 0 ? void 0 : (
|
|
86
|
+
window === null || window === void 0 ? void 0 : (_window__paq = window._paq) === null || _window__paq === void 0 ? void 0 : _window__paq.push([
|
|
87
87
|
"requireCookieConsent"
|
|
88
88
|
], [
|
|
89
89
|
"trackPageView"
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;AEAA;AAGO,MAAM,
|
|
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;QAQ7D;IAPR,MAAM,eAAe,IAAI;IAEzB,IAAI,OAAO,WAAW,aACpB,OAAO;IAGT,MAAM,gBAAgB,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,QAAQ,CAAC;QAC9C;IAAR,OAAO,CAAC,0BAAA,CAAA,yBAAA,SAAS,MAAM,CAAC,KAAK,CAAC,4BAAtB,oCAAA,KAAA,IAAA,sBAAsC,CAAC,EAAE,cAAzC,qCAAA,0BAAwD,YAAY;AAC9E;AAEO,MAAM,4CAAqB,IAAe;IAC/C,IAAI,OAAO,WAAW,aACpB,OAAO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A6B;IAC7B;IAGF,IAAI,OAAO,IAAI,EACb,mCAAmC;IACnC;;IAGF,UAAA,gCAAA,QAAO,6CAAP,8BAAO,OAAS,EAAE;IAElB,mBAAA,oBAAA,KAAA,IAAA,CAAA,eAAA,OAAQ,IAAI,cAAZ,0BAAA,KAAA,IAAA,aAAc,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;IACxF,OAAA,QACI,CAAC,GAAG,OAAe;QACjB,CAAA,GAAA,yCAAU,AAAD,EAAE,iBAAiB;QAC5B,OAAO,eAAA,gBAAA,KAAA,IAAA,MAAQ;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 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.11.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"types": "dist/index.d.ts",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "parcel build",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"lint": "eslint . && prettier --check src",
|
|
21
|
+
"lint:fix": "eslint --fix . && prettier --check src --write",
|
|
22
22
|
"types": "tsc --noEmit",
|
|
23
23
|
"test": "jest"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@lidofinance/config-prettier": "~0.
|
|
28
|
-
"@types/jest": "^
|
|
29
|
-
"jest": "^
|
|
30
|
-
"ts-jest": "^
|
|
27
|
+
"@lidofinance/config-prettier": "~0.11.0",
|
|
28
|
+
"@types/jest": "^29.2.4",
|
|
29
|
+
"jest": "^29.3.1",
|
|
30
|
+
"ts-jest": "^29.0.3",
|
|
31
31
|
"jest-environment-jsdom": "^28.0.0"
|
|
32
32
|
}
|
|
33
33
|
}
|