Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analitycs API get data with dimensions

I work with Google Analitycs API. I want to get all sessions for last 7 days per day like this in only one API call:

[day 1] -> 10

[day 2] -> 100 ...

I use this:

$service->data_ga->get('ga:'.$profile['id'],'7daysAgo','today','ga:sessions');

It works fine but return the sum. I've checked with https://ga-dev-tools.appspot.com/query-explorer/ and for me needed i should add metrics ga:date so the date to be individualy per day not all.

I've tried to add metrics at the end of line:

$service->data_ga->get('ga:'.$profile['id'],'7daysAgo','today','ga:sessions','ga:date');

I got this error:

Uncaught exception 'Google_Exception' with message '(get) missing required param: 'start-date'' in

like image 318
Codeokay Avatar asked Feb 05 '23 14:02

Codeokay


1 Answers

The answer is this:

$SecondaryParams = array('dimensions' => 'ga:date');

$results = $service->data_ga->get('ga:'.$profile['id'],
                                  '7daysAgo',
                                  'today',
                                  'ga:sessions',   
                                   $SecondaryParams);

Send dimensions as array.

like image 119
TheBosti Avatar answered Feb 08 '23 05:02

TheBosti