Hosting Google Analytics Locally

Latest posts by Derek (see all)

Subtitle: “This is not officially supported by Google, but we have been doing this for years without any issues.”[perfmatters]

Note: Information is provided ‘as is!’ This remains effective until the post is edited & each link has been evaluated for relevancy and subjected to a perfunctory safety check. Once completed, you will no longer see this statement. This post is a result of my endeavour to meet the new General Data Protection Regulation (GDPR) regulations concerning the anonymization of IP addresses. For those of you utilizing GA and doing any type of business in Europe, then, this post is especially for you! I can only assume that the rest of you are here for speed considerations. Welcome to all!

Disclaimer: I have no affiliation with any commercial entity mentioned in this post.

Hi! After my ‘meltdown’ over:

  • the Saudi’s ‘ruler-in-waiting’ involvement in the butchering of Jamal Khashoggi
  • the mined data & security techniques used to track Mr. Khashoggi
  • the possible implications of utilizing mined data such as the data from Google Analytics – GA [et al.]

and,

  • the nefarious characters (yeap…the usual ones) utilizing mined data for political ends;

…I felt compelled to remove GA from my site along with Microsoft Clarity – MC! Which I did! Because…IPs associated with mined data were NOT anonymized[1] and, therefore, in breach of the new GDPR regulations.

THEN…oh yeah, then…I spent considerable time researching, deploying first on my hosting server (a big mistake), re-deploying on my development server, where I configured and, finally, made operable, the open-source, in-house, analytics software, Matomo! Just to ease my conscience…and comply with GDPR regulations for the anonymization of a website visitor’s IP! AFTER THAT…oh yeah, after that

Update: NO ONE TOLD ME…

…about GA’s capability to anonymize IPs, eh!

EVERYBODY just kept quiet while I dug my ‘hole’ deeper! That’s OK…lol! YOU ARE SAFE! My voodoo dolls never work. Darn! Besides…I am like a Timex watch: “I take a licking…and I keep on ticking!” EclecticBeaver's Signature Image

Anyway……let me quote something for you:

“According to the GDPR, IP addresses are considered as PII (Personally Identifiable Information). So if you use a Google Analytics account, you’d require to prevent the storage of your website users’ IP address information. You could implement this through the IP anonymization function in Google Analytics.”[unedited from Cookieyes]

That is correct, folks! You can make GA compliant with the new GDPR IP anonymization regulations. You have the capability to anonymize a visitor’s IP address within GA itself! Sweet! Here is the link showing how you can configure the gtag.js script to anonymize a single or all IP addresses. Further information on this subject can be obtained here.

Ok! Now that I am able to, once again, use GA et al, I thought that, before I re-deploy it, I might as well spend a little time researching the Internet to find any optimizing ‘nugget’ I may have overlooked with regard to optimizing GA for a WordPress site.

Well, I did find something! And, I must say, I can not fathom how this discovery escaped notice after all of my previous research attempts on this same subject!!! Yes, I discovered that you can host the GA file itself on your very own server! Whaaaaaaat? But…why?

Benefits from hosting GA locally are obvious to anyone familiar with server requests[2] and how each request affects your scoring on such performance sites[3] as, for instance, GTmetrix. And, there is a ‘lite’ version called Minimal Analytics which “also helps you get rid of that annoying Unused JS notice in Google PageSpeed Insights![configurable with CAOS, a WP plugin by Daan from FFW.Press]

Being the aspiring webmaster that I am, I wanted to manually configure everything necessary for GA to work locally. This obviously included downloading and installing the GA file on my server…which I did! Unfortunately, after installing it in my child theme folder and configuring the gtag.js snippet to find the GA file there, I came to find out that you also have to set a cron job! In order to update! Oh, oh!

You can smell the rubber too, eh? Yeap! Although I can hack my way through HTML, CSS, some JS, and a wee bit of PHP; I have not yet cracked open a book on the inner workings of WordPress. The closest I came to looking ‘inside’ was when I was researching how to create my child theme. Nope! I will be patient with this one as there is that factor X…which means… you may very well be bogged down with troubleshooting…eeks…forever…no…silly me!

