gpt4 book ai didi

php - Google API查询以获得访问范围?

转载 作者:行者123 更新时间:2023-12-02 05:20:15 24 4
gpt4 key购买 nike

我使用带有 JGoogleAPI 扩展的 Yii 框架,如下所示:

$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
);

如果我在 19 日有 10 次点击,20 日有 20 次点击,21 日有 30 次点击,则此查询为我提供:30 + 20 + 10 = 60。但是,我想要一个每天返回行的查询.

即,不是这个:

array[0] = 60

而是这个:

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

知道怎么做吗?

最佳答案

参见 Accessing Google Analytics with Google Client API and PHP tutorial

看起来您需要添加一些维度:

$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)
);

而且,如果您在 Query Explorer 中运行它,您会看到每一天的结果。

enter image description here

当然你可以只在日期前离开:

enter image description here

不确定为什么在您的示例中将 ga:visitsmax-results 指标设置为 1 并包含在 optParams 中。已经有指标的位置,如果需要,您可以在其中包含多个指标。

关于php - Google API查询以获得访问范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13988274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com