Skip to content

Commit

Permalink
Merge pull request #27 from eea/develop
Browse files Browse the repository at this point in the history
Release: Use matomo addTracker for second id - refs #249086
  • Loading branch information
avoinea authored Feb 24, 2023
2 parents 1d2d3cb + c7041e5 commit 3f1eea1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 43 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
}
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
64 changes: 26 additions & 38 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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 }) => {
Expand Down

0 comments on commit 3f1eea1

Please sign in to comment.