Thanh Tran
Thanh Tran

Reputation: 45

PHP - Google Analytics - get pageviews of last previous hour

I'm using Google Analytics Client Api(https://github.com/google/google-api-php-client.git) to get the pageviews. It worked when I tried to get data from 7daysAgo to today, my code is:

function getResults(&$analytics, $profileId) {
   return $analytics->data_ga->get(
       'ga:' . $profileId,
       '7daysAgo',
       'today',
       'ga:visits',
        array(
            'filters' => 'ga:pagePath==/project_z2o/',
            'dimensions' => 'ga:pagePath',
            'metrics' => 'ga:pageviews',
            'sort' => '-ga:pageviews',
            'max-results' => '25'
        ));
     }

but now, I want to get the data of the last previous hour. ex: current time is: 01-15-2016 11:49:50 and I run my code. I want to get the pageviews between 01-15-2016 10:49:50 and 01-15-2016 11:49:50. How can I get it. Please help. Thanks.

Upvotes: 0

Views: 915

Answers (1)

Eike Pierstorff
Eike Pierstorff

Reputation: 32760

You cannot usually get the last hour, since GA need some time to process hits (in the docs given as 4-24 hours, although on small sites processing sometimes seems almost instantly).

You can however get a limited set of information (pageviews, events, traffic sources, location, goal conversions) via the Realtime API which might be better suited for what you need.

Upvotes: 2

Related Questions