嵌入式谷歌分析Javascript是如何工作的?

时间:2022-05-26 15:14:50

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

我只是想知道嵌入式谷歌分析Javascript是如何工作的?例如,他们如何计算你访问网站的时间?每次有人访问网站时,嵌入式Javascript都调用home吗?我只需要知道全局。

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>

1 个解决方案

#1


20  

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.

第一个脚本块创建一个脚本标记,用于下载ga。js从谷歌服务器。这个脚本收集关于网页、你和你的浏览器的数据,收集你从哪里来的信息(引用信息)等等。

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.

该脚本创建一个全局_gat对象。_gat上的一些方法(比如_trackPageview)生成一个_utm。每次加载谷歌的服务器时,都要发送gif请求。

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.

请求本身是谷歌获取估计位置(通过请求的IP地址)和浏览器(通过用户代理字符串,在请求头中发送)的方式。_utm。gif请求意味着脚本请求谷歌服务器上的1x1透明gif文件。每个请求都有附加在查询字符串中的所有信息。谷歌的服务器处理它们的请求日志,并使用关于该请求的信息来处理数据,并基于命中结果重构会话。

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

这个请求,例如*.com,看起来是这样的:

http://www.google-analytics.com/__utm.gif?utmwv=4.7.2&utmn=909339250&utmhn=*.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%2520*%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).

如果您在每个页面的底部安装了这个脚本,每当有人加载一个页面时,脚本就会嵌入,下载ga。js(可能被缓存),读取之前的cookie (utm前缀cookie),并将更新后的信息发送到谷歌的服务器(通过_utm)。gif请求)。

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.

如果你载入索引。html在12:00:00发送一个_utm。gif点击谷歌的服务器,然后在12:01:30加载。它推断你在index.html上花了1:30。这也意味着大多数会话在页面上有0秒的时间用于会话的最终页面视图。

#1


20  

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.

第一个脚本块创建一个脚本标记,用于下载ga。js从谷歌服务器。这个脚本收集关于网页、你和你的浏览器的数据,收集你从哪里来的信息(引用信息)等等。

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.

该脚本创建一个全局_gat对象。_gat上的一些方法(比如_trackPageview)生成一个_utm。每次加载谷歌的服务器时,都要发送gif请求。

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.

请求本身是谷歌获取估计位置(通过请求的IP地址)和浏览器(通过用户代理字符串,在请求头中发送)的方式。_utm。gif请求意味着脚本请求谷歌服务器上的1x1透明gif文件。每个请求都有附加在查询字符串中的所有信息。谷歌的服务器处理它们的请求日志,并使用关于该请求的信息来处理数据,并基于命中结果重构会话。

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

这个请求,例如*.com,看起来是这样的:

http://www.google-analytics.com/__utm.gif?utmwv=4.7.2&utmn=909339250&utmhn=*.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%2520*%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).

如果您在每个页面的底部安装了这个脚本,每当有人加载一个页面时,脚本就会嵌入,下载ga。js(可能被缓存),读取之前的cookie (utm前缀cookie),并将更新后的信息发送到谷歌的服务器(通过_utm)。gif请求)。

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.

如果你载入索引。html在12:00:00发送一个_utm。gif点击谷歌的服务器,然后在12:01:30加载。它推断你在index.html上花了1:30。这也意味着大多数会话在页面上有0秒的时间用于会话的最终页面视图。