Skip to content

Piwik JS Tracker: Easier way for using multiple trackers #9525

@tsteur

Description

@tsteur

For example in #9518 we had a case where two scripts declare a Piwik and overwrite each other. In http://developer.piwik.org/guides/tracking-javascript-guide#multiple-piwik-trackers we explain how to use multiple trackers eg by calling

var piwikTracker = Piwik.getTracker(12,  "http://example.com/piwik/" );
piwikTracker.trackPageView();

However, creating the tracker instance is not trivial and is a bit different from the standard async tracker. For example a developer would need to make sure to call methods on the tracker in this order to configure the tracker:

['disableCookies', 'setTrackerUrl', 'setAPIUrl', 'setCookiePath', 'setCookieDomain', 'setDomains', 'setUserId', 'setSiteId', 'enableLinkTracking'];

Otherwise there might be side effects. Also one would have to change all calls to Piwik tracker from say _paq.push(['trackPageView]) to if (piwikTracker) piwikTracker.trackPageView(); etc. which can be a lot of effort.

I wonder if there are easier ways. Eg could we maybe also provide a _paq2, _paq3, _paq4, ...?
We probably don't want to pollute the namespace so maybe we could do something like _paq2 =_paq.create() or paq2 = _paqCreate();. This way one could create unlimited _paq instances manually as needed. All a developer has to do afterwards is to replace _paq with _paq2 and one is done. The order of the applied methods that are applied would be the same as usual etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementFor new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.c: PlatformFor Matomo platform changes that aren't impacting any of our APIs but improve the core itself.c: UsabilityFor issues that let users achieve a defined goal more effectively or efficiently.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions