From cac84c148fed03a0074e0804d901f8abb0faea6e Mon Sep 17 00:00:00 2001 From: Tiberiu Ichim Date: Wed, 2 Dec 2020 19:17:13 +0200 Subject: [PATCH] Take matomo site id into consideration --- src/utils.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/utils.js b/src/utils.js index 019a898..ed07705 100644 --- a/src/utils.js +++ b/src/utils.js @@ -12,21 +12,26 @@ const _matomo = {}; const doWithMatomo = (fn) => { if (__CLIENT__) { if (!_matomo.instance) { - const siteId = - window.env?.RAZZLE_MATOMO_SITE_ID || settings.matomoSiteId || 1; + const siteId = window.env?.RAZZLE_MATOMO_SITE_ID || settings.matomoSiteId; const urlBase = window.env?.RAZZLE_MATOMO_URL || settings.matomoUrlBase || 'https://matomo.eea.europa.eu/'; - _matomo.instance = createInstance({ - urlBase, - siteId, - }); + if (siteId) { + _matomo.instance = createInstance({ + urlBase, + siteId, + }); + } else { + console.warn( + 'Matomo SiteID is not defined, page actions will not be tracked', + ); + } } - fn(_matomo.instance); + if (_matomo.instance) fn(_matomo.instance); } };