Better async tracker initialization to not having to use _paq.push #10818
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Before:
This allows users to create a tracker instance via
Piwik.getAsyncTracker
before we create the default tracker via: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 byPiwik.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.