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

piwik.js: offer possibility to not send any tracking requests (similar to DoNotTrack) #9954

Closed
denisbabineau opened this issue Mar 21, 2016 · 9 comments
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.

Comments

@denisbabineau
Copy link

I'm using piwik in a cordova application; I want to be able to enable/disable piwik tracking "at runtime" as per user request (thru UI opt-out). I cannot use setDoNotTrack since I can't override the navigator's properties and can't find other means to disable once initialized so I'm using setCustomRequestProcessing to return an undefined (empty) request when I don't want tracking to be sent. This works well for single requests going thru sendRequest but sendBulkRequest doesn't employ the same checks and causes invalid tracking information to be sent (you'll see things like [?], [?], ... in your browser requests to piwik endpoint):

            function sendRequest(request, delay, callback) {
                if (!configDoNotTrack && request) {

vs:

            function canSendBulkRequest(requests)
            {
                if (configDoNotTrack) {
                    return false;
                }

                return (requests && requests.length);
            }

The later only checks for empty arrays, not arrays with empty request. Recommend adding check before adding to array in buildContentImpressionsRequests:

                    request = getRequest(
                        content.buildImpressionRequestParams(contents[index].name, contents[index].piece, contents[index].target),
                        undefined,
                        'contentImpressions'
                    );

                    if (request) {  // NEW CHECK HERE
                        requests.push(request);
                    }
@tsteur
Copy link
Member

tsteur commented Mar 29, 2016

I will merge suggested fix soon but I will still leave the issue open. I'm merging it as it makes sense in general to check whether there is actually a request URL. This is a workaround though and won't be documented or officially supported. To fix the issue we should provide a method to actually disable any tracking. I'm kind of surprised we do not have such method yet :)

setDoNotTrack() method is a bit misleading as I would expect to set the value without being dependent on navigator. Instead I would have expected that current method setDoNotTrack is named enableDoNotTrack or similar. Then setDoNotTrack would have actually accepted a boolean and only set the variable without checking navigator.

Goal of this issue would be to introduce a new method that let's a user disable tracking. We could maybe have a method disableTracking or doNotSendTrackingRequests or ... It could set the already existing variable configDoNotTrack to true or it could make use of a new variable since doNotTrack !== doNotSendTrackingRequests in case someone calls enableTracking afterwards the configDoNotTrack should keep it's meaning.

@tsteur tsteur added Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. labels Mar 29, 2016
@tsteur tsteur changed the title piwik.js: buildContentImpressionsRequests doesn't check the returned request before sending bulk piwik.js: offer possibility to not send any tracking requests (similar to DoNotTrack) Mar 29, 2016
@tsteur
Copy link
Member

tsteur commented Mar 29, 2016

FYI: I updated the title

@denisbabineau
Copy link
Author

@tsteur thanks for adding the check and I look forward to the proposed enhancements, should make things easier/simpler!

@tsteur
Copy link
Member

tsteur commented Mar 30, 2016

BTW: I merged the other pull request so in next version it should at least work as expected for you

@mattab
Copy link
Member

mattab commented Mar 31, 2016

Hi @denisbabineau a Pull request would be welcome to implement the new JS function 👍

@mattab mattab added this to the Mid term milestone Mar 31, 2016
@denisbabineau
Copy link
Author

@mattab I was going to create a PR for my original request (the simple check) but the YUICompressor version at the time was no longer available (I see you updated to 2.4.7 just today, so that's good), I didn't want to provide a possibly incompatible minified file. Ideally minified/binaries wouldn't be stored in source control with every commits but I'm sure the piwik project has a reason to be doing so, to each his own :-)

@mattab
Copy link
Member

mattab commented Mar 31, 2016

I'm sure the piwik project has a reason to be doing so, to each is own :-)

Fyi: we do this because some users use Piwik from git: http://piwik.org/faq/how-to-install/faq_18271/ so it's good to have the minified piwik.js ready to use.

@kevinjoyner
Copy link

@denisbabineau Hey - probably you've thought of this - but can you call set 'setTrackerUrl' as null or '' when the user disables tracking; and then set it properly again if they (re)enable tracking?

@mattab
Copy link
Member

mattab commented Oct 18, 2019

This was implemented in the meantime with the "Asking for consent" feature, see: https://developer.matomo.org/guides/tracking-javascript-guide#asking-for-consent 👍

@mattab mattab closed this as completed Oct 18, 2019
@mattab mattab added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

No branches or pull requests

4 participants