Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tsteur opened this issue Jan 14, 2016 · 8 comments
Closed

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

tsteur opened this issue Jan 14, 2016 · 8 comments
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. c: Usability For issues that let users achieve a defined goal more effectively or efficiently. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Milestone

Comments

@tsteur
Copy link
Member

tsteur commented Jan 14, 2016

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.

@tsteur tsteur added Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. c: Usability For issues that let users achieve a defined goal more effectively or efficiently. labels Jan 14, 2016
@RMastop
Copy link
Contributor

RMastop commented Jan 14, 2016

That would be an awesome improvement! Would both trackers register downloads, outlinks, etc?

@tsteur
Copy link
Member Author

tsteur commented Jan 14, 2016

Yes I'd say so but I'm not sure if there are any problems with it. I think it should work fine though

@ghost
Copy link

ghost commented Mar 22, 2016

So this is working is it?
How can I get the namespace in my tracker, for example, paq2 = _paqCreate(); to a particular tracker if I have 2 trackers. An example would be very helpful.

@tsteur tsteur added the c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. label Mar 28, 2016
@tsteur
Copy link
Member Author

tsteur commented Mar 28, 2016

@mattab
Copy link
Member

mattab commented Apr 21, 2016

PR in progress: #10085

@tsteur
Copy link
Member Author

tsteur commented Apr 21, 2016

BTW it is not 100% going to be solved by #10085. #10085 is only a solution if someone wants to 100% track the same data to both Piwik instances. If someone wants to track different data to different Piwiks a different solution is needed.

@ghost
Copy link

ghost commented Apr 21, 2016

Thanks.. Please keep me posted.

On 21 April 2016 at 06:34, Thomas Steur notifications@github.com wrote:

BTW is not 100% going to be solved by #10085
#10085. #10085
#10085 is only a solution if someone
wants to 100% track the same data to both Piwik instances. If someone wants
to track different data to different Piwiks a different solution is needed.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#9525 (comment)

Best regards,

Meghashri Kirani
Technical analyst

ABOUT YOU GmbH
Domstraße 10
20095 Hamburg

@sebastianpiskorski
Copy link
Contributor

@tsteur I would consider also a scenario where somebody uses two Piwik.js scripts from different versions. There is namespace conflict in such situation because all is stored in global Piwik object.

@mattab mattab modified the milestones: 2.16.2, 2.16.x (LTS) May 23, 2016
mattab added a commit to matomo-org/developer-documentation that referenced this issue Jul 14, 2016
* Document the new addTracker functionnality 

https://github.com/piwik/piwik/pull/10085/files 
matomo-org/matomo#10174 (comment)
matomo-org/matomo#9525
matomo-org/matomo#10174

* Update tracking-javascript-guide.md

* Update tracking-javascript-guide.md

* Improve multiple trackers

* Update tracking-javascript-guide.md

* Update tracking-javascript-guide.md

* Update tracking-javascript-guide.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. c: Usability For issues that let users achieve a defined goal more effectively or efficiently. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

No branches or pull requests

4 participants