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

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

问题描述

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



在我的分析代码中,我有这些行。第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部分:

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

如何将gaq.push转换为2部分并添加到我的通用分析代码?

解决方案

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

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



Google目前建议除了当前的ga.js代码之外,还要设置analytics.js代码。一旦你对基础数据在两者之间排队感到高兴,你可以在你的页面上保留两个版本,或者决定删除旧的ga.js代码。旧配置文件中的历史数据仍然存在,但不会绑定到新的网络媒体资源。我不知道Google是否最终会为现有基于ga.js的网络媒体资源提供升级或转换功能;到目前为止,我还没有看到他们是否会提供这方面的消息。



转到Universal Analytics(analytics.js)代码...

Universal Analytics不使用 .push 语法。相反,它有一个函数 ga(),它需要将参数传递给它。第一个参数是command参数,其他参数用于传递基于命令的其他设置,值等。


  • 设置GA账户现在已经通过'create'命令完成了

  • 跟踪页面视图现在通过'send'命令完成

  • 设置一个自定义变量*现在可以作为'send'命令中的一个参数来完成(仅在'send'命令中弹出它),或者使用'set'命令(用于将它设置为弹出所有'send'在这个页面上执行的命令)..但是关于这个...



自定义变量不再存在



他们这样做,但他们如何实施是不同的。 Universal Analytics提供自定义维度和指标。自定义变量大多数是现在的自定义维度。主要区别在于,设置变量的名称和范围等内容现在在GA界面中完成,而不是作为函数的参数。此外,你现在有5个以上的工作。要进行设置,请点击您创建的网络媒体资源,然后您应该看到标签



个人资料跟踪..自定义



点击自定义标签以设置您的自定义维度和指标。



现在进入页面代码



这就是等效您发布的代码看起来像:

第一个片段:

 <! -  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>
<! - 结束Google Analytics - >

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

第二个片段:

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

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

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.

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

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

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

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

解决方案

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

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 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.

Moving on to Universal Analytics (analytics.js) code ...

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.

  • setting the GA account is now done with the 'create' command
  • tracking a page view is now done with with the 'send' command
  • setting a custom variable* is now done as either an argument in the 'send' command (for only popping it on that 'send' command), or with the 'set' command (for setting it to be popped with all 'send' commands executed on the page)..but about this...

Custom Variables no longer exist

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

Profiles Tracking ..Custom Definitions

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

Now on to the page code

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

First snippet:

<!-- 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 -->

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.

Second snippet:

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

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