2

I use the Yii framework with the JGoogleAPI extension as follows:

$service = Yii::app()->JGoogleAPI->getService('Analytics');
$optParams = array(
 'metrics' => 'ga:visits',
 'max-results' => '1'
);

$gaData = 
  $service->data_ga->get( 
    'ga:XXXXXXX',
    '2012-12-19',
    '2012-12-21',
    'ga:visits',
    $optParams
  );

If I had 10 hits on the 19th, 20 hits on the 20th, and 30 hits on the 21st, this query gives me: 30 + 20 + 10 = 60. However, I want ONE query that returns rows for each day.

Ie, not this:

array[0] = 60

But rather this:

array[0] = 10
array[1] = 20
array[2] = 30

Any idea how to do that?

4

1 回答 1

5

See Accessing Google Analytics with Google Client API and PHP tutorial

Looks like you need to add some dimensions:

$dimensions = 'ga:date,ga:year,ga:month,ga:day';

$gaData = 
  $service->data_ga->get( 
    'ga:XXXXXXX',
    '2012-12-19',
    '2012-12-21',
    'ga:visits',
    array('dimensions' => $dimensions)
  );

And, if you run it in the Query Explorer, you'll see a result for each day.

enter image description here

Of course you could leave in just the date:

enter image description here

Not sure why the metric of ga:visits and max-results is set to one in your example and included in the optParams. There is already a place for metrics and you can include multiple metrics there if you want.

于 2012-12-25T18:13:14.127 回答