使用Google Analytics(分析)API获取人口统计数据 [英] obtain demographic data with google analytics api
问题描述
如果是,是否有人知道教程或其他内容?我使用了提供的示例,并且获得了过去7天中的一些会话.但是除此之外.如果这不可能,那么我可以使用此api获得什么样的东西?
这是我尝试过的:
function getResults(&$analytics, $profileId) {
return $analytics->data_ga->get(
'ga:' . $profileId,
'7daysAgo',
'today',
'ga:sessions');
}
提前谢谢.
您可以获取维度和指标参考.其中包括用于人口统计信息的ga:userAgeBracket和ga:userGender.
要包括其他指标(数字数据),请将其作为参数添加到现在具有ga:sessions(用逗号分隔多个指标)的位置.您需要至少一个指标才能使查询正常工作.
要添加维度(即分类数据),您需要将选项数组传递给具有维度键/值对的查询.这可能还包括其他选项,例如过滤器或排序选项,最好从当前版本(v4)开始.
im trying to obtain some demographic data from the google analytics api, my intention is to integrate this on a cms to generate reports, etc... is this possible?
if it is, is there someone who knows a tutorial or something? i have used the examples provided and i get some sessions that have been in the last 7 day period. But nothing besides that. If that is not possible, what kind of things i can obtain with this api?
here is what i have tried:
function getResults(&$analytics, $profileId) {
return $analytics->data_ga->get(
'ga:' . $profileId,
'7daysAgo',
'today',
'ga:sessions');
}
thanks in advance.
You can obtain everything that's listed in the Dimensions and Metrics Reference. This includes ga:userAgeBracket and ga:userGender for demographic information.
To include additional metrics (numerical data) you put it as a parameter where you now have ga:sessions (separate multiple metrics with a comma). You need at least one metric for a query to work.
To add dimensions (i.e. categorical data) you need to pass an options array to your query that has a key/value pair for dimensions. This may also include additional options like filters or sort options, see the example here..
$optParams = array(
'dimensions' => 'ga:userAgeBracket,ga:userGender'
);
return $analytics->data_ga->get(
'ga:' . $profileId,
'7daysAgo',
'today',
'ga:sessions',
$optParams
);
This for version 3 of the API. If you are just getting started an have no legacy code to maintain you might as well start with there current version (v4).
这篇关于使用Google Analytics(分析)API获取人口统计数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!