Cookieless Google Analytics

A Web Developer based in Belgium, specialized in PHP & JS development
Search for a command to run...

A Web Developer based in Belgium, specialized in PHP & JS development
No comments yet. Be the first to comment.
I recently needed to collect all changes in one file for reporting purposes. Found this article: https://ratfactor.com/cards/git-diff-with-new-files In case you need something similar on Windows, here

Some projects start with a grand plan. Others start because you just need to read a file without thinking too much about it. That was the case for spread-compat. I needed a common interface for CSV, X

With modern css, you can almost get rid of sass. But there is one last pain point : media queries. Not being able to use variables or an easy, common syntax for typical breakpoints is really annoying. That is, until you meet Media Queries Level 5. I’...

This is a quick article to share this demo I just made. https://codepen.io/lekoalabe/pen/JoPNWpX

Modals are typical UI elements for many web apps. There are countless packages dedicated to that specific features, each framework creating its own variation. Popular frameworks like Bootstrap also have custom code to deal with it. But all this feels...

So this is becoming really annoying : you have a website, you want to track users with Google Analytics... but you need to comply with GDPR.
What do you do ? You add a big cookie consent plugin which hurts your website performance, annoy your users and might be blocked by adblockers ? And even then, most people don't have accept tracking (who would?) unless you trick them into accepting it. What if there was a better solution ?
Well there are two issues with Google Analytics :
This one is easy to fix and is even enabled by default in GA4.
gtag('config', '<GA_MEASUREMENT_ID>', { 'anonymize_ip': true })
or with
ga('set', 'anonymizeIp', true);
depending on if you use Universal Analytics or Google Tag Manager.
So this is more tricky because we need a unique id for each user. Obviously you can start a session for each user and use the session id as a reference. You can do this by using the following snippet when initializing Google Analytics:
ga('create', 'YOUR-GA-TRACKING-CODE', {
'storage': 'none',
'clientId': '<YOUR_USER_ID_HERE>'
});
But what if you are not using a session (eg: using cache) ? Then you have a problem. There are libs out there like fingerprintjs that helps to generate a unique token for a user, but again: do you really want to add one more library to your website ?
So here is what I'm using: