use if instead of window['ga-disable-…']?
Closed this issue · 2 comments
The current documentation says to use window['ga-disable-<?= $GoogleAnalyticsId ?>'] = …
in order to opt-out (or in, depending on how you use it) of tracking for Google Analytics. This is also the officially documented way.
However, what advantage does this have over using a simple
if (!localStorage.getItem('COOKIEBAR_ANALYTICS')) {
…
}
around the tracking script? Wouldn't the former still create a connection to Google's server for example?
It is uncertain but it may be that if you set the ga-disable-UA-XXXXX
window variable then Google Analytics may in fact opt you out from the analytics and hopefully delete the tracking records they have stored previously. Remember that until you check the box and refresh the page, you are tracked by GA.
If we would change the code to your proposal, the first visit will track would be tracked and the others would be not. Still, your first visit would be kept in GA system for sure. If you say explicitly to GA that you do not want to be tracked, there is a chance that your first visit would be forgotten.
Also as stated in the docs, this is just an example of how to implement this. If you feel your solution is better, just implement it 😉
It is uncertain but it may be that if you set the ga-disable-UA-XXXXX window variable then Google Analytics may in fact opt you out from the analytics and hopefully delete the tracking records they have stored previously. Remember that until you check the box and refresh the page, you are tracked by GA.
Good point, but do we know this?
If we would change the code to your proposal, the first visit will track would be tracked and the others would be not. Still, your first visit would be kept in GA system for sure. If you say explicitly to GA that you do not want to be tracked, there is a chance that your first visit would be forgotten.
Well, no, if you want it to be "opt-in", then you use
if (localStorage.getItem('COOKIEBAR_ANALYTICS')) {
…
}
Which means the tracking code will not be used until you set the checkbox. The first page visit will be tracked this way also, once you opted in, I think.
If you want it to be "opt-out", then you use
if (!localStorage.getItem('COOKIEBAR_ANALYTICS')) {
…
}
In this case the first visit is also tracked of course.
Also as stated in the docs, this is just an example of how to implement this. If you feel your solution is better, just implement it 😉
Of course :)