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

JS Tracker: expected no warning in the console when addTracker multiple times #12545

Merged
merged 3 commits into from Feb 28, 2018

Conversation

mattab
Copy link
Member

@mattab mattab commented Feb 9, 2018

When addTracker is called twice or more, currently the following message is displayed in the console:

The method addTracker is registered more than once in "_paq" variable. Only the last call has an effect. Please have a look at the multiple Piwik trackers documentation: https://developer.piwik.org/guides/tracking-javascript-guide#multiple-piwik-trackers

In reality it's allowed to call addTracker multiple times and this is an edge case as all other methods should only be called once: var applyFirst = ['addTracker', 'disableCookies', 'setTrackerUrl', 'setAPIUrl', 'enableCrossDomainLinking', 'setCrossDomainLinkingTimeout', 'setSecureCookie', 'setCookiePath', 'setCookieDomain', 'setDomains', 'setUserId', 'setSiteId', 'enableLinkTracking'];

@mattab mattab added Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review labels Feb 9, 2018
@mattab mattab added this to the 3.3.1 milestone Feb 9, 2018
js/piwik.js Outdated
@@ -7084,7 +7084,10 @@ if (typeof window.Piwik !== 'object') {
apply(paq[iterator]);
delete paq[iterator];

if (appliedMethods[methodName] > 1) {
var isMethodCallableMultipleTimes = ["addTracker"],
shouldMethodBeCalledOnceOnly = isMethodCallableMultipleTimes.indexOf(methodName) === -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want to use indexOfArray as .indexOf is not available in all browsers.
Also be good to use to var statements. isMethodCallableMultipleTimes be better renamed to methodsCallableMultipleTimes as it is not a boolean.

In theory it would be even doable to just say methodName !='addTracker' as more is not needed right now.

@tsteur tsteur merged commit 4bd774d into 3.x-dev Feb 28, 2018
@tsteur tsteur deleted the addTracker_warning branch February 28, 2018 03:15
InfinityVoid pushed a commit to InfinityVoid/matomo that referenced this pull request Oct 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants