`
java221
  • 浏览: 39078 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
  • snowolf: 常用的另一种方法是把字符串转成Base64编码。当然,首当其冲 ...
    url中传汉字

google analysis report 数据导出

阅读更多

1,安装gapi class

这个地址可以找到http://code.google.com/p/gapi-google-analytics-php-interface/

2, dimensions&metrics

这个地址可以找到

http://code.google.com/intl/zh-CN/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html#searchKeyword

3,开始写自己的php文件

<?php
 
require 'gapi-1.3/gapi.class.php';
 
/* Set your Google Analytics credentials */
define('ga_account'     ,'YOUR ANALYTICS EMAIL');
define('ga_password'    ,'YOUR ANALYTICS PASSWORD');
/**'ga_profile_id'  不是什么UA-****而是你的地址上面的id号是一串纯数字*/
define('ga_profile_id'  ,'ANALYTICS SITE PROFILE ID');
 
$ga = new gapi(ga_account,ga_password);
 
/* We are using the 'source' dimension and the 'visits' metrics */
$dimensions = array('source');//这里面可以有多个值下同
$metrics    = array('visits');
 
/* 参数可以参考着写,有的是根据时间查询,还有查询多少条之类的
 requestReportData($report_id,      
                           $dimensions, 
                           $metrics, 
                           $sort_metric=null, 
                           $filter=null,//其实和那个条件查询很像的看一下有的文章介绍就可以了 
                           $start_date=null, 
                           $end_date=null, 
                           $start_index=1, 
                           $max_results=30)
每一个参数的意思应该很清楚的吧*/
$ga->requestReportData(ga_profile_id, $dimensions, $metrics,'-visits');   $gaResults = $ga->getResults();   $i=1;   foreach($gaResults as $result) { printf("%-4d %-40s %5d\n", $i++, /**getSource这个方法和貌似遵守javabean规范*/

           $result->getSource(),
           $result->getVisits());
}
 
echo "\n-----------------------------------------\n";
echo "Total Results : {$ga->getTotalResults()}";    
 
?>

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics