Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
226 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...