PDA

View Full Version : Google Analytics Code - Privacy laws



Michael
06-19-2015, 08:07 AM
Hi,

I love the possibility to insert my analytics Tracking ID directly via Admin Panel instead of implementing the code directly into the script files.
However, there is one thing that I had to change, because here in Germany we have some more severe laws concerning privacy, than the rest of the world :).
If you live in Germany and if you want to avoid legal issues, a part of the IP of the website visitor has to be anonymized. You can do it as follows:

- Look for "google_analytics.twig" file in "src/AVCMS/Bundles/CmsFoundation/resources/templates" folder.
- Open the file with an editor and insert the red marked line into the code:


{% if settings.google_analytics_id -%}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '{{ settings.google_analytics_id }}', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');

</script>
{%- endif %}

- Save the file

Thats it, now a part of the IP will be anonymized and the code is compliant with german privacy laws (There are a few other thing that webmasters in Germany have to do to,such as a contract close with google, changing the Privacy Notices and provide the opportunity to disable tracking on your websites).

I hope this little information is useful for other webmasters using the script.

Michael

jacobbannier
06-19-2015, 06:07 PM
Nice tip, are things like this enforced in Germany, or just 'one of them things you should do, but rarely get done'? e.g. enough to get your analytics account banned?

Michael
06-19-2015, 06:32 PM
Nice tip, are things like this enforced in Germany, or just 'one of them things you should do, but rarely get done'? e.g. enough to get your analytics account banned?

These things in Germany are enforced by law. If you do not oberserve this, it can be very expensive for a webmaster. I donīt think that google will ban any account if a webmaster will not do that things.
Google was forced by german legislator to offer those special things like anonymizing the IP and offer a browser plugin that stops analytics from tracking.

Now there is a new thing that german webmasters have to do. As the browser plugin (that stops tracking) do not work for mobile devices, we have to insert a code before the analytics code that gives the visitor the opportunity (especially with mobile devices) to stop analytics. Finally its really exhausting to use analytics and there are many webmasters who stop using it.

Michael
06-24-2015, 09:32 AM
There is another, fairly new thing, that german webmasters have to do.

As the Browser Plugin (that stops tracking) doesnīt work for mobile devices, we have to insert another code (opt-out-cookie) before the analytics code and we have to ad a link within the Privacy Notices that enables users of mobile devices to stop the tracking of google analytics. I added this as follows:

- look for "google_analytics.twig" file in "src/AVCMS/Bundles/CmsFoundation/resources/templates" folder
- open the file with an editor and insert the red marked line into the code
- than add the green marked code before the existing code:




{% if settings.google_analytics_id -%}
<script>
// Set to the same value as the web property used on the site
var gaProperty = 'UA-XXXXXXX-X'; <---- HERE you have to replace your Analytics ID

// Disable tracking if the opt-out cookie exists.
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
}

// Opt-out function
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
}
</script>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '{{ settings.google_analytics_id }}', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');

</script>
{%- endif %}

After that you have to add an additional text like this to your Privacy Notes (should be in german on a german website):


You can refuse the use of Google Analytics by clicking on the following link. An opt-out cookie will be set on the computer, which prevents the future collection of your data when visiting this website:
<a href=“javascript:gaOptout()“>Disable Google Analytics</a>

All german speaking people can find detailed instructions, how they can integrate Google Analytics in Germany compliant to German privacy laws. There you will also find the (important) text parts concerning Analytics, that you have to add to your Privacy Notes: https://www.datenschutzbeauftragter-info.de/fachbeitraege/google-analytics-datenschutzkonform-einsetzen/

I hope that these informations are helpful

Michael