Google Website Optimiser Control Javascript -
could explain javascript makes google's website optimiser control script? specifically: first 2 lines, seem empty functions, , why third function wrapped parentheses () ?
as far can tell script writing out new <script>
presumably loads a/b testing.
function utmx_section(){} function utmx(){} (function() { var k='0634742331',d=document,l=d.location,c=d.cookie; function f(n) { if(c) { var i=c.indexof(n+'='); if (i>-1) { var j=c.indexof(';',i); return escape(c.substring(i+n.length+1,j<0?c.length:j)) } } } var x=f('__utmx'),xx=f('__utmxx'),h=l.hash; d.write('<sc'+'ript src="'+'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com'+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new date().valueof()+(h?'&utmxhash='+escape(h.substr(1)):'')+'" type="text/javascript" charset="utf-8"></sc'+'ript>') } )();
i've attempted step through firebug debugger doesn't seem it. insights appreciated.
many thanks
inside anonymous function shortens names of document , cookies inside @ first, function f(n)
gets value of cookie under name n
. google reads cookies , of d.write
loads scripts (as see related google analytic). way makes on-demand javascript loading... load these scripts time, google needs additional parameters in url, done way - save parameters in cookie, next time used script again.
and first 2 magic lines :) after google loads script (after executing d.write
), there functions uses utmx
, utmx_section
, definition of these functions, or better overriding. think empty @ first because function can execute before real definition, , having empty functions nothing happen (and no js error), otherwise script not work. e.g. after first iteration there data, used make real definition of these functions , starts work :)
Comments
Post a Comment