@dantracking opened this Issue on May 22nd 2019

when putting the tracking code [1] into files and placing it at the bottom or at the top
(within head part bevor tag [2]) of the website the FireFox browser is placing
a message/warning in the console (F12 inspector view).

"_paq.push() was used but Matomo tracker was not initialized before the matomo.js file was loaded.
Make sure to configure the tracker via _paq.push before loading matomo.js. Alternatively, you can
create a tracker..."

The message is not displayed all the time!
Its needed to reload the website in the browser (F5) a few times 5-6 to force this message.
When switching the position of 'tracking.js' and 'piwik.js' so that 'tracking.js' is loaded first,
it looks fine, so that there's no message appearing anymore.

Fail: If the 'piwik.js' is loaded fully first and then the 'tracking.js' the message appears.
OK : Otherwise if 'tracking.js' is finished loaded to be first and the 'piwik.js' no message appears.

Using Matomo 3.9.1
[1] https://matomo.org/faq/general/faq_20904/
[2] https://matomo.org/docs/installation/#install-the-javascript-tracking-tag

@fdellwing commented on May 22nd 2019 Contributor

I was just asking myself why anyone would load the piwik.js by himself, instead of doing this at the end of the tracking code. But than I saw that this is exactly how it is done in the FAQ.

I'm no CSP guru, but it is possible to load the piwik.js dynamically at the end of the tracking.js?

var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = u + 'piwik.js';
s.parentNode.insertBefore(g, s);
@tsteur commented on May 22nd 2019 Member

Not sure what the problem is here? If you load it differently, you just need to make sure to load it in the right order. That's what the message is telling you. Make sure the tracker is initialized before tracker is loaded. If there's any bug, I'm happy to reopen.

@dantracking commented on May 23rd 2019

When I am using the official method proposed in [1] the message occurs. So it seems to me that the published way [1] is not correct, isn't it ?

Of course I can change the order loading 'tracking.js' first but it would against your documentation [1].
Why you do not change the documentation on you website :o ?

@tsteur commented on May 23rd 2019 Member

I've inverted the order of the scripts so it should work?

@dantracking commented on May 23rd 2019

I quess this is the right way.
With loading 'tracking.js' first it works now in my case without message/warning.
Thanks so far.

This Issue was closed on May 22nd 2019
Powered by GitHub Issue Mirror