I somehow felt the urge to use Google Analytics to track page views on my portfolio site. Google Analytics sets cookies and in Europe we’re required to show a cookie consent warning because cookie monsters ugh…
In the spirit of keeping things simple I used an example by Foture that uses fingerprint.js to implement visitor tracking without the need to set cookies. Which turned into a WordPress plugin and yay no cookie and no notification required!
Clone on Github or download plugin as a Zip file.
Via GIPHY
Setting your analytics tracking ID
The plugin has no settings page. Set your own tracking id by adding a filter:
add_filter( 'analytics_without_cookies_tracking_id', function() { return 'UA-XXXXXXX-XX'; } );
Visitor IP addresses are anonymized by default
Because we’re required to do so by law in Germany and because you’re a nice person. Turn it off if you are so inclined:
add_filter( 'analytics_without_cookies_anonymize_ip', '__return_true' );
Logged in users are not tracked by default
Enable tracking logged in users:
add_filter( 'analytics_without_cookies_ignore_logged_in_users', '__return_false' );