Original: http://www.aiuxian.com/article/p-1442657.html
1<!--get user behavior data (JS file external reference) five--2<script type= "Text/javascript" >3 var_uid = "${sessionscope.memberid}";//get user Membership ID4 var_oid = "${orderid}";//get user Order ID5(function() {//(function () {}) is the use of a closure, which is bound to be called. 6 7 varGA = document.createelement (' script '); 8Ga.type = ' Text/javascript '; 9ga.charset= ' GBK ';TenGa.async =true;//Ga.async = True asynchronously invokes an external JS file, that is, parsing without blocking the browser OneGA.SRC = ' Js/ana.js '; A vars = document.getelementsbytagname (' script ') [0];//gets the first element with the tag named script -S.parentnode.insertbefore (GA, s);//add element ga before S - })(); the</script>
1 /*2 * Generate UUID, user unique access Identity3 */4(function() {5Alert ("Asdf");6 //Private array of chars to use7 varCHARS = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '. Split (');8 9Math.uuid =function(len, radix) {Ten varchars = chars, uuid =[], I; OneRadix = Radix | |chars.length; A - if(len) { - for(i = 0; i < len; i++) uuid[i] = Chars[0 | Math.random () *Radix]; the}Else { - varR; -UUID[8] = uuid[13] = uuid[18] = uuid[23] = '-'; -UUID[14] = ' 4 '; + for(i = 0; i < i++;) { - if(!Uuid[i]) { +R = 0 | Math.random () *16; AUuid[i] = chars[(i = = 19)? (R & 0x3) | 0x8: R]; at } - } - } - returnUuid.join (' '); - }; -Math.uuidfast =function() { in varchars = chars, uuid =NewArray (Rnd=0),, R; - for(vari = 0; I < 36; i++) { to if(i==8 | | i==13 | | i==18 | | I==23) { +Uuid[i] = '-'; -}Else if(i==14) { theUuid[i] = ' 4 '; *}Else { $ if(Rnd <= 0x02) rnd = 0x2000000 + (math.random () *0x1000000) |;Panax Notoginsengr = Rnd & 0xf; -Rnd = Rnd >> 4; theUuid[i] = chars[(i = = 19)? (R & 0x3) | 0x8: R]; + } A } the returnUuid.join (' '); + }; - $Math.uuidcompact =function() { $ return' Xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx '. Replace (/[xy]/g,function(c) { - varR = Math.random () *16|0, v = c = = ' x '? R: (r&0x3|0x8); - returnV.tostring (16); the }); - };Wuyi })(); the - //======================================uuid=============================end Wu //page ID, which identifies a single page - varUrl=window.location.href; About $ varUrl_arr=url.split ("."); - - varId=url_arr[url_arr.length-2]; - A //Get member ID + var_memberid = _uid | | ‘‘; the - //Get Order ID $ var_orderid = _oid | | ‘‘; the the //User ID uuid the var_UTMB = $.cookie (' _UTMB ') | | ‘‘; the - //when the _UTMB value is empty, call Math.uuidfast in if(_utmb==NULL|| _utmb== ' Undefined ' | | _utmb== "){ the the_UTMB =math.uuidfast (); About the$.cookie (' _UTMB ', _UTMB); the the } + - //from which path to jump over the var_ref = Document.referrer | | ‘‘;Bayi the var_param = _ref.substring (_ref.indexof ("?")), _ref.length); the - varSTRs =_param.split (' & ')); - the varUtm_source= "; the the for(vari = 0; i < strs.length; i++) { the - if(Strs[i].indexof (' utm_source ')!=-1) { the theutm_source = strs[i].substring (strs[i].indexof (' = ') +1, strs[i].length); the 94 } the the } the 98 //judge that if the value of Utm_source is not empty, the path source is utm_source, otherwise the value _ref About if(utm_source!=NULL&&utm_source!= ' &&utm_source!= ' undefined ') { - 101_ref=Utm_source;102 103 }104 //get the page you are currently visiting the var_currenturl=document. URL | | ‘‘;106 107Alert ($.cookie (' _UTMC ' +id));108 //continuous Refresh to count requests in one second109 if($.cookie (' _UTMC ' +id)) { the 111 } the Else{113 the_UTMC = $.cookie (' _UTMC ' +id,true, {expires:1/24/60/60});//expires the cookie is valid for 1 seconds in days the //write, upload to background the varIMG =NewImage ();//Create an Image object117 118IMG.SRC = ' http://localhost:18080/ec-ga/behavior.img?_utmb= ' +_utmb+ "&_memberid=" +_memberid+ "&_orderid=" + _orderid+ "&_ref=" +_ref+ "&_currenturl=" +_currenturl;119 - Document.body.appendChild (IMG);121}
Code Analysis:
This code is not difficult to understand, there are several places I have to explain:
UUID, here I set it as user access unique identifiers, more information about the UUID, we are online check.
_UTMC, used to identify a period of time, if the user is constantly refreshed, we count the page request, so here we set the expiration date of the cookie
IMG, where we're abandoning the traditional Ajax send request, because Ajax can't send requests across domains, so we're using images as a way to send the data past.
Finally, don't forget to add two JS files, one jquery.js, one jquery.cookie.js
Web site user behavior data statistics and analysis one: Buried Point code design