我正在使用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'
)
);
答案 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'];
}
}