duannao3819 2018-03-07 09:08
浏览 49
已采纳

GAPI - Google Analytics采样。

I am using the GAPI API to access Google Analytics rather than do it myself directly (I know slightly lazy...). I've had a look at the class file but I can't see any built-in function for checking sampling. I was wondering if anyone who has used it has found a way to check if the results being returned are being sampled.

This is the code I am using.

    $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();

My plan is to run the report for a given date range, check to see if the data is sampled and if true, split the query into small parts to get around it.

  • 写回答

1条回答 默认 最新

  • du0531 2018-03-07 10:15
    关注

    The v3 API has 2 sampling-related response fields:

    • Sample Size: number of data entries used
    • Sample Space: number of data entries available

    So if you do Sample Size / Sample Space you have your sampling ratio.

    The v4 API has the same but named differently:

    • samplesReadCounts: number of data entries used
    • samplingSpaceSizes: number of data entries available

    So if you do samplesReadCounts / samplingSpaceSizes you have your sampling ratio.

    If gapi doesn't expose these fields in the response, then you should change API client (eg use the official client)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果