ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

有人可以解释以下JavaScript正在做什么吗?

2019-07-23 16:36:12  阅读:144  来源: 互联网

标签:javascript google-analytics


这是在网站的脚本标签内.

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18914337-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);
})();

我不太熟悉Javascript或jQuery.我在一个网站上看到了这个,我想知道它做了什么……

解决方法:

您帖子中的代码是Google的分析跟踪代码.它不是jQuery,它是纯粹的JavaScript. Google在解释跟踪代码的功能方面做得很好.

Google文档资源

> What is Google Analytics
> Google Analytics Code Explained

来自Google的文档引用:

In general, the Google Analytics Tracking Code (GATC) retrieves web
page data as follows:

  1. A browser requests a web page that contains the tracking code.
  2. A JavaScript Array named _gaq is created and tracking commands are
    pushed onto the array.
  3. A element is created and enabled for asynchronous loading
    (loading in the background).
  4. The ga.js tracking code is fetched, with the appropriate protocol
    automatically detected. Once the code is fetched and loaded, the
    commands on the_gaq array are executed and the array is transformed
    into a tracking object. Subsequent tracking calls are made directly to
    Google Analytics.
  5. Loads the script element to the DOM.
  6. After the tracking code collects data, the GIF request is sent to
    the Analytics database for logging and post-processing.

标签:javascript,google-analytics
来源: https://codeday.me/bug/20190723/1515194.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有