see a lot of Web source code has the following:
<script type= "Text/javascript" >
var _gaq = _gaq | | [];
_gaq.push ([' _setaccount ', ' ua-16407365-1 ']);
_gaq.push ([' _trackpageview ']);
(function () {
var ga = document.createelement (' script '); ga.type = ' text/javascript '; ga.async = true;
ga.src = (' https: ' = = Document.location.protocol? ' Https://ssl ': ' http://www ') + '. Google-analytics.com/ga.js ';
var s = document.getelementsbytagname (' script ') [0]; S.parentnode.insertbefore (GA, s);
})();
</script>
meaning: Google Analytics ga tracking code, a section of JS code. is used for web tracking, the code to the Web page, when the page is requested, the Google server will send back the corresponding cookie data, and then form a report.
Code Analysis:
var _gaq = _gaq | | [];//defines an array that, if _gaq is not empty, takes its own value, otherwise it is initialized to null
_gaq.push ([' _setaccount ', ' ua-16407365-1 ']);//push method adds 2 string elements to the array _setaccount ' and ' ua-16407365-1 '
(function () {}) is a closure usage, and a lot of it is important in JavaScript, so you can learn about it and the closure is bound to be called.
var ga = document.createelement (' script '); ga.type = ' text/javascript '; Ga.async = true;//Creates a SCRIPT element, Script type is javasceipt, asynchronous type
ga.src = (' https: ' = = Document.location.protocol? ' Https://ssl ': ' http://www ') + '. Google-analytics.com/ga.js ';//Set the source code for this script is Ga.js
var s = document.getelementsbytagname (' script ') [0];//Get the first element with tag named script, the so-called tag name is the type name of each element in HTML, such as DIV,IMG, etc.
S.parentnode.insertbefore (GA, s);//add element GA before S
Google web tracking code--Notes