@lidofinance/analytics-matomo 0.6.0 → 0.8.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 +16 -1
- package/dist/index.cjs +65 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +65 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @lidofinance/matomo
|
|
1
|
+
# @lidofinance/analytics-matomo
|
|
2
2
|
|
|
3
3
|
Matomo analytics. You can read about Matomo [there](https://matomo.org/).
|
|
4
4
|
|
|
@@ -6,6 +6,20 @@ Matomo analytics. You can read about Matomo [there](https://matomo.org/).
|
|
|
6
6
|
|
|
7
7
|
`yarn add @lidofinance/analytics-matomo`
|
|
8
8
|
|
|
9
|
+
## Cookie
|
|
10
|
+
|
|
11
|
+
Module does not send matomo event if cookie forbids.
|
|
12
|
+
|
|
13
|
+
If you need to send matomo event, you should set cookie with one of key:
|
|
14
|
+
- 'LIDO_WIDGET__COOKIES_ALLOWED' soon will be deprecated
|
|
15
|
+
- 'cookie-allowed' use it
|
|
16
|
+
|
|
17
|
+
and cookie value must be 'yes'.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
document.cookie = 'cookie-allowed=yes'
|
|
21
|
+
```
|
|
22
|
+
|
|
9
23
|
## Usage
|
|
10
24
|
|
|
11
25
|
### Init Matomo
|
|
@@ -63,3 +77,4 @@ const someHandler = wrapWithEventTrack(matomoSomeEvent, (arg1, arg2) => {
|
|
|
63
77
|
|
|
64
78
|
someHandler('some_value1', 'some_value2')
|
|
65
79
|
```
|
|
80
|
+
|
package/dist/index.cjs
CHANGED
|
@@ -17,22 +17,50 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
17
17
|
function $parcel$export(e, n, v, s) {
|
|
18
18
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
19
19
|
}
|
|
20
|
-
var $
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var $b6335fbce4f6ccb6$exports = {};
|
|
20
|
+
var $8ec118068c18cb0c$exports = {};
|
|
24
21
|
|
|
25
|
-
$parcel$export($
|
|
22
|
+
$parcel$export($8ec118068c18cb0c$exports, "initMatomo", function () { return $8ec118068c18cb0c$export$6ec25100f86fa29d; });
|
|
26
23
|
var $ef5c629b17efc154$exports = {};
|
|
27
24
|
|
|
25
|
+
$parcel$export($ef5c629b17efc154$exports, "COOKIE_ALLOWED_VALUE_YES", function () { return $ef5c629b17efc154$export$69479293c4b47320; });
|
|
26
|
+
$parcel$export($ef5c629b17efc154$exports, "COOKIE_ALLOWED_MAIN_KEY", function () { return $ef5c629b17efc154$export$ed61d9b9718a39c9; });
|
|
27
|
+
$parcel$export($ef5c629b17efc154$exports, "COOKIE_ALLOWED_KEYS", function () { return $ef5c629b17efc154$export$7567476bb64c3721; });
|
|
28
28
|
$parcel$export($ef5c629b17efc154$exports, "matomoAvailable", function () { return $ef5c629b17efc154$export$e5ed1c22a80aba4b; });
|
|
29
|
+
$parcel$export($ef5c629b17efc154$exports, "checkCookieAllowed", function () { return $ef5c629b17efc154$export$83c2c3def90d3b5a; });
|
|
29
30
|
$parcel$export($ef5c629b17efc154$exports, "callMatomo", function () { return $ef5c629b17efc154$export$cecaccc605742066; });
|
|
30
31
|
$parcel$export($ef5c629b17efc154$exports, "trackEvent", function () { return $ef5c629b17efc154$export$73d0a139caca1fee; });
|
|
31
32
|
$parcel$export($ef5c629b17efc154$exports, "getDomain", function () { return $ef5c629b17efc154$export$3e8733322718eb9; });
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
const $ef5c629b17efc154$export$69479293c4b47320 = "yes";
|
|
35
|
+
const $ef5c629b17efc154$export$ed61d9b9718a39c9 = "cookie-allowed";
|
|
36
|
+
const $ef5c629b17efc154$export$7567476bb64c3721 = [
|
|
37
|
+
"LIDO_WIDGET__COOKIES_ALLOWED",
|
|
38
|
+
$ef5c629b17efc154$export$ed61d9b9718a39c9,
|
|
39
|
+
];
|
|
40
|
+
const $ef5c629b17efc154$export$e5ed1c22a80aba4b = ()=>{
|
|
41
|
+
return typeof window !== "undefined" && window._paq !== undefined;
|
|
42
|
+
};
|
|
43
|
+
const $ef5c629b17efc154$export$83c2c3def90d3b5a = ()=>{
|
|
44
|
+
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
|
+
for (const key of $ef5c629b17efc154$export$7567476bb64c3721){
|
|
54
|
+
const cookieValue = getCrossDomainCookieClientSide(key);
|
|
55
|
+
const cookieAllowed = !!(cookieValue && cookieValue === $ef5c629b17efc154$export$69479293c4b47320);
|
|
56
|
+
if (cookieAllowed) return cookieAllowed;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
33
60
|
const $ef5c629b17efc154$export$cecaccc605742066 = (apiMethod, ...args)=>{
|
|
34
61
|
var ref;
|
|
35
|
-
if (
|
|
62
|
+
if (!$ef5c629b17efc154$export$e5ed1c22a80aba4b()) (0, $8ec118068c18cb0c$export$6ec25100f86fa29d)();
|
|
63
|
+
if (typeof window === "undefined" || !$ef5c629b17efc154$export$83c2c3def90d3b5a()) return;
|
|
36
64
|
window === null || window === void 0 ? void 0 : (ref = window._paq) === null || ref === void 0 ? void 0 : ref.push([
|
|
37
65
|
apiMethod,
|
|
38
66
|
...args
|
|
@@ -46,21 +74,11 @@ const $ef5c629b17efc154$export$3e8733322718eb9 = ()=>{
|
|
|
46
74
|
};
|
|
47
75
|
|
|
48
76
|
|
|
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
77
|
var $8ec118068c18cb0c$var$_window;
|
|
63
|
-
|
|
78
|
+
// Need if we tried to init matomo manually without cookie,
|
|
79
|
+
// and use it after accepting the cookie policy
|
|
80
|
+
let $8ec118068c18cb0c$var$futureInitMatomoHost = undefined;
|
|
81
|
+
const $8ec118068c18cb0c$var$injectMatomoScript = (matomoHost)=>{
|
|
64
82
|
document.documentElement.appendChild(Object.assign(document.createElement("script"), {
|
|
65
83
|
async: true,
|
|
66
84
|
src: new URL("/matomo.js", matomoHost).href
|
|
@@ -70,7 +88,11 @@ const $8ec118068c18cb0c$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
|
70
88
|
var ref, ref1;
|
|
71
89
|
if (typeof window === "undefined") // SSR not supported!
|
|
72
90
|
return;
|
|
73
|
-
|
|
91
|
+
if (!(0, $ef5c629b17efc154$export$83c2c3def90d3b5a)()) {
|
|
92
|
+
if (matomoHost) $8ec118068c18cb0c$var$futureInitMatomoHost = matomoHost;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const _matomoHost = $8ec118068c18cb0c$var$futureInitMatomoHost || matomoHost || (window === null || window === void 0 ? void 0 : (ref = window.__env__) === null || ref === void 0 ? void 0 : ref.matomoHost) || undefined;
|
|
74
96
|
if (!_matomoHost) // Where Do I send analytics?
|
|
75
97
|
return;
|
|
76
98
|
if ("_paq" in window) // window._paq has been initialized
|
|
@@ -97,16 +119,33 @@ const $8ec118068c18cb0c$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
|
97
119
|
], [
|
|
98
120
|
"enableCrossDomainLinking"
|
|
99
121
|
]);
|
|
100
|
-
$8ec118068c18cb0c$var$
|
|
122
|
+
$8ec118068c18cb0c$var$injectMatomoScript(_matomoHost);
|
|
101
123
|
};
|
|
102
|
-
// Run after import
|
|
103
|
-
$8ec118068c18cb0c$export$6ec25100f86fa29d();
|
|
104
124
|
|
|
105
125
|
|
|
126
|
+
var $6b3e3d225028b1eb$exports = {};
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
var $b6335fbce4f6ccb6$exports = {};
|
|
130
|
+
|
|
131
|
+
$parcel$export($b6335fbce4f6ccb6$exports, "wrapWithEventTrack", function () { return $b6335fbce4f6ccb6$export$e8f57ad64147d191; });
|
|
132
|
+
|
|
133
|
+
const $b6335fbce4f6ccb6$export$e8f57ad64147d191 = (event, fn)=>{
|
|
134
|
+
return event ? (...args)=>{
|
|
135
|
+
(0, $ef5c629b17efc154$export$cecaccc605742066)("trackEvent", ...event);
|
|
136
|
+
return fn === null || fn === void 0 ? void 0 : fn(...args);
|
|
137
|
+
} : fn;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
// Run after import
|
|
144
|
+
(0, $8ec118068c18cb0c$export$6ec25100f86fa29d)();
|
|
145
|
+
$parcel$exportWildcard(module.exports, $8ec118068c18cb0c$exports);
|
|
106
146
|
$parcel$exportWildcard(module.exports, $6b3e3d225028b1eb$exports);
|
|
107
147
|
$parcel$exportWildcard(module.exports, $b6335fbce4f6ccb6$exports);
|
|
108
148
|
$parcel$exportWildcard(module.exports, $ef5c629b17efc154$exports);
|
|
109
|
-
$parcel$exportWildcard(module.exports, $8ec118068c18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,AAAG,GAAQ;QACjB,CAAA,GAAA,yCAAU,CAAA,CAAC,YAAY,KAAK,KAAK,CAAC;QAClC,OAAO,EAAE,aAAF,EAAE,WAAW,GAAb,KAAA,CAAa,GAAb,EAAE,IAAM,IAAI,CAAC,CAAA;KACrB,GACD,EAAE,CAAA;CAAA;;;;;AJFR,mBAAmB;AACnB,CAAA,GAAA,yCAAU,CAAA,EAAE","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 ('_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 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\nexport const checkCookieAllowed = (): boolean => {\n if (typeof window === 'undefined') {\n return false\n }\n\n const 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\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
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export type MatomoEventType = [category: string, action: string, name: string];
|
|
2
|
-
export const
|
|
2
|
+
export const COOKIE_ALLOWED_VALUE_YES = "yes";
|
|
3
|
+
export const COOKIE_ALLOWED_MAIN_KEY = "cookie-allowed";
|
|
4
|
+
export const COOKIE_ALLOWED_KEYS: string[];
|
|
5
|
+
export const matomoAvailable: () => boolean;
|
|
6
|
+
export const checkCookieAllowed: () => boolean;
|
|
3
7
|
export const callMatomo: (apiMethod: string, ...args: unknown[]) => void;
|
|
4
8
|
export const trackEvent: (category: string, action: string, name: string) => void;
|
|
5
9
|
export const getDomain: () => string;
|
|
6
|
-
export const wrapWithEventTrack: <A extends unknown[], R>(event: MatomoEventType | void, fn: (...args: A) => R) => (...args: A) => R;
|
|
7
10
|
declare global {
|
|
8
11
|
interface Window {
|
|
9
12
|
_paq: undefined | [string, ...unknown[]][];
|
|
@@ -13,5 +16,6 @@ declare global {
|
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
export const initMatomo: (matomoHost?: string) => void;
|
|
19
|
+
export const wrapWithEventTrack: <A extends unknown[], R>(event: MatomoEventType | void, fn: (...args: A) => R) => (...args: A) => R;
|
|
16
20
|
|
|
17
21
|
//# sourceMappingURL=index.d.ts.map
|
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;
|
|
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;AAED,OAAO,MAAM,0BAAyB,OA0BrC,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,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;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
|
@@ -1,22 +1,50 @@
|
|
|
1
1
|
function $parcel$export(e, n, v, s) {
|
|
2
2
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
3
3
|
}
|
|
4
|
-
var $
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var $dfa3db2a6cffa71c$exports = {};
|
|
4
|
+
var $76adf94c93f4a7f4$exports = {};
|
|
8
5
|
|
|
9
|
-
$parcel$export($
|
|
6
|
+
$parcel$export($76adf94c93f4a7f4$exports, "initMatomo", function () { return $76adf94c93f4a7f4$export$6ec25100f86fa29d; });
|
|
10
7
|
var $427566b8f1d3367d$exports = {};
|
|
11
8
|
|
|
9
|
+
$parcel$export($427566b8f1d3367d$exports, "COOKIE_ALLOWED_VALUE_YES", function () { return $427566b8f1d3367d$export$69479293c4b47320; });
|
|
10
|
+
$parcel$export($427566b8f1d3367d$exports, "COOKIE_ALLOWED_MAIN_KEY", function () { return $427566b8f1d3367d$export$ed61d9b9718a39c9; });
|
|
11
|
+
$parcel$export($427566b8f1d3367d$exports, "COOKIE_ALLOWED_KEYS", function () { return $427566b8f1d3367d$export$7567476bb64c3721; });
|
|
12
12
|
$parcel$export($427566b8f1d3367d$exports, "matomoAvailable", function () { return $427566b8f1d3367d$export$e5ed1c22a80aba4b; });
|
|
13
|
+
$parcel$export($427566b8f1d3367d$exports, "checkCookieAllowed", function () { return $427566b8f1d3367d$export$83c2c3def90d3b5a; });
|
|
13
14
|
$parcel$export($427566b8f1d3367d$exports, "callMatomo", function () { return $427566b8f1d3367d$export$cecaccc605742066; });
|
|
14
15
|
$parcel$export($427566b8f1d3367d$exports, "trackEvent", function () { return $427566b8f1d3367d$export$73d0a139caca1fee; });
|
|
15
16
|
$parcel$export($427566b8f1d3367d$exports, "getDomain", function () { return $427566b8f1d3367d$export$3e8733322718eb9; });
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
const $427566b8f1d3367d$export$69479293c4b47320 = "yes";
|
|
19
|
+
const $427566b8f1d3367d$export$ed61d9b9718a39c9 = "cookie-allowed";
|
|
20
|
+
const $427566b8f1d3367d$export$7567476bb64c3721 = [
|
|
21
|
+
"LIDO_WIDGET__COOKIES_ALLOWED",
|
|
22
|
+
$427566b8f1d3367d$export$ed61d9b9718a39c9,
|
|
23
|
+
];
|
|
24
|
+
const $427566b8f1d3367d$export$e5ed1c22a80aba4b = ()=>{
|
|
25
|
+
return typeof window !== "undefined" && window._paq !== undefined;
|
|
26
|
+
};
|
|
27
|
+
const $427566b8f1d3367d$export$83c2c3def90d3b5a = ()=>{
|
|
28
|
+
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
|
+
for (const key of $427566b8f1d3367d$export$7567476bb64c3721){
|
|
38
|
+
const cookieValue = getCrossDomainCookieClientSide(key);
|
|
39
|
+
const cookieAllowed = !!(cookieValue && cookieValue === $427566b8f1d3367d$export$69479293c4b47320);
|
|
40
|
+
if (cookieAllowed) return cookieAllowed;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
17
44
|
const $427566b8f1d3367d$export$cecaccc605742066 = (apiMethod, ...args)=>{
|
|
18
45
|
var ref;
|
|
19
|
-
if (
|
|
46
|
+
if (!$427566b8f1d3367d$export$e5ed1c22a80aba4b()) (0, $76adf94c93f4a7f4$export$6ec25100f86fa29d)();
|
|
47
|
+
if (typeof window === "undefined" || !$427566b8f1d3367d$export$83c2c3def90d3b5a()) return;
|
|
20
48
|
window === null || window === void 0 ? void 0 : (ref = window._paq) === null || ref === void 0 ? void 0 : ref.push([
|
|
21
49
|
apiMethod,
|
|
22
50
|
...args
|
|
@@ -30,21 +58,11 @@ const $427566b8f1d3367d$export$3e8733322718eb9 = ()=>{
|
|
|
30
58
|
};
|
|
31
59
|
|
|
32
60
|
|
|
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
61
|
var $76adf94c93f4a7f4$var$_window;
|
|
47
|
-
|
|
62
|
+
// Need if we tried to init matomo manually without cookie,
|
|
63
|
+
// and use it after accepting the cookie policy
|
|
64
|
+
let $76adf94c93f4a7f4$var$futureInitMatomoHost = undefined;
|
|
65
|
+
const $76adf94c93f4a7f4$var$injectMatomoScript = (matomoHost)=>{
|
|
48
66
|
document.documentElement.appendChild(Object.assign(document.createElement("script"), {
|
|
49
67
|
async: true,
|
|
50
68
|
src: new URL("/matomo.js", matomoHost).href
|
|
@@ -54,7 +72,11 @@ const $76adf94c93f4a7f4$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
|
54
72
|
var ref, ref1;
|
|
55
73
|
if (typeof window === "undefined") // SSR not supported!
|
|
56
74
|
return;
|
|
57
|
-
|
|
75
|
+
if (!(0, $427566b8f1d3367d$export$83c2c3def90d3b5a)()) {
|
|
76
|
+
if (matomoHost) $76adf94c93f4a7f4$var$futureInitMatomoHost = matomoHost;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const _matomoHost = $76adf94c93f4a7f4$var$futureInitMatomoHost || matomoHost || (window === null || window === void 0 ? void 0 : (ref = window.__env__) === null || ref === void 0 ? void 0 : ref.matomoHost) || undefined;
|
|
58
80
|
if (!_matomoHost) // Where Do I send analytics?
|
|
59
81
|
return;
|
|
60
82
|
if ("_paq" in window) // window._paq has been initialized
|
|
@@ -81,13 +103,30 @@ const $76adf94c93f4a7f4$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
|
81
103
|
], [
|
|
82
104
|
"enableCrossDomainLinking"
|
|
83
105
|
]);
|
|
84
|
-
$76adf94c93f4a7f4$var$
|
|
106
|
+
$76adf94c93f4a7f4$var$injectMatomoScript(_matomoHost);
|
|
85
107
|
};
|
|
86
|
-
// Run after import
|
|
87
|
-
$76adf94c93f4a7f4$export$6ec25100f86fa29d();
|
|
88
108
|
|
|
89
109
|
|
|
110
|
+
var $ca05ace152e51327$exports = {};
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
var $dfa3db2a6cffa71c$exports = {};
|
|
114
|
+
|
|
115
|
+
$parcel$export($dfa3db2a6cffa71c$exports, "wrapWithEventTrack", function () { return $dfa3db2a6cffa71c$export$e8f57ad64147d191; });
|
|
116
|
+
|
|
117
|
+
const $dfa3db2a6cffa71c$export$e8f57ad64147d191 = (event, fn)=>{
|
|
118
|
+
return event ? (...args)=>{
|
|
119
|
+
(0, $427566b8f1d3367d$export$cecaccc605742066)("trackEvent", ...event);
|
|
120
|
+
return fn === null || fn === void 0 ? void 0 : fn(...args);
|
|
121
|
+
} : fn;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
// Run after import
|
|
128
|
+
(0, $76adf94c93f4a7f4$export$6ec25100f86fa29d)();
|
|
90
129
|
|
|
91
130
|
|
|
92
|
-
export {$dfa3db2a6cffa71c$export$e8f57ad64147d191 as wrapWithEventTrack, $427566b8f1d3367d$export$e5ed1c22a80aba4b as matomoAvailable, $427566b8f1d3367d$export$
|
|
131
|
+
export {$76adf94c93f4a7f4$export$6ec25100f86fa29d as initMatomo, $dfa3db2a6cffa71c$export$e8f57ad64147d191 as wrapWithEventTrack, $427566b8f1d3367d$export$69479293c4b47320 as COOKIE_ALLOWED_VALUE_YES, $427566b8f1d3367d$export$ed61d9b9718a39c9 as COOKIE_ALLOWED_MAIN_KEY, $427566b8f1d3367d$export$7567476bb64c3721 as COOKIE_ALLOWED_KEYS, $427566b8f1d3367d$export$e5ed1c22a80aba4b as matomoAvailable, $427566b8f1d3367d$export$83c2c3def90d3b5a as checkCookieAllowed, $427566b8f1d3367d$export$cecaccc605742066 as callMatomo, $427566b8f1d3367d$export$73d0a139caca1fee as trackEvent, $427566b8f1d3367d$export$3e8733322718eb9 as getDomain};
|
|
93
132
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;AEAA;AAGO,MAAM,yCAAwB,GAAG,KAAK;AACtC,MAAM,yCAAuB,GAAG,gBAAgB;AAEhD,MAAM,yCAAmB,GAAG;IACjC,8BAA8B;IAC9B,yCAAuB;CACxB;AAEM,MAAM,yCAAe,GAAG,IAAe;IAC5C,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,CAAA;CAClE;AAEM,MAAM,yCAAkB,GAAG,IAAe;IAC/C,IAAI,OAAO,MAAM,KAAK,WAAW,EAC/B,OAAO,KAAK,CAAA;IAGd,MAAM,8BAA8B,GAAG,CAAC,GAAW,GAAoB;YAQ7D,GAAoC;QAP5C,MAAM,YAAY,GAAG,IAAI;QAEzB,IAAI,OAAO,MAAM,KAAK,WAAW,EAC/B,OAAO,YAAY,CAAA;QAGrB,MAAM,aAAa,GAAG,IAAI,MAAM,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC/C,IAAyC;QAAjD,OAAO,CAAC,IAAyC,GAAzC,CAAA,GAAoC,GAApC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,cAApC,GAAoC,WAAK,GAAzC,KAAA,CAAyC,GAAzC,GAAoC,AAAE,CAAC,CAAC,CAAC,cAAzC,IAAyC,cAAzC,IAAyC,GAAe,YAAY,CAAA;KAC7E;IAED,KAAK,MAAM,GAAG,IAAI,yCAAmB,CAAE;QACrC,MAAM,WAAW,GAAG,8BAA8B,CAAC,GAAG,CAAC;QACvD,MAAM,aAAa,GAAG,CAAC,CAAE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B,KAA6B,EAAE,EAAqB;IAC7G,OAAA,KAAK,GACD,CAAC,GAAG,IAAI,AAAG,GAAQ;QACjB,CAAA,GAAA,yCAAU,CAAA,CAAC,YAAY,KAAK,KAAK,CAAC;QAClC,OAAO,EAAE,aAAF,EAAE,WAAW,GAAb,KAAA,CAAa,GAAb,EAAE,IAAM,IAAI,CAAC,CAAA;KACrB,GACD,EAAE,CAAA;CAAA;;;;;AJFR,mBAAmB;AACnB,CAAA,GAAA,yCAAU,CAAA,EAAE","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 ('_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 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\nexport const checkCookieAllowed = (): boolean => {\n if (typeof window === 'undefined') {\n return false\n }\n\n const 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\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.8.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.8.0",
|
|
28
28
|
"@types/jest": "^28.0.0",
|
|
29
29
|
"jest": "^28.0.0",
|
|
30
30
|
"ts-jest": "^28.0.0",
|