We have seen issues where a client already is including Matomo (or older Piwik-versions) from a third party provider, and then they include our instance of Piwik/Matomo. Regular script-tag inclusion with your tags.
This non-encapsulation creates issues where they (kind of) override each other and results in crashes, especially if several different versions of Piwik/Matomo from different providers, is included where versions may differ.
How would we go about solving this issue; and encapsulating (namespacing?) one instance to not be able to get modified by other inclusions of the same software?
You want to track the same site into multiple matomo instances? Guess this post should help: https://matomo.org/blog/2017/02/complete-guide-tracking-websites-web-apps-multiple-piwiks-easily-efficiently/
I agree, you can find more about this idea here: https://forum.matomo.org/t/rename-paq-possible/27460
Thanks for sending those URLs, we've checked them earlier but together they may solve our requirements. We have checked it out previously but the issue in its core is that we have clients who from one agency include Piwik, and then they include our (other version) of Piwik; and then bad things happen. Especially if the previous included Piwik major version differs.
What exactly isn't working? I don't recall too many changes in the tracker or tracker API since the last major version.
The only problem I can see is that the
piwikPluginAsyncInit will be executed twice in this case which it actually very likely shouldn't. This is something that could be likely easily fixed but needs to be verified.
Otherwise depends how you embed the various trackers and how everything is defined. Likely the problem is really due to multiple
_paq overriding each other or so. In this case features like
addTracker etc would need to be used I suppose (if possible).
Really appreciate how helpful you are with this issue. And any further pointers in the right direction would be great. But we thought initially that it would be possible to just rename _paq-variable, or in any other way not reveal "our" version of the script to the outside world by variable scoping.
If we could easily rename piwik.js, and window.piwik (or the equivalent) and the _paq-variable it would be a godsend, but wouldn't really fix the issue for real.
The actual error is this:
And is caused when a client (such as a company) includes piwik/matomo (often different versions, maybe version 2 or version 3, etctera) from different agencies that help them with tracking.
setAccountId is not a method we have in our tracking code so that can't really work. Seems like they customize the tracking code which is not quite supported.
We faced a similar problem.
We have a tag tracker used by our clients which is using Piwik 2, and we use the
The site is using another tag based on Piwik 1 I think, not sure about the version but at least it is not providing
Their tag is loaded first so we are using their implementation of the global variable
Piwik (because Piwik client JS is checking variable existence before loading it) and it fails with
window.Piwik.addTracker is not a function error.
It would be great if we could easily rename, or even better, use a local variable scoped inside our tag, not shared with other third party tags.
I don't think renaming _paq would help much when using two different Piwik/Matomo versions when some methods aren't available. That's because once
window.Piwik is loaded, the 2nd file won't assign
window.Piwik again. A solution may be probably to limit the scope of
window.Piwik using modules or so.
I doubt we will be working on this here soon. I would highly! recommend to get the people to update their Piwik 1 and Piwik 2 to the latest Matomo for security purposes etc which fixes the problem as well but I understand you can't get other companies to do that...