From c13c2c90bb8ea9cfb528eb65cf2a03e410995855 Mon Sep 17 00:00:00 2001 From: Alin Voinea Date: Fri, 24 Feb 2023 11:11:26 +0200 Subject: [PATCH 1/2] fix(secondMatomoId): Use matomo addTracker for second id - refs #249086 --- README.md | 2 +- src/utils.js | 64 +++++++++++++++++++++------------------------------- 2 files changed, 27 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 8ea9794..1a15242 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ The default behavior of volto-matomo is a call to `trackPageView` in `utils.js`, ], "dependencies": { - "@eeacms/volto-matomo": "4.0.0" + "@eeacms/volto-matomo": "*" } ``` diff --git a/src/utils.js b/src/utils.js index 5d26004..ebb51c8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -11,7 +11,7 @@ const _matomo = {}; const doWithMatomo = (fn) => { if (__SERVER__) return; - if (!(_matomo.instance1 || _matomo.instance2)) { + if (!_matomo.instance) { const siteId = window.env?.RAZZLE_MATOMO_SITE_ID || config.settings.matomoSiteId; @@ -42,37 +42,27 @@ const doWithMatomo = (fn) => { config.settings.matomoSecondUrlBase || urlBase; - const secondUserId = - window.env?.RAZZLE_MATOMO_SECOND_USER_ID || - config.settings.matomoSecondUserId || - userId; + // const secondUserId = + // window.env?.RAZZLE_MATOMO_SECOND_USER_ID || + // config.settings.matomoSecondUserId || + // userId; const secondTrackerUrl = window.env?.RAZZLE_MATOMO_SECOND_TRACKER_URL || config.settings.matomoSecondTrackerUrl || - trackerUrl; + `${secondUrlBase}matomo.php`; - const secondSrcUrl = - window.env?.RAZZLE_MATOMO_SECOND_SRC_URL || - config.settings.matomoSecondSrcUrl || - srcUrl; - - if (!(siteId || secondSiteId)) { - if (window.console) { - /* eslint-disable-next-line */ - console.warn( - 'Matomo SiteID is not defined, page actions will not be tracked', - ); - } - return; - } + // const secondSrcUrl = + // window.env?.RAZZLE_MATOMO_SECOND_SRC_URL || + // config.settings.matomoSecondSrcUrl || + // srcUrl; if (siteId) { /** * NOTE: check this link to see all the available options * https://www.npmjs.com/package/@datapunt/matomo-tracker-react */ - _matomo.instance1 = createInstance({ + _matomo.instance = createInstance({ urlBase, siteId, userId, @@ -81,27 +71,25 @@ const doWithMatomo = (fn) => { // Add your own configuration ...(config.settings.matomo || {}), }); - } - if (secondSiteId) { - /** - * NOTE: check this link to see all the available options - * https://www.npmjs.com/package/@datapunt/matomo-tracker-react - */ - _matomo.instance2 = createInstance({ - urlBase: secondUrlBase, - siteId: secondSiteId, - userId: secondUserId, - trackerUrl: secondTrackerUrl, - srcUrl: secondSrcUrl, - // Add your own configuration - ...(config.settings.matomo || {}), - }); + if (secondSiteId) { + _matomo.instance.pushInstruction( + 'addTracker', + secondTrackerUrl, + secondSiteId, + ); + } + } else { + if (window.console) { + /* eslint-disable-next-line */ + console.warn( + 'Matomo SiteID is not defined, page actions will not be tracked', + ); + } } } - if (_matomo.instance1) fn(_matomo.instance1); - if (_matomo.instance2) fn(_matomo.instance2); + if (_matomo.instance) fn(_matomo.instance); }; export const trackPageView = ({ href, ...options }) => { From c7041e531c672e8d8ee3e1d746aba06558188319 Mon Sep 17 00:00:00 2001 From: EEA Jenkins <@users.noreply.github.com> Date: Fri, 24 Feb 2023 09:28:21 +0000 Subject: [PATCH 2/2] Automated release 4.0.2 --- CHANGELOG.md | 9 ++++++--- package.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2be0a50..56af2c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). -### [4.0.1](https://github.com/eea/volto-matomo/compare/4.0.0...4.0.1) - 23 February 2023 +### [4.0.2](https://github.com/eea/volto-matomo/compare/4.0.1...4.0.2) - 24 February 2023 -#### :hammer_and_wrench: Others +#### :bug: Bug Fixes + +- fix(secondMatomoId): Use matomo addTracker for second id - refs #249086 [Alin Voinea - [`c13c2c9`](https://github.com/eea/volto-matomo/commit/c13c2c90bb8ea9cfb528eb65cf2a03e410995855)] + +### [4.0.1](https://github.com/eea/volto-matomo/compare/4.0.0...4.0.1) - 23 February 2023 -- Fix createInstance params [Alin Voinea - [`6252cbb`](https://github.com/eea/volto-matomo/commit/6252cbb46f92bccec36c6315b1ea55a0e09fa955)] ## [4.0.0](https://github.com/eea/volto-matomo/compare/3.0.1...4.0.0) - 23 February 2023 #### :rocket: New Features diff --git a/package.json b/package.json index bdc55e3..1414c04 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eeacms/volto-matomo", - "version": "4.0.1", + "version": "4.0.2", "description": "volto-matomo: Volto add-on", "main": "src/index.js", "author": "European Environment Agency: IDM2 A-Team",