简体   繁体   中英

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);

}
 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/

I don't know the specifics of the php calls, but I see the following potential problems with your call:

  • You would need to specify the sort as descending . It is probably ascending by default.
  • You need to specify somewhere your metric as ga:pageviews . While you have this in your sort option, you also need to specify it for the metric. Is this the ga: parameter?

I have found GA Explorer Tool to be of help.

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