Google Analytics:_setvar 为新的跟踪代码

发布于 2024-10-30 20:58:10 字数 309 浏览 1 评论 0原文

我一直在使用旧版本的分析代码,并使用以下代码来跟踪不同类型的用户,

<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxxx");
pageTracker._setVar('memberlevel-2');    pageTracker._trackPageview();
} catch(err) {}</script>

如何将其与新的异步代码一起使用?谷歌分析论坛已经死了,我没有得到任何回应:(

I have been using the older version of analytics code and used the following to track different types of users

<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxxx");
pageTracker._setVar('memberlevel-2');    pageTracker._trackPageview();
} catch(err) {}</script>

How do I use this with the new asynchronous code? Google Analytics forums is dead and i got no response :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

長街聽風 2024-11-06 20:58:10

尝试阅读此内容以设置自定义变量:

http://code.google.com /apis/analytics/docs/tracking/gaTrackingCustomVariables.html

跟踪页面浏览量的示例代码:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _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);
  })();
</script>

Try reading this for setting custom variable:

http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html

Sample code for to track page view:

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _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);
  })();
</script>
溺ぐ爱和你が 2024-11-06 20:58:10

_setVar 仍然有效,但您应该使用 _setCustomVar 来代替,因为它更强大。

这是使用异步代码的旧代码的样子:

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_setVar', 'memberlevel-2']); 
  _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);
  })();

要使用 setCustomVar,您可以这样做:

  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_setCustomVar', 1, 'memberlevel', '2', 3]);// page-level scope (3), in slot #1
  _gaq.push(['_trackPageview']);

_setVar still works, but you should use _setCustomVar instead, as its more powerful.

Here's what your old code looks like using the async code:

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_setVar', 'memberlevel-2']); 
  _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);
  })();

To use setCustomVar instead, you could do this:

  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_setCustomVar', 1, 'memberlevel', '2', 3]);// page-level scope (3), in slot #1
  _gaq.push(['_trackPageview']);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文