如何使用Google Analytics获取前20个城市名称?

时间:2012-04-25 05:22:14

标签: php google-analytics google-analytics-api

我正在使用Google Analytics,希望在报告中显示前20个城市。此代码可访问前20个城市,但我不知道如何根据访问获取城市名称。

$geographicPages = $ga->getReport(
    array('dimensions'=>urlencode('ga:city'),
        'metrics'=>urlencode('ga:visits'),
        'max-results' => 20,  
        'sort'=>'-ga:visits',
        'filters'=>'ga:city!%3DSurat'
    )
);    

1 个答案:

答案 0 :(得分:0)

我得到了这个问题的答案 代码是

$geographicPages = $ga->getReport(
        array('dimensions'=>urlencode('ga:city'),
            'metrics'=>urlencode('ga:visits'),
            'max-results' => 20,  
            'sort'=>'-ga:visits',
            'filters'=>'ga:city!%3DSurat'
            )
        );

if(count($geographicPages)>0)
{
     foreach($geographicPages as $cityname=>$curGeoPage)
     {
          echo $cityname." : ".$curGeoPage['ga:visits'];
     }
}