简体   繁体   English

Google Analytics 4 Data API 使用顺序

[英]Google Analytics 4 Data API use order by

I started using Google Analytics 4 Data API and downloaded the PHP library to create the requests.我开始使用 Google Analytics 4 Data API 并下载了 PHP 库来创建请求。 I have been playing a little and my request is working good so far, but when I need to sort it I don't know exactly how to pass that data, I have been trying many ways but no luck.我一直在玩一点,到目前为止我的请求运行良好,但是当我需要对其进行排序时,我不知道如何确切地传递该数据,我一直在尝试多种方法但没有运气。

Check "orderBys" data, there I supposed to pass orderType and dimensionName to filter by dimensions date so it should be something like "ordertype" => ALPHANUMERIC and "dimensionName => "date"检查“orderBys”数据,我应该通过orderType和dimensionName来按维度日期过滤,所以它应该类似于“ordertype”=> ALPHANUMERIC“dimensionName =>“date”

Any tip would be much appreciated :)任何提示将不胜感激:)

$response = $client->runReport([
          'property' => 'properties/' . $property_id,
          'dateRanges' => [
              new DateRange([
                  'start_date' => '7daysAgo',
                  'end_date' => 'yesterday',
              ]),
          ],
          'dimensions' => [new Dimension(
              ['name' => 'day']
          ),
          ],
          'metrics' => [

            new Metric(['name' => 'newUsers']),

            new Metric(['name' => 'active7DayUsers']),
          
          ],

          'orderBys' => [],
      ]);

This works for me:这对我有用:

Note that is used the V1beta package请注意,使用的是V1beta

use Google\Analytics\Data\V1beta\BetaAnalyticsDataClient;


$response = $client->runReport([

    // ...

    'orderBys' => [
        new OrderBy([
            'dimension' => new OrderBy\DimensionOrderBy([
                'dimension_name' => 'month', // your dimension here
                'order_type' => OrderBy\DimensionOrderBy\OrderType::ALPHANUMERIC
            ]),
            'desc' => false,
        ]),
    ],
]);

I had similar struggle, the documentation is really bad.我也有过类似的挣扎,文档真的很糟糕。

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

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