{"id":1658,"date":"2018-05-25T14:48:55","date_gmt":"2018-05-25T14:48:55","guid":{"rendered":"http:\/\/digitalsrc.com\/blog\/?p=1658"},"modified":"2023-02-23T05:23:03","modified_gmt":"2023-02-23T05:23:03","slug":"gdpr-compliance-for-google-analytics-how-to","status":"publish","type":"post","link":"https:\/\/digitalsrc.com\/blog\/gdpr-compliance-for-google-analytics-how-to\/","title":{"rendered":"GDPR Compliance for Google Analytics : How To"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1665\" src=\"http:\/\/digitalsrc.com\/blog\/wp-content\/uploads\/2018\/05\/Google-Analytics-GDPR-Compliance.png\" alt=\"\" width=\"568\" height=\"286\" srcset=\"https:\/\/digitalsrc.com\/blog\/wp-content\/uploads\/2018\/05\/Google-Analytics-GDPR-Compliance.png 568w, https:\/\/digitalsrc.com\/blog\/wp-content\/uploads\/2018\/05\/Google-Analytics-GDPR-Compliance-300x151.png 300w\" sizes=\"(max-width: 568px) 100vw, 568px\" \/><\/p>\n<p>Google Analytics is by far the most popular web analytics application that is used across the world. It is used both by individuals and small companies to large Fortune 500 brands. As per this study in 2015, almost 70% of Fortune 500 used Google Analytics as their web analytics platform. If you are one of those millions of Google Analytics users and you are in Europe or deal with clients\/ visitors from EU, you need to ensure that you are GDPR compliant.<\/p>\n<p>While we love to rely on Google and think that they will take care of everything for proper GDPR compliance there are few things that you need to do too.<\/p>\n<p>At a very broad level GDPR asks you not to collect and process any personal data without the consent of the data subject (user). Now before you tell me that Google Analytics data is anonymized and aggregated, let me show you couple of personal data points that could be captured in Google Analytics and put you on the wrong side of GDPR.<\/p>\n<ul>\n<li>Google Analytics captures IP addresses which is considered as Personal Data under GDPR<\/li>\n<li>Also, if you are passing any PII through your URLs ( typically happens when you are using GET method to submit form data or you are trying to personalize user experience) you might end up with URLs looking like www.yourdomain.com\/?name=x&amp;email=abc@gmail.com . Now all these URLs are captured in Google analytics and you are necessarily sharing this PII with Google. This is against Google\u2019s T&amp;C as well as could mean serious trouble for you from GDPR perspective.<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h2>So how to make Google Analytics GDPR Compliant<\/h2>\n<p><strong>Anonymize IP Address<\/strong><br \/>\nGoogle Analytics does provide you an option to anonymize IP addresses. If done properly Google will anonymize the users IP address while still in memory and the data will be written to disc for processing only after the IP addresses have been anonymized. If you are interested in the technical details, you can read the technical explanation here.<\/p>\n<h2>How to Anonymize IP Address in Google Analytics for GDPR Compliance<\/h2>\n<p>This again will depend on the version of Google analytics code you are using. There are three versions that most people are using. You are either using universal analytics using ANALYTICS.JS or GA.JS or the latest GTAG.JS.<\/p>\n<p><b>Anonymize<\/b><strong>\u00a0IP for analytics.js<\/strong><\/p>\n<p>&lt;script&gt;<br \/>\n(function(i,s,o,g,r,a,m){i[&#8216;GoogleAnalyticsObject&#8217;]=r;i[r]=i[r]||function(){<br \/>\n(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),<br \/>\nm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)<br \/>\n})(window,document,&#8217;script&#8217;,&#8217;\/\/www.google-analytics.com\/analytics.js&#8217;,&#8217;ga&#8217;);<br \/>\nga(&#8216;create&#8217;, &#8216;UA-XXXXXXX-X&#8217;, &#8216;auto&#8217;);<br \/>\n<span style=\"color: #ff0000;\"><strong>ga(&#8216;set&#8217;, &#8216;anonymizeIp&#8217;, true);<\/strong><\/span><br \/>\nga(&#8216;send&#8217;, &#8216;pageview&#8217;);<br \/>\n&lt;\/script&gt;<\/p>\n<p>Your analytics code probably looks like the one given above. Look at the highlighted line. You need to add that one line of code to anonymize IP address and it is important that the line is set before the ga(\u2018send\u2019, \u2018pageview\u2019); line.<\/p>\n<hr \/>\n<p><strong>Anonymize IP for gtag.js<\/strong><\/p>\n<p>This is the latest Google analytics code and if you are already using gtag.js, you can follow the below process to anonymize IP for GDPR compliance.<\/p>\n<p>In your gtag code you will notice the following line \u2013<\/p>\n<p>gtag(&#8216;config&#8217;, &#8216;UA-XXXXXX-XX&#8217;);<\/p>\n<p>This needs to be replaced with<\/p>\n<p><strong><span style=\"color: #ff0000;\">gtag(&#8216;config&#8217;, &#8216;UA-XXXXXX-XX&#8217;, { &#8216;anonymize_ip&#8217;: true });<\/span><\/strong><\/p>\n<hr \/>\n<p><strong>Anonymize IP for ga.js<\/strong><\/p>\n<p>In case you are still using the old ga.js Google analytics library, you can try using the below code. Note the line highlighted, you will need to add that to the script.<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\n\/\/ Old Script<br \/>\nvar _gaq = _gaq || [];<br \/>\n_gaq.push([&#8216;_setAccount&#8217;, &#8216;UA-XXXXXX-XX&#8217;]);<br \/>\n<span style=\"color: #ff0000;\"><strong>_gaq.push([&#8216;_gat._anonymizeIp&#8217;]);<\/strong><\/span><br \/>\n_gaq.push([&#8216;_trackPageview&#8217;]);<br \/>\n( function() {<br \/>\nvar ga = document.createElement(&#8216;script&#8217;); ga.type = &#8216;text\/javascript&#8217;; ga.async = true;<br \/>\nga.src = (&#8216;https:&#8217; == document.location.protocol ? &#8216;https:\/\/ssl&#8217; : &#8216;http:\/\/www&#8217;) + &#8216;.google-analytics.com\/ga.js&#8217;;<br \/>\nvar s = document.getElementsByTagName(&#8216;script&#8217;)[0]; s.parentNode.insertBefore(ga, s);<br \/>\n})();<br \/>\n&lt;\/script&gt;<\/p>\n<h2><strong>How to Remove Personal Data from Google Analytics for GDPR Compliance<\/strong><\/h2>\n<p>Now let\u2019s talk about how to remove the personal data that we might send to Google through URL parameters. It is not just important for GDPR compliance but it is also important for ensuring that you are compliant with Google Analytics\u2019 terms of service.<\/p>\n<p>You should ideally try to remove any PII right at the collection level of Google analytics and this requires some coding skills. Two excellent solutions for this has been given below and you can use any one of them that works for you.<\/p>\n<p><a href=\"https:\/\/www.simoahava.com\/gtm-tips\/remove-pii-google-analytics-hits\/\">Simo Ahava\u2019s Solution to Removing PII from GA<\/a><\/p>\n<p><a href=\"https:\/\/brianclifton.com\/blog\/2017\/09\/07\/remove-pii-from-google-analytics\/\">Brian Clifton\u2019s Solution to redact PII from GA<\/a><\/p>\n<p>If you have anonymized all IP addresses and are not capturing any PII in Google analytics, you should be ok with GDPR compliance.<\/p>\n<p>If you are a marketer like me and looking to ensure proper GDPR compliance across your marketing function, you can refer to this <a href=\"http:\/\/digitalsrc.com\/blog\/gdpr-checklist-marketer-infographic\/\"><strong>GDPR Checklist for Marketers Infographic<\/strong><\/a>.<\/p>\n<p>This is not a legal advise about GDPR and if you have any doubts or concern, please consult with a legal professional.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google Analytics is by far the most popular web analytics application that is used across the world. It is used both by individuals and small companies to large Fortune 500 brands. As per this study in 2015, almost 70% of Fortune 500 used Google Analytics as their web analytics platform. If you are one of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1665,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[111],"tags":[522],"_links":{"self":[{"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/posts\/1658"}],"collection":[{"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/comments?post=1658"}],"version-history":[{"count":0,"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/posts\/1658\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/media\/1665"}],"wp:attachment":[{"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/media?parent=1658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/categories?post=1658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalsrc.com\/blog\/wp-json\/wp\/v2\/tags?post=1658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}