With this in mind, I decided to forgo in-depth learning of WordPress development for now and simply use a plugin called the Complete Analytics Optimization Suite (CAOS). Don’t ask me how it is working…yet! I just found it myself! All I can say at this point is that everything is ‘up & running!’ except modifying the script for single or all IP anonymization! Hmm! Well, that’s for another day! Night folks!

——————————

UPDATE March 3, 2022: Hi! Configured CAOS today for dual tracking which utilizes both UA v3 & GA v4 APIs. I stopped at my GA console first and cleaned up my accounts to ensure a fresh start. I will wait a couple of days before resuming…

Thoughts: My next challenge is determining how you can configure the script to anonymize singular or all IPs. I am hoping it is a matter of perusing the files, finding the snippet, and, configuring it according to the GA instructions. Maybe I am looking at this problem too linearly. Perhaps there is another way to accomplish this! At this point, I do not know…Then, in the back of my mind, there is the question of Google’s Tag Manager and its’ compatibility with CAOS. Eventually, I am going to have to incorporate the Tag Manager as the v3 API slowing disappears through attrition.

…gotta go…

UPDATE March 6: Hi! After two days there is still no data showing in GA except my activity! Yet, Microsoft Clarity is showing visitor interaction on my site! Now, I know everything is working when I open the GA interface as you get a little ‘success’ message after the connection ‘handshaking’ has finished. But…there is NO data! Only mine! Even the CAOS plugin indicates everything is fine…which leaves me with…nothing…ugh!

There is an old saying that comes to mind when I am confronted with situations like the one I am now in, eh! And, that is: “Proof is in the pudding!” In other words, time to go back to square one and confirm, again, that GA is still working and registering visitor data as would be indicated in the GUI…without CAOS! If so, then I have to troubleshoot the CAOS configuration. If not, then I am going to start ‘pulling my hair out!’ And, no…I am not afflicted with trichotillomania, lol!

Ok! I am going to uninstall CAOS and re-inject my GA tags (v3 & v4) manually…for now…until I see the results after another couple of days! Time will tell folks…gotta go…

UPDATE March 16: Hi! Had the CAOS plugin up & running again…but…had to deactivate it as no data was showing in the GA interface. Hindsight: I could have checked the GA real-time overview at the time of configuration but I knew mine was proper…end of the story, eh! Bloody Gremlins!

It may be a problem with the new security plugin I installed. Unfortunately, my time is very limited right now and as much as I would like to solve this ‘mystery’, I have to move on…

Besides, I see the GA console is displaying a banner during a UA view announcing the upcoming 2023 end of the UA v3 API (Google Universal Analytics). I might as well swing everything over to the GA v4 API (Google Analytics 4) right now in preparation.

I will have to take this matter up at a later date. And, as that ‘charismatic character’ so bluntly informed us: “I’ll be back!”

UPDATE March 20: just being hammered from all directions right now! And, with GA being asynchronous, I am now wondering if the heyday for plugins like CAOS has come and gone. You reduce server requests but is there any lasting time benefit once the process has completed its’ cycle? How refined would the tests have to be to see actual-time differences between each possible scenario? Lol! More questions! Time for some BF4…have a good evening folks!

To be continued…sometime…maybe…

——————————

[1] Is this a case of ‘begging the question?’ Being anonymized, within the context of the GDPR, does not preclude the ability to trace the route whence the ‘anonymized IP’ came, and subsequently, discover the non-anonymized IP itself! Using the Tor network would normally prevent such a discovery. And, whether such things as secure DNS (or DNS over HTTPS) help, in any way, to obscure reverse engineering, is beyond my expertise! In any event, I am quite sure not everyone would be happy using the Tor network simply to avoid having their IP discovered! As most people don’t bother with such things. …I feel so lonely now…

[2] No need for a roundtrip to a GA server and back…heha!

[3] Although useful, these sites are informative only! How many times have you run a ‘perfect’ test and yet noticed that your website is not visually fast at all! I have seen this numerous times and was caused by factors such as caching, server load…who knows…&%(*#^%$, lol! Just think of the many possible technical scenarios between these testing applications and real-world website configurations being rendered by their respective hardware! In other words: don’t get fixated on them! Do what you can with the provided information…and then move on!

[4] Here is the Minimal ‘Google Analytics’ Snippet from minimalanalytics.com

Comment! 😊

Your email address will not be published.