Google Universal Analytics 自定义维度和trackpageview [英] Google Universal Analytics custom dimensions and trackpageview

查看:34
本文介绍了Google Universal Analytics 自定义维度和trackpageview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Google 旧版 Analytics 迁移到 Universal Analytics.我在下面和 通用 - 开发人员指南中有代码我找不到解决方案.

I'm trying to migrate from Google old Analytics to Universal Analytics. I have code below and from universal - developers guide I couldn't find solution.

在我的分析代码中,我有这些行.第 1 部分:

Inside my analytics code I had these lines. Part 1:

 var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-123456-1']);

     _gaq.push(['_trackPageview','/tools/one');
     _gaq.push(['_setCustomVar', 1, 'name', 'michael', 1]);

(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);
    })();

也在我的其他一些脚本中,我有这个代码片段.第 2 部分:

Also inside my some other script I have this code snippet. Part 2:

if (typeof _gaq !== "undefined" && _gaq !== null) {
    _gaq.push(['_trackPageview', '/dosomework']);
}

如何将gaq.push"分成两部分并添加到我的通用分析代码中?

How can I convert "gaq.push"s inside 2 parts and add to my universal analytics code ?

推荐答案

不幸的是,迁移到 analytics.js 并不像更改代码语法那么简单.

Unfortunately, migrating to analytics.js isn't as simple as just changing the code syntax.

首先,您应该知道 Universal Analytics 目前处于公测阶段.目前,谷歌不提供升级"或转换"现有网络资产以利用通用分析 (analytics.js) 跟踪的方法.您需要设置一个新的网络媒体资源(或新帐户)并选中通用分析"单选按钮.

Firstly you should know that Universal Analytics is currently in open beta phase. Currently google does not offer a way to "upgrade" or "convert" an existing web property to take advantage of universal analytics (analytics.js) tracking. You will need to setup a new web property (or new account) and check the "universal analytics" radio button.

Google 目前建议设置analytics.js 代码除了您当前的ga.js 代码.一旦您对基本数据在两者之间排列感到满意,您就可以在页面上保留两个版本,也可以决定删除旧的 ga.js 代码的日期.您旧配置文件中的历史数据仍然存在,但不会与新的网络媒体资源相关联.我不知道 Google 最终是否会为现有的基于 ga.js 的网络资产提供升级"或转换"功能;到目前为止,我还没有看到任何关于他们是否/何时会提供这个的消息.

Google currently recommends setting up analytics.js code in addition to your current ga.js code. Once you are happy that the base data is lining up between the two, you can either keep both versions on your page or decide on a date to remove the old ga.js code. The historical data in your old profile will still be there but it won't be tied to the new web property. I don't know if Google will eventually offer an "upgrade" or "convert" feature for existing ga.js based web properties; so far I have not seen any news on if/when they will offer this.

继续使用 Universal Analytics (analytics.js) 代码......

Universal Analytics 不使用 .push 语法.相反,它有一个函数 ga() 需要将参数传递给它.第一个参数是命令"参数,附加参数用于根据命令传递附加设置、值等.

Universal Analytics does not use the .push syntax. Instead, it has a function ga() that requires arguments to be passed to it. The first argument is the "command" argument, and the additional arguments are for passing additional settings, values, etc. based on the command.

  • 现在使用创建"命令设置 GA 帐户
  • 现在使用发送"命令跟踪页面浏览量
  • 设置自定义变量*现在可以作为'send'命令中的参数(仅在该'send'命令上弹出它)或使用'set'命令(用于设置它与所有在页面上执行的发送"命令)..但是关于这个......

自定义变量不再存在

嗯,它们确实如此,但它们的实现方式不同.Universal Analytics 提供自定义维度和指标.自定义变量现在主要是自定义维度.主要区别在于,变量的名称和范围等设置现在是在 GA 接口中完成的,而不是作为函数的参数.此外,您现在可以使用 5 个以上的工具.要进行设置,请点击您创建的网络媒体资源,您应该会看到标签

Well they do, but how they are implemented is different. Universal Analytics offers custom dimensions and metrics. Custom Variables are mostly what Custom Dimensions now are. The main difference is that setting things like the name and scope of the variable is now done within the GA interface instead of as an argument to the function. Also, you get more than 5 to work with now. To set this up, click on the web property you created, and you should see tabs

个人资料跟踪..自定义定义

点击Custom Definitions 标签,在那里设置您的自定义维度和指标.

Click on the Custom Definitions tab to setup your custom dimensions and metrics there.

现在进入页面代码

这就是您发布的代码的等效":

This is what the "equivalent" of the code you posted would look like:

第一个片段:

<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-123456-1');
ga('send', 'pageview', '/tools/one');
ga('set', 'dimension1', 'michael');

</script>
<!-- End Google Analytics -->

注意: 如上所述,您将在界面中设置维度的名称和范围.'dimension1' 应该更改为您创建的任何维度#.

note: as mentioned above, you would set the name and scope of the dimension within the interface. 'dimension1' should be changed to whatever dimension# you created.

第二个片段:

if (typeof ga == 'function') {
    ga('send', 'pageview', '/dosomework');
}

旁注:与您的问题并不真正相关,但在您的代码中,您首先发送页面视图,然后设置自定义变量.如果您不知道,如果您在页面视图 (_trackPageview) 之后设置自定义变量 (_setCustomVar),您的自定义变量将不会随该页面视图一起发送('/tools/one' 命中).它将(假设您的第二个片段稍后弹出)与第二个页面视图('/dosomework' 一个)一起发送.不知道为什么你会有两个单独的综合浏览量,或者你是否知道操作顺序,但如果你对当前报告中的内容感到满意..analytics.js 版本的行为方式相同.

sidenote: Not really related to your question, but in your code you first send a page view and then set the custom variable. In case you didn't know, if you set the custom variable (_setCustomVar) after the page view (_trackPageview), your custom variable will not be sent with that page view (the '/tools/one' hit). It will (assuming your 2nd snippet gets popped later on) be sent along with that 2nd page view (the '/dosomework' one). Not sure why you would have two separate pageviews or if you knew about that order of operations thing but if you're happy with how things currently look in the reports..well the analytics.js version will behave the same way.

这篇关于Google Universal Analytics 自定义维度和trackpageview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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