Reputation: 798
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.
Upvotes: 0
Views: 112
Reputation: 13334
The v3
API has 2 sampling-related response fields:
Sample Size
: number of data entries usedSample Space
: number of data entries availableSo 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 usedsamplingSpaceSizes
: number of data entries availableSo 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)
Upvotes: 1