@lidofinance/analytics-matomo 0.51.0 → 0.52.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 CHANGED
@@ -24,6 +24,7 @@ var $ef5c629b17efc154$exports = {};
24
24
 
25
25
  $parcel$export($ef5c629b17efc154$exports, "COOKIE_ALLOWED_VALUE_YES", function () { return $ef5c629b17efc154$export$69479293c4b47320; });
26
26
  $parcel$export($ef5c629b17efc154$exports, "COOKIE_ALLOWED_MAIN_KEY", function () { return $ef5c629b17efc154$export$ed61d9b9718a39c9; });
27
+ $parcel$export($ef5c629b17efc154$exports, "META_INFO_COOKIE", function () { return $ef5c629b17efc154$export$506bf4ed084a716; });
27
28
  $parcel$export($ef5c629b17efc154$exports, "COOKIE_ALLOWED_KEYS", function () { return $ef5c629b17efc154$export$7567476bb64c3721; });
28
29
  $parcel$export($ef5c629b17efc154$exports, "matomoAvailable", function () { return $ef5c629b17efc154$export$e5ed1c22a80aba4b; });
29
30
  $parcel$export($ef5c629b17efc154$exports, "checkCookieAllowed", function () { return $ef5c629b17efc154$export$83c2c3def90d3b5a; });
