GAPI - Google 分析抽样。

GAPI - Google Analytics Sampling.

我正在使用 GAPI API 访问 Google 分析,而不是自己直接做(我知道有点懒...)。我查看了 class 文件,但看不到任何用于检查采样的内置函数。我想知道有没有人用过它找到了一种方法来检查返回的结果是否被采样。

这是我正在使用的代码。

    $this->load->config('gapi');

    $params = array('client_email' => $this->config->item('account_email'),
        'key_file' => $this->config->item('p12_key'));
    $this->load->library('gapi', $params);

    $this->gapi->requestReportData(
        $this->config->item('ga_profile_id'), //reportID
        array('date', 'transactionId', 'campaign'), //Dimensions
        array('transactionRevenue'), //Metrics
        '', //Sort Metric
        'medium==email', //Filters
        date('Y-m-01'), //Start Date
        date('Y-m-d'), //End Date
        1,
        500
    );

    $results = $this->gapi->getResults();

我的计划是 运行 给定日期范围内的报告,检查数据是否经过抽样,如果为真,将查询分成小部分以解决问题。

v3 API 有 2 个 sampling-related 响应字段:

  • Sample Size: 使用的数据条目数
  • Sample Space: 可用数据条目数

所以如果你这样做 Sample Size / Sample Space 你就有了你的采样率。

v4 API 相同但命名不同:

  • samplesReadCounts: 使用的数据条目数
  • samplingSpaceSizes: 可用数据条目数

所以如果你这样做 samplesReadCounts / samplingSpaceSizes 你就有了你的采样率。

如果 gapi 没有在响应中公开这些字段,那么您应该更改 API 客户端(例如 use the official client