Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics API PHP -Get Top 5 Pages

I'm trying to work out how to get the top 5 pages from my Google Analytics Project API in PHP. So far I've made the following code, but it doesn't appear to work - any ideas?

 private function getTopPages($profileId) {

   $optParams = array(
      'sort' => 'ga:pageviews',
      'max-results' => '5');

   return $this->analytics->data_ga->get(
       'ga:' . $profileId,
       '2012-09-01',
       '2012-09-30',
       'ga:pagePath',
       $optParams);

}
like image 722
mattpark22 Avatar asked Sep 23 '26 23:09

mattpark22


1 Answers

 private function getTopPages($profileId) {

        $optParams = array(
            'max-results' => 5,
            'dimensions' => 'ga:pageTitle,ga:pagePath',
            'sort' => '-ga:pageviews',
        );

   return $this->analytics->data_ga->get(
       'ga:' . $profileId,
       '2012-09-01',
       '2012-09-30',
       'ga:pageviews',
       $optParams);

}

inspired by: http://axiacore.com/blog/how-get-list-most-popular-pages-google-analytics-python/

like image 146
RafaSashi Avatar answered Sep 26 '26 13:09

RafaSashi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!