Tracking Code for Using Multiple Piwik Trackers


#1

Hi,

I’ve checked out JavaScript Tracking Client: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 and wanted to clarify ‘exactly’ how my code should look to ensure both of the trackers are set up correctly.

Do I only need to use this code:


<script type="text/javascript">

window.piwikAsyncInit = function () {
    try {
        var piwikTracker = Piwik.getTracker("http://subdomain.URL_1/", 1);
        piwikTracker.trackPageView();
        var piwik2 = Piwik.getTracker("http://subdomain.URL_2/", 4);
        piwik2.trackPageView();
    } catch( err ) {}
};

</script>

or do I need to include this somehow within the javascript tracking code that Piwik generates via Settings/tracking area?

thanks for any help solving this.

Paul


#2

+1!

Please answer!


(Matthieu Aubry) #3

@Paul your code looks good!