[DigitalPoint] Better Google Analytics

[DigitalPoint] Better Google Analytics 1.1.2.2

No permission to download
Happening on mine too, but only once in awhile. It looks like this...


View attachment 319575

Site is https://www.satelliteguys.us
Hmmm... I don't see it happening no matter how much I click around. Is there a specific URL on the site that it seems to happen more with for you?

Looking at the browser console, I do see a crazy amount of errors (literally pages and pages of errors), but looks like they are from ads and other third-party things, I don't see any error from Google Analytics stuff. and I'm not seeing any issue with the later_today_at_x thing.
 
The only thing I can think of is maybe it's a timing issue... it looks like you have a ton of custom/third-party JavaScript going on before the Google Analytics JavaScript. So if one of those things trigger a Google Analytics event before the browser is able to get down to the window.dataLayer=window.dataLayer||[]; line of JavaScript code, an error would happen in the console (basically if you have something trying to call gtag() before gtag is defined). I suppose you could rearrange some JavaScript so the other stuff being added is coming at the end of the <head> tag instead of the beginning, that could help...

Hard to exactly track down what might be the culprit, because as I said, there's a TON of JavaScript going on (and I also haven't been able to replicate it).

You could wrap the Analytics code in it's own <script> tag, but honestly I'm not sure that's a great idea... all that would do is hide you have a timing issue, it doesn't solve it (you wouldn't get an error, but you also wouldn't get any Google Analytics data).
 
Happening on mine too, but only once in awhile. It looks like this...


View attachment 319575

Site is https://www.satelliteguys.us
Are you able to disable Google Analytics ad tracking within your Ads Manager addon? It looks like it has the potential to fire gtag() events before gtag is defined. I could be wrong, but skimming the code, it's looks like it has a sendGaEvent function that is firing Google Analytics events for things like ad impressions and ad clicks, but attaching those events based on a delay timer (2 second delay) but not actually checking if gtag has been defined (normally 2 seconds would be plenty of time for gtag to be defined... but you would get an error if it didn't happen for whatever reason).

If your site is running terribly slow (for whatever reason), you could end up with a timing issue there (would be the same with or without this addon though).

Something to test anyway...

I think a more probable cause is going to be the crazy number of third-party ads and scripts you have running... if any one of those decide to fire a Google Analytics event without checking if gtag exists, it's going to be a problem... but hard to track down without seeing it happen.

For example whatever this is, it's the first JavaScript to be run on your site... even before XenForo's preamble:

Code:
<script defer src="https://cdn.unblockia.com/h.js"></script>
 
