解释 Google Analytics 异步跟踪器 [英] Explaining Google Analytics async tracker

查看:37
本文介绍了解释 Google Analytics 异步跟踪器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 google 的异步分析跟踪器的工作原理有所了解.以下代码用于初始化命令数组:

I have a as to how google's async analytics tracker works. The following code is used to init a command array:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(
    ['_setAccount', 'UA-xxxxxxxx-x'],
    ['_trackPageview']
  );
</script>

现在,这是一个标准数组,一旦加载 GA 的代码就会被替换,并用作一种存储点击的队列.

Now, this is a standard array that gets replaced once the GA's code is loaded and is used as a sort of queue that stores your clicks.

我的困惑在于想知道如果用户单击导致重新加载的链接(在加载 GA javascript 之前),这些点击如何可能会持续存在.如果 GA 代码没有捕获到 _gaq 对象上的推送,那么用户单击一个链接并转到一个新页面,这个数组每次都只是重新初始化,不是吗?

My confusion lies in wondering how these clicks could possibly be persisted if a user clicks a link that causes a reload (prior to the GA javascript being loaded). If the GA code hasn't captured that push on the the _gaq object, then the user clicks a link and goes to a new page, this array is just re initialized each time no?

javascript 变量不会在导致刷新的请求中持续存在,这不是真的吗?如果是这种情况,我们是不是就失去了导致页面重新加载的原始点击?

Isn't it true that a javascript variable will not persist across requests that cause a refresh? If this is the case, haven't we then lost that original click that caused the page reload?

非常感谢任何解释.

推荐答案

是的,如果用户在 ga.js 加载并执行 __utm.gif 请求到 Google 的服务器之前点击离开站点,这是正确的,那么它将不会跟踪 _gaq 数组并且该信息将永远消失.但是这个版本的代码仍然比旧的同步代码提供了很多好处.

Yes, you're right that if the user clicks away from the site before ga.js has loaded and has executed the __utm.gif request to Google's servers, then it will not track the _gaq array and that information is gone forever. But this version code still provides many benefits over the older synchronous code.

首先,使用这种方法加载ga.js是阻塞的.

First, the loading of ga.js using this method is not blocking.

巧妙地,ga.js 的加载是通过 JavaScript 间接注入的,而不是通过硬编码的

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