Multiple decoupled Matomo instances (rename '_paq', 'window.Piwik', ...)

Sometimes it’s needed to be able to completely decouple one Piwik instance from others on the same page … rename ‘_paq’, ‘window.Piwik’, … (For externally included JS Scripts which come with Piwik Tracking - to be sure not to collide with Piwik Instanced already present on Page)
Detailed explanation: Rename “_paq” possible?

Andreas Schnederle-Wagner

Just keep in mind that renaming _paq isn’t enough to decouple two Matomo scripts in one page.

At the very least window.Piwik will have to be renamed.

But probably there are still a lot of event listeners that will interfere.

thx for pointing out - rephrased initial post.
But I guess it won’t happen as it would produce a very a long rat tail to completely decouple instances … ?!

If you create an other instance of a PiwikTracker to send data you don’t have to use _paq variable normally, have you got an example of code ?

@Yann_Poirot - I wish it would be that easy … but it’s not working to simply rename “_paq” … see Testcase:

only firing 1 PageView to the first defined Server …

Use addTracker insteadOf getTracker it’s work very well :slight_smile:

window.piwikAsyncInit = function(){
   var tracker1 = Piwik.addTracker('url', id);
   var tracker2 = Piwik.addTracker('url', id);
    tracker1.trackPageView(); // only for Viewer tracker
	tracker2.trackPageView(); // only for Map tracker
    _paq.push(['trackPageView']) // both

haven’t found anything about addTracker in the Docs? --> JavaScript Tracking Client: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3

What’s the difference between addTracker and getTracker?