Updated to the latest version a few days ago, didn't think anything of it but I checked Analytics and there's nothing going into it now :(

Checking my source code and I can see this:

<script async="" src="/jc/gtm.js?_v=aa54f2c8"></script>

However, it 404s because there's nothing there.

I do have cloudflare / caching etc but even so it shouldn't break this should it?

Thanks


Edit, ignore this I found a fix for Nginx and it worked:

location ~ ^/jc/gtm.js {
try_files $uri /index.php?$uri&$args;
}
 
Updated to the latest version a few days ago, didn't think anything of it but I checked Analytics and there's nothing going into it now :(

Checking my source code and I can see this:



However, it 404s because there's nothing there.

I do have cloudflare / caching etc but even so it shouldn't break this should it?

Thanks


Edit, ignore this I found a fix for Nginx and it worked:
While that will fix it as a one-off, it probably makes sense to not have Nginx blindly intercept requests based on the extension (.js in this case) without also checking if the file actually exists in the filesystem.

It sounds like any requests that end in .js, Nginx is choosing to handle it itself and not pass the request along to the application. It’s okay if you want to do that for whatever reason, but it’s probably worth having Nginx check if it’s an actual file (and if it’s not, let the application handle it).
 
Everytime this happens, the browser console will show
whats-new/:202 Uncaught ReferenceError: gtag is not defined
at whats-new/:202:445
 
Everytime this happens, the browser console will show
whats-new/:202 Uncaught ReferenceError: gtag is not defined
at whats-new/:202:445
Ya, I think it has to do with people using <xf:js> to inject custom JavaScript, but only is a problem in XenForo 2.3.

Specifically, XenForo inserts (and always has) Google Analytics JavaScript at the end of the <head> tag. But XF 2.3 now inserts code from <xf:js> usage at the top of <head> (previously it was added to the end of the <body>. This change in XF 2.3 seems to be causing timing issues because the Google Analytics JavaScript is now inserted after anything added with <xf:js>.

I have a new version in testing that injects the Analytics code farther up the page source instead of where XenForo injects it by default.

FWIW - it’s not a situation unique to this addon, stock XenForo does the same thing, but probably don’t notice it as much because it’s not doing any custom events (that XF 2.3 would still add above the primary GA code).
 
Confirmed this too, I thought I was going nuts, it goes away after a refresh. It's sporadic for sure.

Now it shows on the what's new page...
1740788243598.webp
 
I see something like tomorrow_at_x that then automaticly turns into later_today_at_x. If you reload the page it disapears.
Users have seen it in threads. I have seen it in news widgets I use from "[D.C Style] New Threads". I am useing xf 2.3.4 at the moment.
Hopefully your new version will solve this.
 
Updated and so far so good.
Will report back if it still happens.
Thank you Shawn.
FWIW, it's an underlying issue with XenForo core and how they changed execution order of JavaScript in 2.3. It just doesn't pop up as much in stock XenForo usage of Google Analytics because XenForo isn't really tracking much beyond page views (no problem with execution order of JavaScript when you aren't adding JavaScript to track Analytics events).

If you look at the page source of any page on xenforo.com, you'll see the Google Analytics code (search for gtag) is now coming after all other JavaScript... The change in XenForo 2.3 that moved all JavaScript into <head>, above the Analytics code is what's causing the timing issue. You just don't run into it much in stock XenForo because it's not doing much (which I already said). :)
 
No element passed in to event.
console.error.console.error@(index):114

114:
!function(b,c){"object"==typeof console&&"function"==typeof console.error&&(console.error_old=console.error,console.error=function(){console.error_old.apply(this,arguments);b.gtag("event","exception",{error_type:"console",error_message:arguments[0],fatal:!1})});b.onerror=function(a,d,e){b.gtag("event","exception",{error_type:"javascript",error_message:a,error_location:d,error_line_number:e,fatal:!1})};b.onload=function(){c.querySelectorAll("img").forEach(a=>{a.complete&&0===a.naturalWidth&&b.gtag("event",
 
No element passed in to event.

console.error.console.error@(index):114

114:
!function(b,c){"object"==typeof console&&"function"==typeof console.error&&(console.error_old=console.error,console.error=function(){console.error_old.apply(this,arguments);b.gtag("event","exception",{error_type:"console",error_message:arguments[0],fatal:!1})});b.onerror=function(a,d,e){b.gtag("event","exception",{error_type:"javascript",error_message:a,error_location:d,error_line_number:e,fatal:!1})};b.onload=function(){c.querySelectorAll("img").forEach(a=>{a.complete&&0===a.naturalWidth&&b.gtag("event",
Can you try a different browser without extensions/plugins installed by chance? If you Google that error, literally there is one result from the entire web... and that result is from you (out of 8 billion people on earth) with a different addon. Makes me think you might have something going on in your browser somehow. We are talking about a JavaScript error that no one else in the world has ever seen or talked about on any site? Seems unlikely...

 
Can you try a different browser without extensions/plugins installed by chance? If you Google that error, literally there is one result from the entire web... and that result is from you (out of 8 billion people on earth) with a different addon. Makes me think you might have something going on in your browser somehow. Somehow, we are talking about a JavaScript error that no one else in the world has ever seen or talked about? Seems unlikely...

Could be related to the shoutbox, but no reference in the line. Non shoutbox page seems to not produce it. How sporadic of me.
 
Could be related to the shoutbox, but no reference in the line. Non shoutbox page seems to not produce it. How sporadic of me.
If you have a URL where it's happening, I can try to take a look... I can't promise being able to debug it, but maybe it's something obvious. Just seems strange that whatever is going on seems to be specific to you somehow.
 
If you have a URL where it's happening, I can try to take a look... I can't promise being able to debug it, but maybe it's something obvious. Just seems strange that whatever is going on seems to be specific to you somehow.
I'll shoot you a message with some login details later, but its the homepage of our forum when signed in.

Cheers.
 
Back
Top Bottom