doukanxi4246 2012-12-21 10:21
浏览 22
已采纳

Google API查询可获得多种访问?

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?

  • 写回答

1条回答 默认 最新

  • dougua3705 2012-12-25 18:13
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数