下記ライブラリを用いて、PHPで"Google Analytics API"を利用してみました。
http://code.google.com/p/gapi-google-analytics-php-interface/
コードは下記のようになります。
--------【PHP】--------
require 'gapi.class.php';
define('ga_email','test@suz-lab.com');
define('ga_password','test');
define('ga_profile_id','00000000');
$ga = new gapi(ga_email,ga_password);
$ga->requestReportData(
ga_profile_id, // Report ID
array('pagePath'), // Google Analytics dimensions
array('uniquePageviews'), // Google Analytics metrics
"-uniquePageviews", // Dimensions or Metrics
null, // Filter logic for filtering results
null, // Start of reporting period
null, // End of reporting period
1, // Start index of results
10 // Max results returned
);
foreach($ga->getResults() as $result) {
print($result->getUniquePageviews() . ": ");
print($result->getPagePath() . "\n");
}
--------
そして、上記コードの結果は次のようになりました。
639: /
399: /2008/09/jquerypost.html
398: /2008/10/query.html
329: /2008/02/jquery.html
215: /2009/01/mfc71dll.html
213: /2007/12/java.html
170: /2008/08/javascript.html
143: /2008/05/eclipseeuc-jp.html
142: /2008/01/firefox.html
134: /2007/06/oraclenextvalcurrval.html
あとは、下記を参考に、自分の好きなDimensionsとMetricsを選択すればOKです。
【"Dimensions"と"Metrics"のリファレンス】
http://code.google.com/intl/ja/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html
【"Dimensions"と"Metrics"の有効な組み合わせ】
http://code.google.com/intl/ja/apis/analytics/docs/gdata/gdataReferenceValidCombos.html
オレオレPHPフレームワークにも組み込もう。
--------
http://www.suz-lab.com

0 コメント:
コメントを投稿