Title: litespeed and google analytics error
Last modified: January 21, 2023

---

# litespeed and google analytics error

 *  Resolved [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/)
 * Hello
 * since activating Litespeed caching (latest version) I noticed a big discrepancy
   in google analytics. Most of the traffic is marked as Direct.
 * I found an [earlier thread](https://wordpress.org/support/topic/all-google-analytics-traffic-marked-as-direct/page/2/)
   about how this was solved but, it seems it hasn’t.
 * This is the google analytics code that I use:
 *     ```wp-block-code
       <!-- Global site tag (gtag.js) - Google Analytics -->
       <script async src="https://www.googletagmanager.com/gtag/js?id=G-xxxxxx"></script>
       <script>
         window.dataLayer = window.dataLayer || [];
         function gtag(){dataLayer.push(arguments);}
         gtag('js', new Date());
   
         gtag('config', 'UA-xxxxxxx-1');
         gtag('config', 'G-xxxxxxx');
       </script>
       ```
   
 * I’ve added under JS excludes and JS Deferred excludes:
 * analytics.js
   gtag
 * Now I’ve also added those under Guest mode excludes which impacts the Pagespeed
   score negatively.
 * Is there anything else I should do or change in order to solve this?
 * thank you!

Viewing 12 replies - 1 through 12 (of 12 total)

 *  [serpentdriver](https://wordpress.org/support/users/serpentdriver/)
 * (@serpentdriver)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16395732)
 * > Is there anything else I should do or change in order to solve this?
 * ….and you purged the cache after the changes?
 *  Thread Starter [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16395839)
 * I did. If I check Realtime analytics the percentage of direct visits seems too
   high, but I will know after a few days if the trend is normalizing.
 * I keep running into problems. I run litespeed caching on 3 websites on the same
   VPS with openlitespeed web server.
 * On one [website ](https://biketestreviews.com/)I noticed, after I updated today
   to the latest version of the plugin plus added those excludes above, litespeed
   caching is no longer working. Pagespeed score dropped from 95 to 46-50. Seems
   that guest mode caching is not working on mobile.
 * Is it normal that .htaccess file doesn’t contain any of the litespeed caching
   directives? 😮
 *  Thread Starter [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16395862)
 * my mistake. htaccess is not empty.
 * wordpress installation is inside a wp directory (public_html/wp/)
 * .htaccess file in public_html folder only contains wordpress directives.
 * .htaccess file in public_html/wp/ has wordpress directives plus litespeed directives
   etc.
 * is that alright?
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16397082)
 * please provide the report number
 * you can get it in toolbox -> report -> click “send to LiteSpeed”
 *  Thread Starter [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16397134)
 * I did. as it happens on all litespeed installations here are two reports:
 * Report number: **BGFPBXNO**
 * Report number: **SLEQEJCU**
 * thank you!
 *  Thread Starter [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16408353)
 * just to confirm that I still face the same issue.
 * distribution of traffic channels is skewed (too much direct traffic) and pages
   per visits are higher than normal.
 * I forgot to mention that I use cloudflare, if that can make any kind of impact
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16414762)
 * hmmm , I don’t think CF will affect this part
 * please create a ticket by mail to `support at litespeedtech.com` , with reference
   link to this topic , one of our devs will check up with you on this issue.
 *  Thread Starter [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16456660)
 * support was contacted. still trying to find the solution
 *  [John](https://wordpress.org/support/users/graphical/)
 * (@graphical)
 * [3 years ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16725994)
 * We have the exact same problem on a couple sites. Any update ?
    -  This reply was modified 3 years ago by [John](https://wordpress.org/support/users/graphical/).
 *  Thread Starter [ropezg](https://wordpress.org/support/users/ropezg/)
 * (@ropezg)
 * [3 years ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16726024)
 * putting this code on top of the page before GA code solved the problem when it
   comes to high percentage of direct visits.
 *     ```wp-block-code
       <script data-no-optimize="1">var litespeed_docref=sessionStorage.getItem("litespeed_docref");litespeed_docref&&(Object.defineProperty(document,"referrer",{get:function(){return litespeed_docref}}),sessionStorage.removeItem("litespeed_docref"));</script>
       ```
   
 * however, the pageviews is still higher than it should be
 *  [John](https://wordpress.org/support/users/graphical/)
 * (@graphical)
 * [3 years ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16726133)
 * [@ropezg](https://wordpress.org/support/users/ropezg/) Interesting.
   Pageviews
   are higher only when guest mode is activated?
 *  [serpentdriver](https://wordpress.org/support/users/serpentdriver/)
 * (@serpentdriver)
 * [3 years ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16726339)
 * > Pageviews are higher only when guest mode is activated?
 * Because the initial request is loaded twice.
 * [https://blog.litespeedtech.com/2021/06/01/guest-mode-for-wordpress-in-lscwp-v4-0/](https://blog.litespeedtech.com/2021/06/01/guest-mode-for-wordpress-in-lscwp-v4-0/)

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘litespeed and google analytics error’ is closed to new replies.

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 12 replies
 * 4 participants
 * Last reply from: [serpentdriver](https://wordpress.org/support/users/serpentdriver/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/litespeed-and-google-analytics-error/#post-16726339)
 * Status: resolved