obtain demographic data with google analytics api

情到浓时终转凉″ 提交于 2019-12-25 17:22:14

问题


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.


回答1:


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




回答2:


To be able to get age and gender informations from analytics, you should Enable Demographics and Interests reports on your GA account. doc : https://support.google.com/analytics/answer/2819948



来源:https://stackoverflow.com/questions/37488470/obtain-demographic-data-with-google-analytics-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!