Detecting a visitor whose browser is blocking your Google Analytics Tracking from being loaded is quite simple. The best way is to check if the browser window knows the ga() function at all. And if not, well, something must have blocked Google Analytics from being loaded:
As we have to assign unique Client IDs to our visitors for proper tracking in Google Analytics, I use a little PHP Script that does five things:
Like this, you can store a unique Client ID in a PHP-Session-Variable even if a visitor is blocking Cookies. This enables you to identify the user at least during the entire session. (It won't recognise returning visitors because of the missing cookie. But it will track them as new ones.) If you don't store the Client ID for a visitor at all, a new one would be created on every page view. Like this, you couldn't track a user's journey at all as every new page view would seem to come from a different visitor in Google Analytics. That's why we try to set a long lasting Cookie. And just in case this isn't possible, we will have the Client ID at least stored in a PHP-Session-Variable (just in case of a Cookie blocking user). This is how my ga-cid.php looks like:
The ga-trackit.js will initialise Google Analytics in the first step. Here, we tell the loader not to create a Google Analytics Cookie as we will work with our own Client IDs. These Client IDs come from our PHP-Script as described above. We will request them with little Ajax Calls. And just in case the Ajax Call doesn't work for some reason whatsoever, the script will tell Google Analytics to start in the default (auto) mode. And if something blocked Google Analytics from being loaded, it will inject our Backend Tracking Pixel into the DOM / HTML:
The full ga-trackit.php (with the ga-cid.php include plus the code that returns the Transparent Tracking Pixel) looks like this now:
You can (and should) add more parameters to your tracking data, just check the Measurement Protocol Parameter List and you will find what you need for your insights — especially with regard to Ecommerce Tracking.
Click here to download the AdBlock Google Analytics Tracking Example Code . You can test the tracking in the Real Time Report of Google Analytics. And as you may have realised, I am able to code, some say even quite well, but I am definitely not a developer (rather enjoy working on the business side of things). Which means, probably, you are able to make a more beautiful version of all this if you are working rather on the development side. Feel free to send through a cool version and I will upload it here with a link to your website or GitHub profile.
I hope you have enjoyed my concept and you will make the best out of it!
Please share these ideas with your peers for further feedback & review on:
If you have knowledge about the impact of the coming ePrivacy Regulation , please get in touch as I want to discuss this topic in detail. Because here, we set a First Party Cookie with data (maybe) processed by a Third Party (Google Inc.). On the other hand, the same Client ID can be used to store data like products in a saved shopping cart. The Factsheet about Stronger privacy rules for electronic communications (01/2017) provided by the European Commission states:
Please get in touch if you want to discuss this topic. It's quite on top of my agenda and I would be delighted to receive additional information and your opinion. Thanks for sharing this concept paper now on:
You may enjoy my GitHub Open Source (05/2017):
ga-rm.js Plugin for Interaction Tracking in Google Analytics