Search...

Google Analytics WordPress LiteSpeed problem

How to fix a problem with Google Analytics for a WordPress website, caused by LiteSpeed caching plugin.
Update September 2021: current LiteSpeed plugin version (update) no longer has the problematic option – so there’s nothing to fix and no problems. 🙂

Contents:

  1. Noticing a Google Analytics problem
  2. Determining the problem cause
  3. Fixing the LiteSpeed caused Analytics problem
  4. Conclusion


1. Noticing a Google Analytics problem

As I was showing to a friend how to connect Google Search Console, and Google Analytics to a WordPress site, I realized that my analytics showed zero visitors since the 3rd of February 2021:

Google Analytics problem - no visitors registered since the 3rd of February
Google Analytics problem – no visitors registered since the 3rd of February
Picture 1

OK, I have noticed a problem, how will I solve it?


2. Determining the problem cause

The first thing I do when checking if Google Analytics works properly is going to open a page on my website, and go to Google Analytics “Realtime” reports page – to see if my visit is shown there.

Google Analytics realtime reports page
Google Analytics realtime reports page
Picture 2

This looked OK when I was logged-into the website as an admin, but if I opened a page with an incognito browser tab (not logged in), my visit didn’t show in Google Analytics.
I hadn’t thought of cross-checking this right away, until bibi from LowEndSpirit forum suggested it.

I test every update, or website change, in a staging environment before implementing them on my websites. Everything looked OK up to that point, and I hadn’t made any website changes before the problem occured.

I compared page source code of the WordPress website that had “lost Analytics,” with a plain HTML website who’s Analytics worked fine – looking for Google Analytics tag code. It showed this:

Plain HTML website:

<script async src="https://www.googletagmanager.com/gtag/js?id=...


WordPress website:

<script async src="https://io.bikegremlin.com/wp-
content/litespeed/localres/www.googletagmanager.com/gtag/js?id=

You can see a page’s source by clicking the right mouse button, then choosing the “View page source…” option, or using CTRL+U key combination.

I’m not smart enough to see the problem cause from this. However, I did suspect LiteSpeed, so I Googled: “Google Analytics LiteSpeed problem.”

It turned out that LiteSpeed’s update of February the 2nd 2021 caused problems to many people.


3. Fixing the LiteSpeed caused Analytics problem

The solution is simple:

  1. Go to the LiteSpeed caching plugin options.
  2. Choose the “Page Optimization” menu option.
  3. Click on the “Localisation” option.
  4. Delete, or comment out (using the “#” sign) all the Google script lines.
  5. Click on the “Save Changes” button.

Picture makes it clearer:

Fixing Google Analytics problem caused by LiteSpeed caching plugin
Fixing Google Analytics problem caused by LiteSpeed caching plugin
Picture 3

Your website’s list may include many more scripts, but these five are the ones causing problems with Google Analytics:

https://www.google.com/recaptcha/api.js
https://www.google-analytics.com/analytics.js
https://www.googletagmanager.com/gtag/js
https://www.googletagmanager.com/gtm.js
https://www.googletagservices.com/tag/js/gpt.js

You can also solve the problem by turning off the “Localise Resources” option, with all the pros and cons of such solution.


4. Conclusion

This is one of the things I don’t like about WordPress. In spite of all the caution & precautions, problems like these can arise. To make matters worse, they sometimes aren’t even noticed right away.

Many themes and plugins are updated relatively frequently. Some of these updates are “security critical,” or could be important. So you are bound to be updating relatively frequently, with every update posing a risk. You are damned if you update, and damned if you don’t. 🙂


Please use the BikeGremlin.net forum for any comments or questions.

If you've found any errors or lacking information in the article(s) - please let me know by commenting on the BikeGremlin forum.
You can comment anonymously (by registering with any name/nickname), but I think it is good to publicly document all the article additions (and especially corrections) - even if their author chooses to remain anonymous.

Tools and other products that I use (and can recommend)

Skip to content