2

我正在使用报告 API 的 v4 版本,并且有一个函数可以构建我想要的报告。我面临的唯一问题是找到一种方法来从另一个函数中获取报告的日期。

function getReport($analytics, $start_date, $end_date) {

            // Replace with your view ID, for example XXXX.
            $VIEW_ID = "XXXXXXX";

            // Create the DateRange object.
            $dateRange = new Google_Service_AnalyticsReporting_DateRange();
            $dateRange->setStartDate("$start_date");
            $dateRange->setEndDate("$end_date");

            // Create the Metrics object.
            $transactionRevenue = new Google_Service_AnalyticsReporting_Metric();
            $transactionRevenue->setExpression("ga:transactionRevenue");
            $transactionRevenue->setAlias("Revenue");

            $transID = new Google_Service_AnalyticsReporting_Dimension();
            $transID->setName('ga:transactionId');
            $campaign = new Google_Service_AnalyticsReporting_Dimension();
            $campaign->setName('ga:campaign');
            $date = new Google_Service_AnalyticsReporting_Dimension();
            $date->setName('ga:date');

            $camFil = new Google_Service_AnalyticsReporting_DimensionFilter();
            $camFil->setDimensionName('ga:campaign');
            $camFil->setExpressions(array('.*[^0-9].*'));
            $camFil->setOperator('REGEXP');

            $dimensionFilterClause = new Google_Service_AnalyticsReporting_DimensionFilterClause();
            $dimensionFilterClause->setOperator('AND');
            $dimensionFilterClause->setFilters(array($camFil));

            // Create the ReportRequest object.
            $request = new Google_Service_AnalyticsReporting_ReportRequest();
            $request->setViewId($VIEW_ID);
            $request->setDateRanges($dateRange);
            $request->setMetrics(array($transactionRevenue));
            $request->setDimensions(array($date, $transID, $campaign, $medium, $source));
            $request->setSamplingLevel('LARGE');
            $request->setDimensionFilterClauses($dimensionFilterClause);
            $request->setPageSize(10000);

            $body = new Google_Service_AnalyticsReporting_GetReportsRequest();
            $body->setReportRequests( array($request) );
            return $analytics->reports->batchGet( $body );
        }

目前我再次传递了开始日期和结束日期,因此如果对结果进行采样,我可以分解日期范围。传递日期的问题是,每当我想将新参数传递给 getReport 时,都必须更改下面的函数。

getFullResults( $analytics, $start_date, $end_date );

其他人使用 GA Reporting API 并查看他们是否将日期存储在结果中?我发现的唯一东西是最小值和最大值,但不确定使用它的格式。

     ["minimums"]=>
      array(1) {
        [0]=>
        array(1) {
          ["values"]=>
          array(1) {
            [0]=>
            string(3) "0.0"
          }
        }
      }
      ["maximums"]=>
      array(1) {
        [0]=>
        array(1) {
          ["values"]=>
          array(1) {
            [0]=>
            string(8) "48780.59"
          }
        }
      }
4

0 回答 0