Google Analytics Opt-Out using the Google Tag Manager (GDPR compliant)
If Google Analytics is in use, the operators of a website are obligated to inform the user about the scope of the data collection and to provide him with an opt-out option. Google offers a browser add-on for all common browsers that prevents Google Analytics tracking. However, this solution only works for desktop clients. But what if you are on the go with a smartphone or tablet and the opt-out plugin cannot be used? For this, we have developed an alternative solution for an opt-out link in our example. This makes it possible to set the Google Analytics opt-out cookie for mobile devices as well and is thus in compliance with data protection laws.
Problems with Google Analytics with GDPR coming into force
If the user is not offered an opt-out option for all devices, there may be problems with the new EU General Data Protection Regulation (EU GDPR). The new GDPR comes into force on May 25, 2018, and companies that fail to comply with the data protection guidelines can expect to face significantly high penalties. However, if the user is offered an opt-out link for all end devices, there is no need to fear a violation of the DSGVO according to the current status.
The integration of the Google Analytics opt-out link can be done easily and quickly with the help of Google Tag Manager (GTM), for example.
Short course: The Google Tag Manager
Google Tag Manager is a free tool in which tags (small "snippets" of code) can be easily included and managed on the website. The integration can theoretically be done without the need to additionally involve a developer to include the code in the source code. The prerequisite for adding the opt-out link is, of course, that the Google Tag Manager has already been set up for the website.
Easy integration of the Google Analytics opt-out in Google Tag Manager (GTM)
In Google Tag Manager, first create a custom script tag and include the following JavaScript code with the property ID:
<script>
var gaSettings = {
disableStr : 'ga-disable-{{Analytics Property}}',
gaOptOutFeedbackText : '{{OptOutFeedbackText}}'
};
function gaOptout(gaSettings) {
document.cookie = gaSettings.disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[gaSettings.disableStr] = true;
}
function gaOptOutFeedback(gaSettings) {
var gaDomainName = document.getElementById('gaDomainName'),
gaOptOutDom = document.getElementById('gaOptOutDom'),
gaOptOut = document.getElementById('gaOptOut'),
gaOptOutFeedback = document.getElementById('gaOptOutFeedback'),
newDomainName = document.createElement('span'),
newFeedbackText = document.createElement('span');
newDomainName.setAttribute('id', 'gaDomainName');
newDomainName.innerHTML = ' : <a href="' + window.location.origin + '">' + window.location.origin + '</a>';
newFeedbackText.setAttribute('id', 'gaOptOutFeedback');
newFeedbackText.setAttribute('class', 'gaOptOutFeedback');
newFeedbackText.innerHTML = ' ' + gaSettings.gaOptOutFeedbackText;
if (gaDomainName !== null){
gaDomainName.remove();
}
if (gaOptOutFeedback !== null){
gaOptOutFeedback.remove();
}
gaOptOutDom.insertAdjacentElement('afterend', newDomainName);
gaOptOut.insertAdjacentElement('afterend', newFeedbackText);
}
document.getElementById('gaOptOut').addEventListener('click', function () {
gaOptout(window.gaSettings);
gaOptOutFeedback(window.gaSettings);
});
if (document.cookie.indexOf(window.gaSettings.disableStr + '=true') > -1) {
window[window.gaSettings.disableStr] = true;
gaOptOutFeedback(window.gaSettings);
}
</script>
After the two variables Analytics Property and OptOutFeedbackText have been stored in the Tag Manager, you can continue with the integration of the text module in the website.
Integration of the Google Analytics Opt-Out Link in the Data Privacy Policy
An HTML code snippet is added to the privacy page that executes the gaOptout
function when the link is clicked. This function then sets a cookie called "disable-YOUR-ANALYTICS_ID" (e.g. disable-UA-12-3456789), which tells Google Analytics that tracking is not allowed. By doing this, we allow the user to opt out of Google Analytics tracking, no matter what device they are using. The HTML code for your website could look like this:
<p class="bodytext" id="disableGA">
Alternativ zum Browser-Add-On oder innerhalb von Browsern auf mobilen Geräten,
<a id="gaOptOut" href="/de/datenschutz/#disableGA">klicken Sie bitte diesen Link</a>,
um die Erfassung durch Google Analytics innerhalb dieser Website zukünftig zu verhindern
(das Opt Out funktioniert nur in diesem Browser
und nur für diese <span id="gaOptOutDom">Domain</span>).
Dabei wird ein Opt-Out-Cookie auf Ihrem Gerät abgelegt.
Löschen Sie Ihre Cookies in diesem Browser, müssen Sie diesen Link erneut klicken.
</p>
If the user deletes all cookies for the website, a new click is required. Otherwise, Google Analytics would track again.
Do you need assistance in setting up the Google Analytics Opt-Out function
or in setting up your Google Tag Manager / Google Analytics account?
We will be happy to advise you and look forward to your call or message!
Please feel free to share this article.
Comments
No comments yet.