@tsteur opened this Pull Request on November 1st 2016 Owner

Once merged I will issue PR for 3.x

ping @mattab

This PR is needed in order to not having to use _paq.push() when also using custom tracker plugins. Without this PR Piwik always created an unconfigured tracker instance which custom trackers may have used for tracking.

Also we have called window.piwikAsyncInit(); too late. It needs to be called before the tracker is marked as initialized:

Now:

window.piwikAsyncInit();
window.Piwik.trigger('PiwikInitialized', []);
window.Piwik.initialized = true;

Before:

window.Piwik.trigger('PiwikInitialized', []);
window.Piwik.initialized = true;
window.piwikAsyncInit();

This allows users to create a tracker instance via Piwik.getAsyncTracker before we create the default tracker via:

window.piwikAsyncInit = function () {
    var tracker = Piwik.getAsyncTracker(url, id);
};

Also now we only create an async tracker when there is actually a _paq configuration for it. If a user has not set any _paq.push() variables we won't create the initial async tracker. Otherwise we would have an unconfigured async tracker returned by Piwik.getAsyncTrackers() and users that use this method would not know whether the tracker has been configured or not. A not configured tracker would send all requests to the same URL as the current website which is wrong.

I have tested this with several plugins and it worked fine. Tested cases were piwik.js is loaded first, were custom tracker is loaded first etc.

@mattab commented on November 3rd 2016 Owner

Very well done :100: good to make the JS API more robust & pluggable

This Pull Request was closed on November 3rd 2016
Powered by GitHub Issue Mirror