[4.1.1] XXX is registered more than once in "_paq" variable

Hey there,

since we upgraded from latest 3.x Version to 4.x Version we get those Errors on all of our Web-Pages:

The method requireCookieConsent is registered more than once in "_paq" variable. Only the last call has an effect. Please have a look at the multiple Matomo trackers documentation: https://developer.matomo.org/guides/tracking-javascript-guide#multiple-piwik-trackers matomo.js:12:287
The method setTrackerUrl is registered more than once in "_paq" variable. Only the last call has an effect. Please have a look at the multiple Matomo trackers documentation: https://developer.matomo.org/guides/tracking-javascript-guide#multiple-piwik-trackers matomo.js:12:287
The method setSiteId is registered more than once in "_paq" variable. Only the last call has an effect. Please have a look at the multiple Matomo trackers documentation: https://developer.matomo.org/guides/tracking-javascript-guide#multiple-piwik-trackers matomo.js:12:287
The method enableLinkTracking is registered more than once in "_paq" variable. Only the last call has an effect. Please have a look at the multiple Matomo trackers documentation: https://developer.matomo.org/guides/tracking-javascript-guide#multiple-piwik-trackers matomo.js:12:287

We have always used the “Alternative solution” mentioned in the Docs: https://developer.matomo.org/guides/tracking-javascript-guide#multiple-piwik-trackers
And it was always working as expected. It’s still working - but some of our Customers are unsettled because of those Warnings …

Example: https://www.futureweb.at/ (after accepting Cookie Consent … otherwise it won’t track)
Code:

<script data-type="application/javascript" data-name="matomo">
   var _paq = window._paq = window._paq || [];
   /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
   _paq.push(['requireCookieConsent']);
   _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
   _paq.push(['trackPageView']);
   _paq.push(['enableLinkTracking']);
   _paq.push(['enableHeartBeatTimer']);
   (function() {
     var u="https://stats.futureweb.at/";
     _paq.push(['setTrackerUrl', u+'matomo.php']);
     _paq.push(['setSiteId', '1']);
     _paq.push(['addTracker', piwikUrl = u+'matomo.php', 927]);                    
     var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
     g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
   })();
</script>
<noscript>
   <p><img src="https://stats.futureweb.at/matomo.php?idsite=1&rec=1" style="border:0;" alt="" /></p>
   <p><img src="https://stats.futureweb.at/matomo.php?idsite=927&rec=1" style="border:0;" alt="" /></p>
</noscript>

I guess this was changed in 4.x … but IMHO a Solution mentioned in the Docs should not throw Errors/Warnings?

Any idea how to disable those Warnings?

thx, bye from Austria
Andreas A.

Hi,

This seems like a bug, but I can’t reproduce this on a testpage (but I see the warnings on your site).

I created this HTML file

<!DOCTYPE html>
<html>
<head>
		<title>Index of /trackingtests/</title>
		<meta charset="utf-8" />
</head>
<body>
</body>



<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
		   _paq.push(['requireCookieConsent']);
   _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
   _paq.push(['trackPageView']);
   _paq.push(['enableLinkTracking']);
   _paq.push(['enableHeartBeatTimer']);
  (function() {
    var u="//dev.matomo/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
	  _paq.push(['addTracker', u+'matomo.php', 2]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

</html>

which should do the same as your site, but it works fine without any warning.

Completely unrelated, but your klaro_config.js.php?lang=de returns Javascript with a text/html mime type which might create some issues if you don’t fix it.

I think there is something really weird with your site where the script tag gets executed twice.

When I block the matomo.js from loading and after the pageload look what has been appended to _paq, I see everything twice:

console.log(_paq.join("\n"))
requireCookieConsent
setDocumentTitle,www.futureweb.at/Futureweb St. Johann in Tirol - gĂĽnstige Webseite - gĂĽnstige Homepage
trackPageView
enableLinkTracking
enableHeartBeatTimer
setTrackerUrl,https://stats.futureweb.at/matomo.php
setSiteId,1
addTracker,https://stats.futureweb.at/matomo.php,927
requireCookieConsent
setDocumentTitle,www.futureweb.at/Futureweb St. Johann in Tirol - gĂĽnstige Webseite - gĂĽnstige Homepage
trackPageView
enableLinkTracking
enableHeartBeatTimer
setTrackerUrl,https://stats.futureweb.at/matomo.php
setSiteId,1
addTracker,https://stats.futureweb.at/matomo.php,927
rememberCookieConsentGiven

I think Klaro (or your integration of it) is at fault.

https://kiprotect.com/docs/klaro/getting-started explains that you should add data-name="matomo" to the Matomo script tag so that Klaro knows it is Matomo (and probably executes it), but it also says you should set it to type="text/plain" so that the browser doesn’t execute it.

As you didn’t do the latter, your Matomo tracking code gets executed by the browser and afterwards by klaro.

1 Like

:roll_eyes: sorry for wasting your Time Lukas … guess I should have found this out by myself … :man_facepalming:

It just irritated me so much that it started exactly after the update … or maybe only noticed afterwards during testing …

Thank you for pointing me in the right Direction! :slight_smile:

1 Like