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

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

问题描述

我只是想知道嵌入式 Google Analytics Javascript 是如何工作的?例如,他们如何计算您访问该网站的时间?每次有人访问网站时,嵌入式 Javascript 都会调用 home 吗?...我只需要知道大图

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

谢谢.

以下是如何工作的?

<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.该脚本收集有关网页、您和您的浏览器的数据,收集您来自何处的信息(推荐人信息)等.所有这些都是在每次点击时收集的.

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.

该脚本创建一个全局 _gat 对象._gat 上的某些方法(例如 _trackPageview)在每次加载时都会向 Google 的服务器发出 _utm.gif 请求.

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.

请求本身就是 Google 如何获取您的估计位置(通过请求的 IP 地址)和您的浏览器(通过您的用户代理字符串,在请求标头中发送)._utm.gif 请求意味着该脚本从 Google 的服务器请求一个 1x1 透明 gif 文件.每个请求都附加在查询字符串中的所有信息.Google 的服务器处理他们的请求日志,并使用有关该请求的信息来处理数据并根据命中重建会话.

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.

该请求(例如在 stackoverflow.com 上)如下所示:

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

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

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.

因此,如果您在 12:00:00 加载 index.html 并将 _utm.gif 命中发送到 Google 的服务器,然后在 12:01:30 加载 about.html,则推断您已经花费了1:30 在 index.html 上.这也意味着大多数会话将在页面上第二次 0 用于会话的最终浏览量.

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天全站免登陆