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


(Andreas Schnederle-Wagner) #1

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?

thx
Andreas Schnederle-Wagner


Rename "_paq" possible?
(Lukas Winkler) #2

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.


(Andreas Schnederle-Wagner) #3

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 … ?!


(Yann) #4

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 ?


(Andreas Schnederle-Wagner) #5

@Yann_Poirot - I wish it would be that easy … but it’s not working to simply rename “_paq” … see Testcase: http://in.futureweb.at/temp/matomo.php

only firing 1 PageView to the first defined Server …


(Yann) #6

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.setDocumentTitle('Viewer');
	tracker2.setDocumentTitle('Map');
	
    tracker1.trackPageView(); // only for Viewer tracker
	tracker2.trackPageView(); // only for Map tracker
    _paq.push(['trackPageView']) // both
}

(Andreas Schnederle-Wagner) #7

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?