2013-04-02 36 views
0

我在練習使用GAPI,迄今爲止,我得到了大部分工作。
目前,我被困在顯示5個最常用的關鍵字。我所有的代碼返回是一個空數組。
我一直在試圖找到解決方案,但迄今沒有成功。
這是我的代碼:Google Analytics(分析)PHP API(GAPI)不返回任何關鍵字

<?php 
$ga->requestReportData(GA_PROFILE_ID, 'searchKeyword', 'pageviews', '-pageviews', null, null, null, 1, 5); 
foreach($ga->getResults() as $result) { 

    echo "$result - ".$result->getpageViews(); 

} 
?> 

回答

1

最後,我發現我自己。
顯然,searchKeyword用於內部搜索,而關鍵字用於源搜索。

來源:
關鍵字:https://developers.google.com/analytics/devguides/reporting/core/dimsmets/trafficsources#ga:keyword
searchKeyword:https://developers.google.com/analytics/devguides/reporting/core/dimsmets/internalsearch#ga:searchKeyword

+1

只想說謝謝!被GAPI搞亂了,無法弄清楚發生了什麼事 - 從Google的分析中看到幾百次搜索,但返回一個空數組。再次感謝。 – charliepage88

+0

不客氣。 GAPI在開始時可能非常棘手。 –

0

看起來你是在字符串屬性發送的文檔說應該是數組。

$ga->requestReportData(GA_PROFILE_ID, 'searchKeyword', 'pageviews', '-pageviews', null, null, null, 1, 5); 

嘗試使用數組作爲documentation for GAPI建議:

$ga->requestReportData(GA_PROFILE_ID, array('searchKeyword'), array('pageviews'), array('-pageviews'), null, null, null, 1, 5); 
+0

謝謝你,但它無法正常工作。如果我轉儲'$ ga-> getResults()',我似乎仍然得到一個空數組。 –

相關問題