javascript - How to run a trackingscript after page is completely done loading? -


i try keep webpages rendering fast possible. wish wait running google analytics-code until else done. cause problems/caveats , best event listen when doing this?

$(document).ready $(window).load 

something else?

this google tacking code. renders javascript in turn makes http-request via tracking-pxiel.

//ga (function(i,s,o,g,r,a,m){i['googleanalyticsobject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new date();a=s.createelement(o), m=s.getelementsbytagname(o)[0];a.async=1;a.src=g;m.parentnode.insertbefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga');  ga('create', 'ua-xxxxxx-x', 'auto'); ga('send', 'pageview'); 

have considered doing asynchronous loading?
read here -> tracking basics (asynchronous syntax)


Comments