Skip to content

πŸ“Š Google Analytics without GDPR or cookie bar hassle

Notifications You must be signed in to change notification settings

pieterbeulque/anonymous-analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘€ Anonymous Analytics πŸ‘€

Are you sure you need to use Google Analytics? Consider Fathom Analytics or Simple Analytics as an alternative!

There's a way to use Google's analytics.js script in a GDPR- and cookie-friendly manner.

This script loads Google Analytics for you. It then disables all cookies set by Google Analytics & enables the IP anonymization built into GA. The unique client ID is generated by nanoid and stored in local storage using storee (if available) or in the history state object using histore.

Because you're now using a first party method instead of a third party cookie to track your user across their session, you might be able to get away without the dreaded cookie bar.

The ga object is still exposed on window, so you can still do any other event tracking. Be careful to keep your GDPR-compliance if you do so. There is currently no option to rename the ga global.

Usage

<script src="anonymous-analytics.js"></script>
<script>
    window.anonymousAnalytics('UA-XXXXXX-XX');
</script>

Browser support

It works on every modern browser and has been tested in IE11. I don't see any reason why it should not work in any older versions of Internet Explorer, but I haven't tested it thoroughly.

Disclaimer

I am not a lawyer and cannot be held accountable for any wrong advice

About

πŸ“Š Google Analytics without GDPR or cookie bar hassle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published