在Google Analytics(分析数据API)中获取空行

发布于 2025-01-25 17:24:21 字数 971 浏览 1 评论 0 原文

很难从分析数据API(GA4)beta中获得空行。我正在按日期数组来拉动简单的流量,但是任何零流量的日期都不会返回 - 我希望它给我日期和零。

我相信应该有一个keepemptrows参数,但这似乎不起作用 - 我花了很长时间才能完成订单工作,以至于我以为我会首先检查这里,看看其他人是否有此功能。我知道我可以使用PHP代码填写缺失的日期,但我更喜欢从查询中获取它。这是我的JSON查询的PHP:

$response = $client->runReport([
'property' => 'properties/' . $_SESSION["gaid"],
'dateRanges' => [
    new DateRange([
        'start_date' => $mstartdate,
        'end_date' => $menddate,
    ]),
],
'dimensions' => [new Dimension(
    [
        'name' => 'date',
    ]
),
],
'metrics' => [new Metric(
    [
        'name' => 'activeUsers',
        'name' => 'sessions',
    ]
)
],
'orderBys' => [
    new OrderBy([
        'dimension' => new OrderBy\DimensionOrderBy([
            'dimension_name' => 'date',
            'order_type' => OrderBy\DimensionOrderBy\OrderType::ALPHANUMERIC
        ]),
        'desc' => false,
    ])],
    'keepEmptyRows'=>"1"

]);

提前致谢 :)

Having difficulty getting empty rows from the Analytics Data API (GA4) BETA. I'm pulling simple traffic by date array but any dates that have zero traffic are not returned - I would prefer it to give me the date and zero.

I believe there should be a KEEPEMPTYROWS parameter but this doesn't seem to work - it took me so long to get the ORDERBY working that I thought I'd check here first to see if anyone else has got this working lol. I know I can fill in the missing dates using PHP code but I'd prefer to get it from the query. Here's the PHP for my JSON query:

$response = $client->runReport([
'property' => 'properties/' . $_SESSION["gaid"],
'dateRanges' => [
    new DateRange([
        'start_date' => $mstartdate,
        'end_date' => $menddate,
    ]),
],
'dimensions' => [new Dimension(
    [
        'name' => 'date',
    ]
),
],
'metrics' => [new Metric(
    [
        'name' => 'activeUsers',
        'name' => 'sessions',
    ]
)
],
'orderBys' => [
    new OrderBy([
        'dimension' => new OrderBy\DimensionOrderBy([
            'dimension_name' => 'date',
            'order_type' => OrderBy\DimensionOrderBy\OrderType::ALPHANUMERIC
        ]),
        'desc' => false,
    ])],
    'keepEmptyRows'=>"1"

]);

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃兔兔 2025-02-01 17:24:21

对于任何寻找答案的人,该选项称为“ keepementyrows”:

$client = new BetaAnalyticsDataClient(['credentials' => ...]);
$response = $client->runReport([
    ...
    'keepEmptyRows' => true,
]);

来源:

不幸的是,它无法正常工作。

我要求提供7天的报告,每7行,每行包含0(以前UA都这样工作)。
相反,我有0s。

此处也提到了这个问题:
https://github.com/google/google/site-kit-kit-wp/issues/- 6623

最后,在应用来自GA的更改之前,我最终用默认数据对数组进行了预填充数组。

For anyone else looking for an answer, the option is called "keepEmptyRows":

$client = new BetaAnalyticsDataClient(['credentials' => ...]);
$response = $client->runReport([
    ...
    'keepEmptyRows' => true,
]);

Source:
https://github.com/googleapis/php-analytics-data/blob/master/src/V1beta/RunReportRequest.php#L642

Unfortunately, it does not work as expected.

I was asking for a 7 day report, expecting each 7 rows, each containing 0s (previously UA was working like that).
Instead I got single row with 0s.

This problem is also mentioned here:
https://github.com/google/site-kit-wp/issues/6623

In the end, I ended up pre-filling the array with the default data before applying changes that come from GA.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文