Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GA script just before the </body> tag 2

Status
Not open for further replies.

Pav1977

IS-IT--Management
Jul 5, 2006
59
GB
I remember reading somewhere that it somethimes displays wrong results if you place the stats script in header rather than at the end of body - is that true - if so why. I have it on my site and I think it works fine but I'm just interested to think about what case would it not work in?

Regards - help much appreciated as usally.
 
Purely because if the script is in the header then it is possible that the user will skip to a new page before the content has loaded.

This means that you are logging a visit to the page when there hasn't really been one (since it never loaded).

Putting the script at the end means it doesn't load until the content has loaded.


It's swings and roundabouts really. Neither method is going to be 100% accurate. I guess it's just preferable to know someone actually saw the page rather than knowing someone started to load it.



--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
You could get two accounts and put one at the top and one at the bottom of the page... then compare the reports after a while to see if there is any difference [smile]

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
There was a report released very recently that showed the effect of where the code was placed in GA and a number of other analytics programs.

I can't for the life of me find it now though.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
I suppose there's also the issue that the script is going to fire up GA and store whatever it's going to store, and the user has to wait till it's finished before continuing - better to do that after the page has loaded than to keep the visitor waiting.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Foamcow - have you found the article or are you just winding me up? ;)

ChrisHunt - well how long does it take a fraction of a second to send a few packets to the GA server? I'm not sure that is a valid point unless you have some data to prove that it can take at least a second.

Cheers
 
No I've not found it. No I'm not winding you up.


And to be fair, Chris's point is perfectly valid. You don't know whether the connection sending those few bytes will stall or not.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Of course I did find it after I typed "I've not found it".
doh!


--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top