Reputation: 324
I use Google Analytics on my page, and I want to give the user the option to disable the tracking by clicking on a button that executes the following code:
window["ga-disable-<my tracking id>"] = true;
This code is provided by Google: https://developers.google.com/analytics/devguides/collection/analyticsjs/user-opt-out
However, it sets the property and doesen't send any more hit tasks as long as I stay in the session, but as soon as I reload the page the property is set to false again.
Is there any way I can disable it permanentely?
Upvotes: 2
Views: 1357
Reputation: 34
The custom function will need to be execute. It will set a cookie for a long time in the future and disable analytics.js data collection. When a user returns to this site, the script above will check to see if the opt-out cookie has been set. If it has, then the analytics.js data collection will also be disabled. For reference use the below URL
https://developers.google.com/analytics/devguides/collection/gajs/#disable
Upvotes: 1