@@ -34,6 +35,7 @@ $parcel$export($ef5c629b17efc154$exports, "getDomain", function () { return $ef5
34
35
 
35
36
  const $ef5c629b17efc154$export$69479293c4b47320 = "yes";
36
37
  const $ef5c629b17efc154$export$ed61d9b9718a39c9 = "cookie-allowed";
38
+ const $ef5c629b17efc154$export$506bf4ed084a716 = "meta-info";
37
39
  const $ef5c629b17efc154$export$7567476bb64c3721 = [
38
40
  "LIDO_WIDGET__COOKIES_ALLOWED",
39
41
  $ef5c629b17efc154$export$ed61d9b9718a39c9
@@ -59,6 +61,12 @@ const $ef5c629b17efc154$export$83c2c3def90d3b5a = ()=>{
59
61
  const $ef5c629b17efc154$export$cecaccc605742066 = (apiMethod, ...args)=>{
60
62
  if (!$ef5c629b17efc154$export$e5ed1c22a80aba4b()) (0, $8ec118068c18cb0c$export$6ec25100f86fa29d)();
61
63
  if (typeof window === "undefined" || !$ef5c629b17efc154$export$83c2c3def90d3b5a()) return;
64
+ const customDimensionValue = $ef5c629b17efc154$var$getCrossDomainCookieClientSide($ef5c629b17efc154$export$506bf4ed084a716) || "none";
65
+ window?._paq?.push([
66
+ "setCustomDimension",
67
+ 1,
68
+ customDimensionValue
69
+ ]);
62
70
  window?._paq?.push([
63
71
  apiMethod,
64
72
  ...args
@@ -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,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ACzB,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;;;;;;;;;;AGzHO,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 /**\n * # How to update matomo\n *\n * To safely update Matomo without analytics downtime:\n *\n * 1. Download the new Matomo version zip from https://github.com/matomo-org/matomo/releases\n * 2. Extract matomo.js from the zip archive\n * 3. Generate integrity checksum:\n * - Run: `cat matomo.js | openssl dgst -sha384 -binary | openssl base64 -A`\n * - Add 'sha384-' prefix to the generated hash\n * 4. Add the new integrity hash to the array below (keep the old one)\n * 5. Release this package and update all dependent repositories\n *\n * Notes:\n * - The script will automatically use the matching integrity hash\n * - Old integrity values can be safely removed later if desired\n * - No console errors will occur during the transition\n * - This approach ensures zero analytics downtime during updates\n */\n document.documentElement.appendChild(\n Object.assign(document.createElement('script'), {\n async: true,\n src: new URL('/matomo.js', matomoHost).href,\n crossOrigin: 'anonymous',\n /**\n * To generate checksum:\n * 1. Download matomo.js via `curl -O https://matomo.lido.fi/matomo.js`\n * 2. Calculate checkusm via `cat matomo.js | openssl dgst -sha384 -binary | openssl base64 -A`\n * 3. Add sha384 prefix\n * For other options see https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity#tools_for_generating_sri_hashes\n */\n integrity: [\n 'sha384-zEaC37u+jplyCMnmF4H7LxCC9kIFKvwV32PWyiLIIIUVOrm1W8+ljIA2kUa/cTHa', // Matomo v 5.2.0 && Matomo v 5.2.2\n ].join(' '),\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 // Add subdomain prefix to page titles to separate analytics by subdomain\n ['setDocumentTitle', window.location.hostname + '/' + (document.title || '')],\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"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEGO,MAAM,4CAA2B;AACjC,MAAM,4CAA0B;AAChC,MAAM,2CAAmB;AAEzB,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,MAAM,uBAAuB,qDAA+B,6CAAqB;IACjF,QAAQ,MAAM,KAAK;QAAC;QAAsB;QAAG;KAAqB;IAElE,QAAQ,MAAM,KAAK;QAAC;WAAc;KAAK;AACzC;AAEO,MAAM,4CAAa,CAAC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ACpC;YAAC;YAA4B;SAAK;KACnC;IAED,0BAA0B;IAC1B,MAAM,SAAS,IAAI;IACnB,KAAK,MAAM,CAAC,KAAK,MAAM,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;;;;;;;;;;AGzHO,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 /**\n * # How to update matomo\n *\n * To safely update Matomo without analytics downtime:\n *\n * 1. Download the new Matomo version zip from https://github.com/matomo-org/matomo/releases\n * 2. Extract matomo.js from the zip archive\n * 3. Generate integrity checksum:\n * - Run: `cat matomo.js | openssl dgst -sha384 -binary | openssl base64 -A`\n * - Add 'sha384-' prefix to the generated hash\n * 4. Add the new integrity hash to the array below (keep the old one)\n * 5. Release this package and update all dependent repositories\n *\n * Notes:\n * - The script will automatically use the matching integrity hash\n * - Old integrity values can be safely removed later if desired\n * - No console errors will occur during the transition\n * - This approach ensures zero analytics downtime during updates\n */\n document.documentElement.appendChild(\n Object.assign(document.createElement('script'), {\n async: true,\n src: new URL('/matomo.js', matomoHost).href,\n crossOrigin: 'anonymous',\n /**\n * To generate checksum:\n * 1. Download matomo.js via `curl -O https://matomo.lido.fi/matomo.js`\n * 2. Calculate checkusm via `cat matomo.js | openssl dgst -sha384 -binary | openssl base64 -A`\n * 3. Add sha384 prefix\n * For other options see https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity#tools_for_generating_sri_hashes\n */\n integrity: [\n 'sha384-zEaC37u+jplyCMnmF4H7LxCC9kIFKvwV32PWyiLIIIUVOrm1W8+ljIA2kUa/cTHa', // Matomo v 5.2.0 && Matomo v 5.2.2\n ].join(' '),\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 // Add subdomain prefix to page titles to separate analytics by subdomain\n ['setDocumentTitle', window.location.hostname + '/' + (document.title || '')],\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 { initMatomo } from './init'\nimport { MatomoEventType } from './type'\n\nexport const COOKIE_ALLOWED_VALUE_YES = 'yes'\nexport const COOKIE_ALLOWED_MAIN_KEY = 'cookie-allowed'\nexport const META_INFO_COOKIE = 'meta-info'\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 const customDimensionValue = getCrossDomainCookieClientSide(META_INFO_COOKIE) || 'none'\n window?._paq?.push(['setCustomDimension', 1, customDimensionValue])\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
@@ -1,6 +1,7 @@
1
1
  export type MatomoEventType = [category: string, action: string, name: string];
2
2
  export const COOKIE_ALLOWED_VALUE_YES = "yes";
3
3
  export const COOKIE_ALLOWED_MAIN_KEY = "cookie-allowed";
4
+ export const META_INFO_COOKIE = "meta-info";
4
5
  export const COOKIE_ALLOWED_KEYS: string[];
5
6
  export const matomoAvailable: () => boolean;
6
7
  export const checkCookieAllowed: () => boolean;
@@ -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;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,wFAAiF,IAE7F,CAAA;AAED,OAAO,MAAM,uBAEZ,CAAA;AC/DD,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;AA6CD,2BAA2B,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAA;AAExD,OAAO,MAAM,0BAA2B,MAAM,kCAAoC,IAsEjF,CAAA;ACzHD,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"}
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;AACvD,OAAO,MAAM,8BAA8B,CAAA;AAE3C,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,IAalE,CAAA;AAED,OAAO,MAAM,gEAA0C,IAEtD,CAAA;AAED,OAAO,MAAM,wFAAiF,IAE7F,CAAA;AAED,OAAO,MAAM,uBAEZ,CAAA;ACnED,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;AA6CD,2BAA2B,KAAK,CAAC,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAA;AAExD,OAAO,MAAM,0BAA2B,MAAM,kCAAoC,IAsEjF,CAAA;ACzHD,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
@@ -8,6 +8,7 @@ var $427566b8f1d3367d$exports = {};
8
8
 
9
9
  $parcel$export($427566b8f1d3367d$exports, "COOKIE_ALLOWED_VALUE_YES", function () { return $427566b8f1d3367d$export$69479293c4b47320; });
10
10
  $parcel$export($427566b8f1d3367d$exports, "COOKIE_ALLOWED_MAIN_KEY", function () { return $427566b8f1d3367d$export$ed61d9b9718a39c9; });
11
+ $parcel$export($427566b8f1d3367d$exports, "META_INFO_COOKIE", function () { return $427566b8f1d3367d$export$506bf4ed084a716; });
11
12
  $parcel$export($427566b8f1d3367d$exports, "COOKIE_ALLOWED_KEYS", function () { return $427566b8f1d3367d$export$7567476bb64c3721; });
12
13
  $parcel$export($427566b8f1d3367d$exports, "matomoAvailable", function () { return $427566b8f1d3367d$export$e5ed1c22a80aba4b; });
13
14
  $parcel$export($427566b8f1d3367d$exports, "checkCookieAllowed", function () { return $427566b8f1d3367d$export$83c2c3def90d3b5a; });
@@ -18,6 +19,7 @@ $parcel$export($427566b8f1d3367d$exports, "getDomain", function () { return $427
18
19
 
19
20
  const $427566b8f1d3367d$export$69479293c4b47320 = "yes";
20
21
  const $427566b8f1d3367d$export$ed61d9b9718a39c9 = "cookie-allowed";
22
+ const $427566b8f1d3367d$export$506bf4ed084a716 = "meta-info";
21
23
  const $427566b8f1d3367d$export$7567476bb64c3721 = [
22
24
  "LIDO_WIDGET__COOKIES_ALLOWED",
23
25
  $427566b8f1d3367d$export$ed61d9b9718a39c9
@@ -43,6 +45,12 @@ const $427566b8f1d3367d$export$83c2c3def90d3b5a = ()=>{
43
45
  const $427566b8f1d3367d$export$cecaccc605742066 = (apiMethod, ...args)=>{
44
46
  if (!$427566b8f1d3367d$export$e5ed1c22a80aba4b()) (0, $76adf94c93f4a7f4$export$6ec25100f86fa29d)();
45
47
  if (typeof window === "undefined" || !$427566b8f1d3367d$export$83c2c3def90d3b5a()) return;
48
+ const customDimensionValue = $427566b8f1d3367d$var$getCrossDomainCookieClientSide($427566b8f1d3367d$export$506bf4ed084a716) || "none";
49
+ window?._paq?.push([
50
+ "setCustomDimension",
51
+ 1,
52
+ customDimensionValue
53
+ ]);
46
54
  window?._paq?.push([
47
55
  apiMethod,
48
56
  ...args
@@ -191,5 +199,5 @@ const $dfa3db2a6cffa71c$export$e8f57ad64147d191 = (event, fn)=>event ? (...args)
191
199
  (0, $76adf94c93f4a7f4$export$6ec25100f86fa29d)();
192
200
 
193
201
 
194
- 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$40aa6af9e848a6e0 as trackVisibleContentImpressions, $427566b8f1d3367d$export$3e8733322718eb9 as getDomain};
202
+ 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$506bf4ed084a716 as META_INFO_COOKIE, $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$40aa6af9e848a6e0 as trackVisibleContentImpressions, $427566b8f1d3367d$export$3e8733322718eb9 as getDomain};
195
203
  //# sourceMappingURL=index.mjs.map
@@ -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,IAA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ics/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 /**\n * # How to update matomo\n *\n * To safely update Matomo without analytics downtime:\n *\n * 1. Download the new Matomo version zip from https://github.com/matomo-org/matomo/releases\n * 2. Extract matomo.js from the zip archive\n * 3. Generate integrity checksum:\n * - Run: `cat matomo.js | openssl dgst -sha384 -binary | openssl base64 -A`\n * - Add 'sha384-' prefix to the generated hash\n * 4. Add the new integrity hash to the array below (keep the old one)\n * 5. Release this package and update all dependent repositories\n *\n * Notes:\n * - The script will automatically use the matching integrity hash\n * - Old integrity values can be safely removed later if desired\n * - No console errors will occur during the transition\n * - This approach ensures zero analytics downtime during updates\n */\n document.documentElement.appendChild(\n Object.assign(document.createElement('script'), {\n async: true,\n src: new URL('/matomo.js', matomoHost).href,\n crossOrigin: 'anonymous',\n /**\n * To generate checksum:\n * 1. Download matomo.js via `curl -O https://matomo.lido.fi/matomo.js`\n * 2. Calculate checkusm via `cat matomo.js | openssl dgst -sha384 -binary | openssl base64 -A`\n * 3. Add sha384 prefix\n * For other options see https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity#tools_for_generating_sri_hashes\n */\n integrity: [\n 'sha384-zEaC37u+jplyCMnmF4H7LxCC9kIFKvwV32PWyiLIIIUVOrm1W8+ljIA2kUa/cTHa', // Matomo v 5.2.0 && Matomo v 5.2.2\n ].join(' '),\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 // Add subdomain prefix to page titles to separate analytics by subdomain\n ['setDocumentTitle', window.location.hostname + '/' + (document.title || '')],\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"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;AEGO,MAAM,4CAA2B;AACjC,MAAM,4CAA0B;AAChC,MAAM,2CAAmB;AAEzB,MAAM,4CAAsB;IACjC;IACA;CACD;AAEM,MAAM,4CAAkB;IAC7B,OAAO,OAAO,WAAW,eAAe,OAAO,SAAS;AAC1D;AAEA,MAAM,uDAAiC,CAAC;IACtC,MAAM,eAAe;IAErB,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AAQ;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 /**\n * # How to update matomo\n *\n * To safely update Matomo without analytics downtime:\n *\n * 1. Download the new Matomo version zip from https://github.com/matomo-org/matomo/releases\n * 2. Extract matomo.js from the zip archive\n * 3. Generate integrity checksum:\n * - Run: `cat matomo.js | openssl dgst -sha384 -binary | openssl base64 -A`\n * - Add 'sha384-' prefix to the generated hash\n * 4. Add the new integrity hash to the array below (keep the old one)\n * 5. Release this package and update all dependent repositories\n *\n * Notes:\n * - The script will automatically use the matching integrity hash\n * - Old integrity values can be safely removed later if desired\n * - No console errors will occur during the transition\n * - This approach ensures zero analytics downtime during updates\n */\n document.documentElement.appendChild(\n Object.assign(document.createElement('script'), {\n async: true,\n src: new URL('/matomo.js', matomoHost).href,\n crossOrigin: 'anonymous',\n /**\n * To generate checksum:\n * 1. Download matomo.js via `curl -O https://matomo.lido.fi/matomo.js`\n * 2. Calculate checkusm via `cat matomo.js | openssl dgst -sha384 -binary | openssl base64 -A`\n * 3. Add sha384 prefix\n * For other options see https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity#tools_for_generating_sri_hashes\n */\n integrity: [\n 'sha384-zEaC37u+jplyCMnmF4H7LxCC9kIFKvwV32PWyiLIIIUVOrm1W8+ljIA2kUa/cTHa', // Matomo v 5.2.0 && Matomo v 5.2.2\n ].join(' '),\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 // Add subdomain prefix to page titles to separate analytics by subdomain\n ['setDocumentTitle', window.location.hostname + '/' + (document.title || '')],\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 { initMatomo } from './init'\nimport { MatomoEventType } from './type'\n\nexport const COOKIE_ALLOWED_VALUE_YES = 'yes'\nexport const COOKIE_ALLOWED_MAIN_KEY = 'cookie-allowed'\nexport const META_INFO_COOKIE = 'meta-info'\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 const customDimensionValue = getCrossDomainCookieClientSide(META_INFO_COOKIE) || 'none'\n window?._paq?.push(['setCustomDimension', 1, customDimensionValue])\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
@@ -7,7 +7,7 @@
7
7
  "url": "https://github.com/lidofinance/warehouse/issues"
8
8
  },
9
9
  "license": "MIT",
10
- "version": "0.51.0",
10
+ "version": "0.52.0",
11
11
  "files": [
12
12
  "dist"
13
13
  ],
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "peerDependencies": {},
36
36
  "devDependencies": {
37
- "@lidofinance/config-prettier": "~0.51.0",
37
+ "@lidofinance/config-prettier": "~0.52.0",
38
38
  "@types/jest": "^29.2.4",
39
39
  "jest": "^29.3.1",
40
40
  "jest-environment-jsdom": "^28.0.0",