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

Better async tracker initialization to not having to use _paq.push #10818

Merged
merged 2 commits into from Nov 3, 2016

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Nov 1, 2016

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.

@tsteur tsteur added the Needs Review PRs that need a code review label Nov 1, 2016
@tsteur tsteur added this to the 2.17.1 milestone Nov 1, 2016
@mattab
Copy link
Member

mattab commented Nov 3, 2016

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

@mattab mattab merged commit 1a2a91e into 2.x-dev Nov 3, 2016
@mattab mattab deleted the betterasynctracker branch December 16, 2016 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants