Here's an example of 1 simpler ways to do this:
We used to save the statistics code to 1 files: File path:/config/counter.conf
The statistical code is as follows:
Copy Code code as follows:
<script type= "Text/javascript" >
var _gaq = _gaq | | [];
_gaq.push ([' _setaccount ', ' ua-18744406-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>
We use StreamReader to read the contents of the file, the code will not be listed in detail
We need a page to output this JavaScript code:
Page:/do.ashx?args=getcounter
Copy Code code as follows:
String code = "Read the statistic Code";
Code = Regex.Replace (Code, "[\]", "\");
Code = Regex.Replace (Code, "[\n\r]", "");
Context. Response.Write ("document.write (' +code+ ');");
This will be able to add the output of JavaScript to the page to implement the statistics function!
All we need to do is add the following code to the JavaScript file that the Web page references:
Copy Code code as follows:
var _s=document.createelement (' script ');
_s.type= ' Text/javascript ';
_s.src= '/do.ashx?args=getcounter ';
var _fs=document.getelementsbytagname ("script") [0];
_fs.parentnode.insertbefore (_S,_FS);
Done, the statistics code will not be displayed on your page, but in fact it has been loaded into your Web page!