matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.85k stars 2.64k forks source link

Make tracking with multiple trackers more consistent and robust #10952

Open tsteur opened 7 years ago

tsteur commented 7 years ago

By default tracking is done like this: _paq.push(['trackFooBar', 'param1', 'param2]).

When working with multiple trackers (and tracking different data to different sites) the same would be

var tracker = Piwik.getAsyncTracker(piwikUrl, siteId);
tracker.trackFooBar('param1', 'param2');

I think it would be more consistent to always use a push method as well instead:

var tracker = Piwik.getAsyncTracker(piwikUrl, siteId);
tracker.push(['trackFooBar', 'param1', 'param2']);

This simplifies some docs greatly, for example http://developer.piwik.org/guides/media-analytics/reference where we always need to explain how and where to call different kind of plugin tracker methods.

It would also make it more robust since tracker.trackFooBar() would result in an error when it is not defined but in the push method we can log or ignore certain methods, etc

It would also work with global tracker plugin methods (the ones that have ::) and works perfectly with custom tracker methods. Even when a plugin is uninstalled tracking would still work because tracker.MediaAnalytics.scanForMedia would not result in an error when done like this: tracker.push(['MediaAnalytics.scanForMedia']).

Easier to port code between _paq.push and multiple trackers. Because syntax is the same it is much easier to move from one solution to another.

hpvd commented 7 years ago

+1