@lidofinance/analytics-matomo 0.31.0 → 0.33.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 +14 -1
- package/dist/index.cjs +54 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +54 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -53,6 +53,20 @@ initMatomo('https://matomo.somedomain.com/')
|
|
|
53
53
|
// some code
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
You can also pass any [matomo configuration](https://developer.matomo.org/guides/tracking-javascript-guide) as a second argument
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
initMatomo('https://matomo.somedomain.com/', [
|
|
60
|
+
// enable option
|
|
61
|
+
['option', true],
|
|
62
|
+
['option'],
|
|
63
|
+
// disable option
|
|
64
|
+
['option', false],
|
|
65
|
+
// enable and customize option
|
|
66
|
+
['option', 'value'],
|
|
67
|
+
])
|
|
68
|
+
```
|
|
69
|
+
|
|
56
70
|
### Track event
|
|
57
71
|
|
|
58
72
|
```ts
|
|
@@ -77,4 +91,3 @@ const someHandler = wrapWithEventTrack(matomoSomeEvent, (arg1, arg2) => {
|
|
|
77
91
|
|
|
78
92
|
someHandler('some_value1', 'some_value2')
|
|
79
93
|
```
|
|
80
|
-
|
package/dist/index.cjs
CHANGED
|
@@ -84,7 +84,7 @@ const $8ec118068c18cb0c$var$injectMatomoScript = (matomoHost)=>{
|
|
|
84
84
|
src: new URL("/matomo.js", matomoHost).href
|
|
85
85
|
}));
|
|
86
86
|
};
|
|
87
|
-
const $8ec118068c18cb0c$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
87
|
+
const $8ec118068c18cb0c$export$6ec25100f86fa29d = (matomoHost, customConfig = [])=>{
|
|
88
88
|
if (typeof window === "undefined") // SSR not supported!
|
|
89
89
|
return;
|
|
90
90
|
if (!(0, $ef5c629b17efc154$export$83c2c3def90d3b5a)()) {
|
|
@@ -97,26 +97,61 @@ const $8ec118068c18cb0c$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
|
97
97
|
if (window._paq) // window._paq has been initialized
|
|
98
98
|
return;
|
|
99
99
|
window._paq ??= [];
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
const rawConfig = [
|
|
101
|
+
// These are hardcoded values and cannot be changed
|
|
102
|
+
[
|
|
103
|
+
"setTrackerUrl",
|
|
104
|
+
new URL("/matomo.php", _matomoHost).href
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"requireCookieConsent",
|
|
108
|
+
true
|
|
109
|
+
],
|
|
110
|
+
// These are custom settings
|
|
111
|
+
...customConfig,
|
|
112
|
+
// These are default settings, will be overwritten if custom set
|
|
113
|
+
[
|
|
114
|
+
"trackPageView",
|
|
115
|
+
true
|
|
116
|
+
],
|
|
114
117
|
[
|
|
115
|
-
|
|
118
|
+
"enableLinkTracking",
|
|
119
|
+
true
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
"setSiteId",
|
|
123
|
+
"1"
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
"setDomains",
|
|
127
|
+
[
|
|
128
|
+
`*.${(0, $ef5c629b17efc154$export$3e8733322718eb9)()}`
|
|
129
|
+
]
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
"enableCrossDomainLinking",
|
|
133
|
+
true
|
|
116
134
|
]
|
|
117
|
-
]
|
|
118
|
-
|
|
119
|
-
|
|
135
|
+
];
|
|
136
|
+
// Map keeps order of keys
|
|
137
|
+
const config = new Map();
|
|
138
|
+
for (const [key, value] of rawConfig)if (!config.has(key)) config.set(key, value);
|
|
139
|
+
window?._paq?.push(...Array.from(config.entries()).map(([key, value])=>{
|
|
140
|
+
switch(value){
|
|
141
|
+
case false:
|
|
142
|
+
return false;
|
|
143
|
+
case true:
|
|
144
|
+
case undefined:
|
|
145
|
+
return [
|
|
146
|
+
key
|
|
147
|
+
];
|
|
148
|
+
default:
|
|
149
|
+
return [
|
|
150
|
+
key,
|
|
151
|
+
value
|
|
152
|
+
];
|
|
153
|
+
}
|
|
154
|
+
}).filter((item)=>item !== false));
|
|
120
155
|
$8ec118068c18cb0c$var$injectMatomoScript(_matomoHost);
|
|
121
156
|
};
|
|
122
157
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEGO,MAAM,4CAA2B;AACjC,MAAM,4CAA0B;AAEhC,MAAM,4CAAsB;IACjC;IACA;CACD;AAEM,MAAM,4CAAkB;IAC7B,OAAO,OAAO,WAAW,eAAe,OAAO,SAAS;AAC1D;AAEA,MAAM,uDAAiC,CAAC;IACtC,MAAM,eAAe;IAErB,IAAI,OAAO,WAAW,aACpB,OAAO;IAGT,MAAM,gBAAgB,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,QAAQ,CAAC;IACtD,OAAO,AAAC,SAAS,OAAO,MAAM,gBAAgB,CAAC,EAAE,IAAe;AAClE;AAEO,MAAM,4CAAqB;IAChC,IAAI,OAAO,WAAW,aACpB,OAAO;IAGT,KAAK,MAAM,OAAO,0CAAqB;QACrC,MAAM,cAAc,qDAA+B;QACnD,MAAM,gBAAgB,CAAC,CAAE,CAAA,eAAe,gBAAgB,yCAAuB;QAE/E,IAAI,eACF,OAAO;IAEX;IAEA,OAAO;AACT;AAEO,MAAM,4CAAa,CAAC,WAAmB,GAAG;IAC/C,IAAI,CAAC,6CACH,CAAA,GAAA,yCAAS;IAGX,IAAI,OAAO,WAAW,eAAe,CAAC,6CACpC;IAGF,QAAQ,MAAM,KAAK;QAAC;W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IAAI,UACzB,IAAI,CAAC,OAAO,IAAI,MACd,OAAO,IAAI,KAAK;IAIpB,QAAQ,MAAM,QACT,MAAM,KAAK,OAAO,WAClB,IAAI,CAAC,CAAC,KAAK,MAAM;QAChB,OAAQ;YACN,KAAK;gBACH,OAAO;YACT,KAAK;YACL,KAAK;gBACH,OAAO;oBAAC;iBAAI;YACd;gBACE,OAAO;oBAAC;oBAAK;iBAAM;QACvB;IACF,GACC,OAAO,CAAC,OAAyC,SAAS;IAG/D,yCAAmB;AACrB;;;;;;;;;;AGzFO,MAAM,4CAAqB,CAAyB,OAA+B,KACxF,QACI,CAAC,GAAG;QACF,CAAA,GAAA,yCAAS,EAAE,iBAAiB;QAC5B,OAAO,QAAQ;IACjB,IACA;;;;AJFN,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 type MatomoConfig = Array<[string, ...unknown[]]>\n\nexport const initMatomo = (matomoHost?: string, customConfig: MatomoConfig = []): 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 const rawConfig = [\n // These are hardcoded values and cannot be changed\n ['setTrackerUrl', new URL('/matomo.php', _matomoHost).href],\n ['requireCookieConsent', true],\n\n // These are custom settings\n ...customConfig,\n\n // These are default settings, will be overwritten if custom set\n ['trackPageView', true],\n ['enableLinkTracking', true],\n ['setSiteId', '1'],\n ['setDomains', [`*.${getDomain()}`]],\n ['enableCrossDomainLinking', true],\n ]\n\n // Map keeps order of keys\n const config = new Map()\n for (const [key, value] of rawConfig) {\n if (!config.has(key)) {\n config.set(key, value)\n }\n }\n\n window?._paq?.push(\n ...Array.from(config.entries())\n .map(([key, value]) => {\n switch (value) {\n case false:\n return false\n case true:\n case undefined:\n return [key]\n default:\n return [key, value]\n }\n })\n .filter((item): item is [string, ...unknown[]] => item !== false),\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.d.ts
CHANGED
|
@@ -16,7 +16,8 @@ declare global {
|
|
|
16
16
|
} & Record<string | number | symbol, unknown>;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
export
|
|
19
|
+
export type MatomoConfig = Array<[string, ...unknown[]]>;
|
|
20
|
+
export const initMatomo: (matomoHost?: string, customConfig?: MatomoConfig) => void;
|
|
20
21
|
export const wrapWithEventTrack: <A extends unknown[], R>(event: MatomoEventType | void, fn: (...args: A) => R) => (...args: A) => R;
|
|
21
22
|
|
|
22
23
|
//# 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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AAM,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,2BAA2B,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAA;AAExD,OAAO,MAAM,0BAA2B,MAAM,kCAAoC,IAoEjF,CAAA;ACzFD,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
|
@@ -68,7 +68,7 @@ const $76adf94c93f4a7f4$var$injectMatomoScript = (matomoHost)=>{
|
|
|
68
68
|
src: new URL("/matomo.js", matomoHost).href
|
|
69
69
|
}));
|
|
70
70
|
};
|
|
71
|
-
const $76adf94c93f4a7f4$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
71
|
+
const $76adf94c93f4a7f4$export$6ec25100f86fa29d = (matomoHost, customConfig = [])=>{
|
|
72
72
|
if (typeof window === "undefined") // SSR not supported!
|
|
73
73
|
return;
|
|
74
74
|
if (!(0, $427566b8f1d3367d$export$83c2c3def90d3b5a)()) {
|
|
@@ -81,26 +81,61 @@ const $76adf94c93f4a7f4$export$6ec25100f86fa29d = (matomoHost)=>{
|
|
|
81
81
|
if (window._paq) // window._paq has been initialized
|
|
82
82
|
return;
|
|
83
83
|
window._paq ??= [];
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
const rawConfig = [
|
|
85
|
+
// These are hardcoded values and cannot be changed
|
|
86
|
+
[
|
|
87
|
+
"setTrackerUrl",
|
|
88
|
+
new URL("/matomo.php", _matomoHost).href
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
"requireCookieConsent",
|
|
92
|
+
true
|
|
93
|
+
],
|
|
94
|
+
// These are custom settings
|
|
95
|
+
...customConfig,
|
|
96
|
+
// These are default settings, will be overwritten if custom set
|
|
97
|
+
[
|
|
98
|
+
"trackPageView",
|
|
99
|
+
true
|
|
100
|
+
],
|
|
98
101
|
[
|
|
99
|
-
|
|
102
|
+
"enableLinkTracking",
|
|
103
|
+
true
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"setSiteId",
|
|
107
|
+
"1"
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
"setDomains",
|
|
111
|
+
[
|
|
112
|
+
`*.${(0, $427566b8f1d3367d$export$3e8733322718eb9)()}`
|
|
113
|
+
]
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
"enableCrossDomainLinking",
|
|
117
|
+
true
|
|
100
118
|
]
|
|
101
|
-
]
|
|
102
|
-
|
|
103
|
-
|
|
119
|
+
];
|
|
120
|
+
// Map keeps order of keys
|
|
121
|
+
const config = new Map();
|
|
122
|
+
for (const [key, value] of rawConfig)if (!config.has(key)) config.set(key, value);
|
|
123
|
+
window?._paq?.push(...Array.from(config.entries()).map(([key, value])=>{
|
|
124
|
+
switch(value){
|
|
125
|
+
case false:
|
|
126
|
+
return false;
|
|
127
|
+
case true:
|
|
128
|
+
case undefined:
|
|
129
|
+
return [
|
|
130
|
+
key
|
|
131
|
+
];
|
|
132
|
+
default:
|
|
133
|
+
return [
|
|
134
|
+
key,
|
|
135
|
+
value
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
}).filter((item)=>item !== false));
|
|
104
139
|
$76adf94c93f4a7f4$var$injectMatomoScript(_matomoHost);
|
|
105
140
|
};
|
|
106
141
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;AEGO,MAAM,4CAA2B;AACjC,MAAM,4CAA0B;AAEhC,MAAM,4CAAsB;IACjC;IACA;CACD;AAEM,MAAM,4CAAkB;IAC7B,OAAO,OAAO,WAAW,eAAe,OAAO,SAAS;AAC1D;AAEA,MAAM,uDAAiC,CAAC;IACtC,MAAM,eAAe;IAErB,IAAI,OAAO,WAAW,aACpB,OAAO;IAGT,MAAM,gBAAgB,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,QAAQ,CAAC;IACtD,OAAO,AAAC,SAAS,OAAO,MAAM,gBAAgB,CAAC,EAAE,IAAe;AAClE;AAEO,MAAM,4CAAqB;IAChC,IAAI,OAAO,WAAW,aACpB,OAAO;IAGT,KAAK,MAAM,OAAO,0CAAqB;QACrC,MAAM,cAAc,qDAA+B;QACnD,MAAM,gBAAgB,CAAC,CAAE,CAAA,eAAe,gBAAgB,yCAAuB;QAE/E,IAAI,eACF,OAAO;IAEX;IAEA,OAAO;AACT;AAEO,MAAM,4CAAa,CAAC,WAAmB,GAAG;IAC/C,IAAI,CAAC,6CACH,CAAA,GAAA,yCAAS;IAGX,IAAI,OAAO,WAAW,eAAe,CAAC,6CACpC;IAGF,QAAQ,MAAM,KAAK;QAAC;WAAc;KAAK;AACzC;AAEO,MAAM,4CAAa,CAAC,GAAG;IAC5B,0CAAW,iBAAiB;AAC9B;AAEO,MAAM,4CAAiC,CAAC,gBAAgB,IAAI,EAAE,mBAAmB,GAAG;IACzF,0CAAW,kCAAkC,eAAe;AAC9D;AAEO,MAAM,2CAAY;IACvB,OAAO,SAAS,SAAS,MA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oBAAC;oBAAK;iBAAM;QACvB;IACF,GACC,OAAO,CAAC,OAAyC,SAAS;IAG/D,yCAAmB;AACrB;;;;;;;;;;AGzFO,MAAM,4CAAqB,CAAyB,OAA+B,KACxF,QACI,CAAC,GAAG;QACF,CAAA,GAAA,yCAAS,EAAE,iBAAiB;QAC5B,OAAO,QAAQ;IACjB,IACA;;;;AJFN,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 type MatomoConfig = Array<[string, ...unknown[]]>\n\nexport const initMatomo = (matomoHost?: string, customConfig: MatomoConfig = []): 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 const rawConfig = [\n // These are hardcoded values and cannot be changed\n ['setTrackerUrl', new URL('/matomo.php', _matomoHost).href],\n ['requireCookieConsent', true],\n\n // These are custom settings\n ...customConfig,\n\n // These are default settings, will be overwritten if custom set\n ['trackPageView', true],\n ['enableLinkTracking', true],\n ['setSiteId', '1'],\n ['setDomains', [`*.${getDomain()}`]],\n ['enableCrossDomainLinking', true],\n ]\n\n // Map keeps order of keys\n const config = new Map()\n for (const [key, value] of rawConfig) {\n if (!config.has(key)) {\n config.set(key, value)\n }\n }\n\n window?._paq?.push(\n ...Array.from(config.entries())\n .map(([key, value]) => {\n switch (value) {\n case false:\n return false\n case true:\n case undefined:\n return [key]\n default:\n return [key, value]\n }\n })\n .filter((item): item is [string, ...unknown[]] => item !== false),\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.33.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.33.0",
|
|
28
28
|
"@types/jest": "^29.2.4",
|
|
29
29
|
"jest": "^29.3.1",
|
|
30
30
|
"ts-jest": "^29.0.3",
|