• Hi,

    We use WP Rocket and exclude our locally hosted file. So it runs immediately. However after that and after user does some action even analytics.js runs. Is analytics.js necessary to keep running and why? And if we have it delayed is there an issue?

    It’s weird because it looks like it’s not needed, we have pretty fine stats in GA and GA4. But on our other site no matter what I try it’s not excluded and runs directly at the page load…

    Thanks for answering.

    Karel

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author DaanvandenBergh

    (@daanvandenbergh)

    Hi!

    I’m not sure I fully understand what you mean with “After user does some action even analytics.js runs.”

    Do you mean that the file is loaded after user e.g. scrolls the page?

    If so, I know that WP Rocket has a JS optimization option to delay JS loading until user interaction.

    By analytics.js, do you mean the file loaded from Google’s servers? I.e. google-analytics.com/analytics.js or googletagmanager.com/gtag.js?

    Thread Starter keengamer

    (@keengamer)

    Yes to everything. First of all the local javascript is loaded. After some interaction the analytics.js from google server is loaded.

    For example first load it’s fd89fbf1.js, after the interaction it’s also https://www.google-analytics.com/analytics.js but not before. The initiator is the first local file leading to gtag which leads to analytics.js

    Is this analytics.js needed? Is it important to load together with the first local file or could it be delayed?

    We use asynchronous gtag.js (v4 beta) settings in your plugin.

    I’m thinking that delaying analytics means that people bouncing from the site will not load it and therefore our stats will be wrong without those pageviews??

    Thanks.

    Edit: For some reason I am unable to run analytics.js together with the local file. However still, it doesn’t make sense to load the file when it’s locally set. And, if I switch to analytics.js or gtag.js (not the beta version) then gtag neither analytics is loaded. It looks like it’s loaded only with the beta ga4 version…

    Edit 2: Hm, alright, using gtag.js and dual tracking means that 3 local javasccripts are loaded.

    In my opinion, if first script loads fine and others are after some interactions then GA4 using gtag is not correct, right? But loading three files instead of one is not really an optimization here in my opinion. Also, if using GA4 beta why the second file is not hosted locally as well?

    • This reply was modified 2 years, 1 month ago by keengamer.
    • This reply was modified 2 years, 1 month ago by keengamer.
    • This reply was modified 2 years, 1 month ago by keengamer.
    Thread Starter keengamer

    (@keengamer)

    Alright, more info…

    If I exclude the main local javascript, all the next ones are delayed. It is necessary to exclude also js-(before|after) to make the other scripts running. However, I think that you are jquery dependent which means that we get another error in the console

    Uncaught ReferenceError: jQuery is not defined
    at (index):1722:1
    (anonymous) @ (index):1722

    So, right now I have no idea how to use dual tracking which would run correctly and would not be excluded from WP Rocket.

    Thread Starter keengamer

    (@keengamer)

    Another details. We were trying the minimal analytics directly without your plugin. It works but it would be nice to hide or redirect the google-analytics.com from the code which we are unable to do on our apache server. Maybe you would know how to do it. But…

    The main issue is that if we run Minimal analytics GA4 Beta then from the code I can see on the site you run this in the code https://www.google-analytics.com/g/collect with UA code and not G- code. So you mixed up GA and GA4 together. For GA there is this url used https://www.google-analytics.com/collect with UA and for GA4 it’s what you have but with G- identifier.

    So in this case, it doesn’t track anything neither in GA or GA4.

    For the previous minimal analytics you track it correctly.

    You can check GA4 here https://dariusz.wieckiewicz.org/en/minimal-google-analytics-4-snippet/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Is analytics.js needed?’ is closed to new replies.