Forum Moderators: DixonJones

Message Too Old, No Replies

How much has to load before Google Analytics counts a Page View?

         

ergophobe

4:51 pm on Feb 5, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I assume that once
- the DOM is fully loaded
- the asynch code for GA is loaded
We count a page view.

Someone is trying to tell me they have it set up so that they only count a page view if the page is 100% loaded (so the window.onload event vs document.onload). I'm 99.99% sure this is wrong, but would like to have something more authoritative than my opinion.

Anybody have a source that shows when asynch GA code fires for page view (not page timings, I can find docs for that)?

Thanks.

ergophobe

6:02 pm on Feb 5, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As near as I can tell, it's something like this

- DOM load
- resources start loading asynchronously in a race
- once the ga.js resource loads, you have a pageview unless you do something special

Marshall

12:53 am on Feb 6, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I thought it depended where on the page the analytics script was. Do they not recommend in the <head> before <body> for that reason?

Marshall

ergophobe

4:56 am on Feb 6, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It used to be a blocking script so they recommended before <body> unless it had to be in <head> for a specific reason (various types of event tracking).

Now it's asynch and should always go in the head, but you don't know when it will load.

But for things like AdWords conversion.js script, it actually fires when a page becomes visible (so if you open in a new background tab and then close your browser without looking, that would not fire).

In any case, the script is going to get downloaded in between DOMContentLoaded and window.load in all likelihood, though it is possible that it could get loaded before the DOM is fully parsed and ready, so even that's not certain.

So the question is whether or not the Pageview metric fires as soon as the script downloads?

I assume it does and that only the User Timing metrics fire on specific events and get deferred post-load.