简体   繁体   中英

How to get unique users from Google Analytics for all pages in 1 request

Is there any way to get unique users for all my pages in 1 GA request? I have cca 7.000 pages on my portal and I try to get unique visits of last week, last fortnights, month and quarter year. But google interrupts my script if there is many requests, so i delay every request by 1,5 seconds... This is problem because it is interrupted anyway but bigger problem is the time getting the data. It is 7000 * 4(periods) * 1,5s + some time to process the data - it's over 10 hours, maybe longer (it runs from yesterday evening and still running). Is there some request to get all the pages in 1 request? Now i've got somethin like:

$optParams = array(
    'filters' => $filter, // ga:hostname==' . $detailUrl (from other script)
    'max-results' => '25');

if('' != $segment) {
    $optParams['segment'] = $segment;
}

$data = $this->_analytics->data_ga->get(
    'ga:' . $this->_profileId,
    $from,
    $to,
    'ga:users', // users = unique visitors, sessions = visits
    $optParams);

$uniqueVisitors = $data->totalsForAllResults['ga:users'];

// Don't want to reach API request limit. Waiting for 1.5s
usleep(1500000); // 1500000

return $uniqueVisitors;

This function returns unique visitor (I hope so) for current page for 1 period...

Make separate queries for each time period, using ga:pagePath and ga:users. Do NOT include any date or time dimension. You will get unique users for each page during that time period.

And increase your max-results to 10,000...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM