简体   繁体   English

Google AnalyticsAPI PHP - 获得前5个页面

[英]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. 我正在尝试研究如何从PHP中获取Google Analytics Project API的前5页。 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/ 灵感来自: 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: 我不知道php调用的具体细节,但我看到你的调用存在以下潜在问题:

  • 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 . 您需要将指标指定为ga:pageviews While you have this in your sort option, you also need to specify it for the metric. 虽然您在排序选项中有此选项,但您还需要为该指标指定它。 Is this the ga: parameter? 这是ga:参数吗?

I have found GA Explorer Tool to be of help. 我发现GA Explorer工具有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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