简体   繁体   English

谷歌分析数据 API 的日期范围

[英]DateRanges for Google Analytics Data API

I have been successfully running a runRealtimeReport function from Google Analytics Data API, but I am currently struggling to run a runReport function.我已经成功地运行了来自 Google Analytics 数据 API 的 runRealtimeReport function,但我目前正在努力运行 runReport function。

Here is my code which I try to use:这是我尝试使用的代码:

$client->runReport([
                    'entity' => ['property_Id' => config('app.ga.propertyID')],
                    'dateRanges' => [new DateRange(['startDate' => '28daysago']),
                        new DateRange(['endDate' => 'today'])],
                    'dimensions' => [new Dimension([
                        'name' => 'sessionSource'
                    ])
                    ],
                    'metrics' =>[
                        [new Metric([
                            'name' => 'activeUsers'
                        ])],
                    [new Metric([
                        'name' => 'sessions'
                    ])],
                    [new Metric([
                        'name' => 'engagedSessions'
                    ])],
                    [new Metric([
                        'name' => 'userEngagementDuration'
                    ])],
                    [new Metric([
                        'name' => 'eventsPerSession'
                    ])],
                    [new Metric([
                        'name' => 'engagementRate'
                    ])]
                ]]);

No matter how I try to pass the values for DateRange, the API constantly fails and throws the following error:无论我如何尝试传递 DateRange 的值,API 都会不断失败并抛出以下错误:

Invalid message property: startDate

I am using an idiomatic PHP client for this我为此使用惯用的 PHP 客户端

You need to specify both the startDate and endDate in one Date Range.您需要在一个日期范围内同时指定 startDate 和 endDate。 As written, you've specified the startDate and endDate in two separate date ranges.如前所述,您已在两个单独的日期范围内指定了 startDate 和 endDate。 Please update to:请更新为:

'dateRanges' => [new DateRange(['start_date' => '28daysago',
                               'end_date' => 'today'])],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM