嵌入式Google Analytics Javascript如何工作? [英] How does the embedded Google Analytics Javascript work?

查看:120
本文介绍了嵌入式Google Analytics Javascript如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道嵌入式Google Analytics Javascript是如何工作的一般想法?例如,他们如何计算您访问该网站的时间?每次有人访问某个网站时,嵌入式Javascript是否会调用回家?...我只需要知道大图的内容。b / b

谢谢。

编辑:以下是如何工作的?

 < script type =text / javascript> 
var gaJsHost =((https:== document.location.protocol)?https:// ssl。:http:// www。);
document.write(unescape(%3Cscript src ='+ gaJsHost +google-analytics.com/ga.js'type ='text / javascript'%3E%3C / script%3E));
< / script>
< script type =text / javascript>
var pageTracker = _gat._getTracker(UA-xxxxxx-x);
pageTracker._trackPageview();
< / script>


解决方案

第一个脚本块创建一个脚本标记,来自Google服务器的ga.js。该脚本收集关于网页,你和你的浏览器的数据,收集你从哪里来的信息(引用者信息)等等。所有这些都是在每次点击时收集的。

该脚本创建一个全局 _gat 对象。 _gat (如 _trackPageview )上的一些方法使 _utm.gif 请求本身就是Google如何通过请求IP地址和您的浏览器(通过您的用户代理字符串,通过请求标头发送)获取您的估计位置。 _utm.gif 请求表示该脚本向Google服务器请求1x1透明gif文件。每个请求都包含查询字符串中附加的所有信息。 Google的服务器处理他们的请求日志,并使用关于该请求的信息来处理数据并根据命中数据重建会话。


$ b

例如在stackoverflow.com上的请求如下所示:

  http://www.google-analytics.com/__utm.gif?utmwv=4.7.2&utmn=909339250&utmhn=stackoverflow.com&utmcs=UTF-8&utmsr=1920x1080&utmsc=24-bit& ; utmul = EN-US&安培; utmje = 1&安培; utmfl = 10.1%20r82&安培; utmdt =最新%20'google-分析%20Questions%20-%20Stack%20Overflow&安培; utmhid = 456625342&安培; utmr = 0&安培; UTMP =%2Fquestions% 2Ftagged%2Fgoogle-分析&安培; utmac = UA-5620270-1&安培; utmcc = __ UTMA%3D140029553.1672509655.1273785261.1282328140.1282335818.167%3B%2B__utmz%3D140029553.1282158995.159.95.utmcsr%3Dgoogle%7Cutmccn%3D(有机)%7Cutmcmd%3Dorganic %7Cutmctr%3Dforce%2520download%2520image%2520in%2520php%2520stackoverflow%3B& gaq = 1 

如果你在每个页面的底部安装了这个脚本,每当有人加载脚本将嵌入的页面,下载 ga.js (可能会被缓存),请阅读以前的cookie(utm pref ixed cookies),并将更新后的信息发送给Google的服务器(通过 _utm.gif 请求)。

现场计算时间非常零星;它会根据您的浏览推断页面上的时间。

因此,如果您在12:00:00加载index.html并将_utm.gif点击发送给Google服务器,然后在12:01:30发送给您加载about.html,它会推断您已经在index.html上花费了1:30。这也意味着大多数会话将在会话的最后一次浏览页面上第二次显示 0


I was just wondering the general idea how the embedded Google Analytics Javascript works? Example, how do they calculate how long you been visiting the site? Does the embedded Javascript calls home every time someone visit a site?... I just need to know the big picture

Thanks.

Edit: how does the following work?

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
</script>

解决方案

The first script block creates a script tag, which downloads ga.js from Google's servers. That script gathers data about the webpage, you, and your browser, collecting information from where you came from (referrer information), etc. All of this is collected on every hit.

The script creates a global _gat object. Some methods on _gat (like _trackPageview) make a _utm.gif request to Google's server every time they're loaded.

The request itself is how Google gets your estimated location (via the requesting IP address) and your browser (via your user agent string, sent in the request headers). A _utm.gif request means that the script requests a 1x1 transparent gif file from Google's servers. Each request has all of the information appended within the query string. Google's servers process their request logs and use the information about that request to process the data and reconstruct the session based on the hits.

That request, for example on stackoverflow.com, looks like this:

http://www.google-analytics.com/__utm.gif?utmwv=4.7.2&utmn=909339250&utmhn=stackoverflow.com&utmcs=UTF-8&utmsr=1920x1080&utmsc=24-bit&utmul=en-us&utmje=1&utmfl=10.1%20r82&utmdt=Newest%20'google-analytics'%20Questions%20-%20Stack%20Overflow&utmhid=456625342&utmr=0&utmp=%2Fquestions%2Ftagged%2Fgoogle-analytics&utmac=UA-5620270-1&utmcc=__utma%3D140029553.1672509655.1273785261.1282328140.1282335818.167%3B%2B__utmz%3D140029553.1282158995.159.95.utmcsr%3Dgoogle%7Cutmccn%3D(organic)%7Cutmcmd%3Dorganic%7Cutmctr%3Dforce%2520download%2520image%2520in%2520php%2520stackoverflow%3B&gaq=1

If you installed this script at the bottom of every page, every time someone loads a page the script will embed, download ga.js (which is likely to be cached), read the previous cookies (utm prefixed cookies), and send the updated information to Google's servers (via the _utm.gif request).

The calculation of time on site is pretty piecemeal; it deduces time on page based on your browsing.

So, if you load index.html at 12:00:00 and send a _utm.gif hit to Google's server, and then at 12:01:30, you load about.html, it deduces that you've spent 1:30 on index.html. This also means that most sessions will have a 0 second time on page for the final pageview of the session.

这篇关于嵌入式Google Analytics Javascript如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