Skip to main content

How to disable cookies on Google Analytics so that you don't need a consent banner

The integration of Google Analytics into a website or blog is not GDPR-compliant by default. You must first obtain explicit consent of the end-users to store cookies, describing in your privacy policy how you intend to use collected personal data. This is the reason why most websites nowadays display an annoying (but necessary) consent banner. If you fail to do so or if you only ask for implicit consent, you are at risk of being fined.


However, it is possible to disable cookies on Google Analytics (GA) respecting end-users privacy, so that you don't need to ask for consent. The downside is that you will not be able to distinguish the type of user (unique vs new vs returning) and you will miss some session insights. If these details are not relevant for you, here is how you do it.

Disable Google Analytics cookies on a custom website
If you have a custom website with full access to the source code, you can simply insert the script below between the <head> and </head> tags, filling in your own tracking id. The only difference between the default Google Tag Manager tracking code and this one is the client_storage: 'none' attribute that disables storing cookies on user's browser.
<script async='async' src='https://www.googletagmanager.com/gtag/js?id=UA-YOUR_TRACKING_ID'/>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-YOUR_TRACKING_ID', {
client_storage: 'none'
});
</script>

Disable Google Analytics cookies on a React web app
If you own a web app developed with ReactJS, it might be wise to use react-ga package for Google Analytics integration. In order to disable cookies you need to set these two attributes under gaOptions when initializing react-ga.
import ReactGA from 'react-ga'

ReactGA.initialize('UA-YOUR_TRACKING_ID', {
gaOptions: {
storage: 'none',
storeGac: false
}
});


Disable Google Analytics cookies on Blogger
Blogger has an option to set up Google Analytics via Settings, but this feature does not allow you to disable cookies. In order to do so, you need to access the source code of your theme by selecting selecting Theme -> My theme -> Edit HTML in the left-side menu. First you need to insert this code (with your own tracking id) between the <head> and </head> tags.

<script async='async' src='https://www.googletagmanager.com/gtag/js?id=UA-YOUR_TRACKING_ID'/>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-YOUR_TRACKING_ID', {
client_storage: 'none'
});
</script>

Then you need to remove (or comment) the following line:
<b:include data='blog' name='google-analytics'/>

If you want to remove the cookie banner that Blogger displays by default, you need to add this line of code in the <head> section and save the changes.
<!-- Remove Blogger cookie banner since we use Funding Choice -->
<script type='text/javascript'>cookieChoices = {};</script>


Check that Google Analytics cookies are disabled
  1. Open an incognito window on Google Chrome
  2. Open Developer Tools and click on the Applications tab
  3. Go to your website or blog
  4. If you click on your website URL under Cookies you should not see anything at all, as per screenshot below.
  5. Open Google Analytics and ensure that your visit has been successfully registered.

Disclaimer
This article does not constitute legal advice. You are responsible of ensuring that your website is compliant with the existing privacy regulations at all times.

Popular posts from this blog

How to jump to time offsets in HTML5 video

Let's say that you have a 30-minute WEBM video file, from which you just want to play the following video segments , jumping from one to the other automatically  without interruptions : [00:01:25.00 - 00:02:25.00] -> from second 85 to 145 [00:11:40.00 - 00:11:55.00] -> from second 700 to 715 [00:20:26.00 - 00:21:07.00] -> from second 1226 to 1267 [00:26:11.00 - 00:28:01.00] -> from second 1571 to 1681 To increase the complexity, let's think that you have these video segments in a PHP variable $arrayVideoSegments  (normally the case if they were retrieved from the database).   $arrayVideoSegments[0]->startTime = 85   $arrayVideoSegments[0]->endTime = 145   $arrayVideoSegments[1]->startTime = 700   $arrayVideoSegments[1]->endTime = 715   $arrayVideoSegments[2]->startTime = 1226   $arrayVideoSegments[2]->endTime = 1267   $arrayVideoSegments[3]->startTime = 1571   $arrayVideoSegments[3]->endTime = 1681 The fo

5 learnings from a techie turned into a NFT artist

In September 2021 I chose to sell my crypto AI art business after two enriching (and often painful) years as a part-time sole founder. Today  AImade.art  is one of the best-selling AI art collections on Opensea . I want to share with you some of the key lessons I learned during this period: Work hard and get lucky.  And I got really lucky. On February 24th 2021 I had planned to shut down AImade.art , back then a business selling AI Art printed on canvas. I was discouraged after several months with no sales and my Shopify billing cycle was ending that day. Then something incredible happened: I missed the Shopify deadline and I sold an artwork one hour later. The buyer asked me: " Can I get it in as an NFT? ". I had absolutely no idea what an NFT was, but after a bit of research I found the concept so interesting that, two days later, I had pivoted the entire business to  NFT art made by AI . Sales started to pick up: I had finally found product-market fit . Impostor syn

Microsoft will soon launch a feature to schedule chat messages on Teams

In 2021 I wrote an article  where I shared why I started scheduling my emails and the positive impact this easy action has had on the wellbeing of the recipients and on my own work-life balance . However, one of my frustrations is that, as of today, it is not possible to schedule chat messages or posts on Microsoft Teams. Have you ever received a push notification on a Friday evening  from a non-urgent message that could have easily waited until Monday? Yes, you know what I am talking about! The good news is that Microsoft is currently working on this feature, and it is expected to be released in July 2022 , as we can see on Microsoft's roadmap . It was back in June 2019 when this useful functionality was first proposed on Microsoft Tech Community . It soon gained many supporters that pushed it through the approval channels. I can't wait to start using this!