Google analytics API - 跟踪子域名 [英] Google analytics API - Tracking subdomains

查看:123
本文介绍了Google analytics API - 跟踪子域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,其中每个用户注册为子域名(username.domain.com)。
我用下面的代码跟踪所有子域名:

  var _gaq = _gaq || []; 
_gaq.push(['_ setAccount','UA-XXXXXX-X']);
_gaq.push(['_ setDomainName','.domain.com']);
_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);
})();

我想为使用GA API的每个用户显示自定义统计信息。
由于我只使用一个GA帐户来跟踪所有子域名,我如何过滤数据以便仅显示每个用户(子域名)的数据?



谢谢。

解决方案

setDomainName Google Analytics用于跟踪会话的Cookie。也就是说,按照您的设置进行设置,这样可以始终如一地跟踪这些子域名上的所有流量。



但是,这并不会更改发送的域数据Google Analytics(分析)。所有匹配都会通过网页浏览的主机名(JavaScript中的 document.domain )发送到Google Analytics。该值可在API <维护code> ga:主机名维度下访问。您可以将它用作查询的维度,或者将其用作数据的过滤器(即,只返回我查询此特定过滤器的数据)。
$ b $因此,无论 setDomainName 配置如何,您都可以使用Google Analytics API在子域级别访问和分段。


I have a website where each user registers as subdomain (username.domain.com). I'm tracking all subdomains with the folllowing code:

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXX-X']);
  _gaq.push(['_setDomainName', '.domain.com']);
  _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);
  })();

I want to show custom statistics for each user using the GA API. Since i'm using only one GA account for tracking all "subdomains", how can i filter the data in order to show only the data for each user (subdomain)?

Thanks.

解决方案

setDomainName is only relevant for the cookies that Google Analytics uses for tracking sessions. That is, setting it as you are makes it such that all traffic across those subdomains will be tracked consistently.

However, that doesn't change the domain data that gets sent to Google Analytics. All hits are sent to Google Analytics with the hostname (document.domain in JavaScript) of the pageview. That value is accessible in the API under the dimension ga:hostname. You can either use it as a dimension for a query, or use it as a filter for data (ie, say "only return the data I'm querying for this specific filter.)

So, regardless of the setDomainName configuration, you'll be able to access and segment on a subdomain level basis using the Google Analytics API.

这篇关于Google analytics API - 跟踪子域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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