本文介绍了开发人员与产品的Google Analytics(分析)标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上运行标准的Google Analytics(分析)跟踪代码(ga.js异步版本).我想知道是否可以添加一行js到跟踪代码中,以便我可以分离dev/prod数据?例如当我拉入代码库进行开发工作时,可以将标签设置为DEV.在重新投入生产时,DEV标签将被PROD标签取代.

I run a standard google analytics tracking code (ga.js asynch version) on a website. I am wondering if there is a line of js I can add to the tracking code so that I can segregate dev/prod data? e.g. when I pull in the codebase to do dev work, I can set the tag to DEV. When releasing back to production, DEV tag gets replaced with PROD tag.

这是否有可能,如果可以的话,我该如何实现呢?

Is this even possible and if so, how do i implement it?

我想到的一种方法就是创建一个新的属性"(它将生成一个新的ua号,我可以在开发过程中添加它,以便我可以分别对其进行跟踪.)

One method I thought of is just to create a new "property" (which would generate a new ua number, which I could add during dev. that would allow me to track it all separately.)

想知道我是否应该考虑其他方法.

Wondering if there are any other methods I should consider.

推荐答案

我不担心从开发服务器上收集数据,但是我想确保我不会污染我的生产数据-我已经一直使用以下内容的一些变体:

I'm not worried about collecting data from my development server, but I do want to make sure I'm not polluting my production data -- I've been using some variation of the following:

if (!/devServer|localhost/.test(window.location.hostname))
{
    _gaq.push(['_setAccount', 'UA-11111111-1']);
}

在devserver域(或在localhost)上,不会执行_setAccount,因此跟踪器默认为默认跟踪器UA-99999999-1.这样一来,您仍然可以查看通过ga_debug.js,chrome开发工具,firebug,fiddler等发送到分析服务器的跟踪数据,但不会针对您的生产配置文件进行注册.

On the devserver domain (or on localhost), _setAccount doesn't get executed, so the tracker defaults to the default tracker, UA-99999999-1. This allows you to still see tracking data being sent to the analytics servers (via ga_debug.js, chrome dev tools, firebug, fiddler, etc), but doesn't register against your production profiles.

缺点-这是在客户端上运行的额外代码.

Downsides -- it is an extra bit of code that get's run on the client.

如果您确实希望从开发服务器中进行分析,则可以尝试以下方法:

If you do want analytics from your development servers, you could try something like:

gaq.push(
    [ '_setAccount', 
      /devServer|localhost/.test(window.location.hostname) ? 'UA-11111111-1', 
    'UA-22222222-1']
);

这篇关于开发人员与产品的Google Analytics(分析)标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 04:36