duannao3819 2018-03-07 01: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 02: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)

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部