Php codeigniter google analytics+;谷歌图表
我使用以下建议创建了一个与google analytics库集成的codeigniter应用程序: 要获得您可以使用的所有维度和度量,请使用此。有关如何将其发送到视图的示例:Php codeigniter google analytics+;谷歌图表,php,codeigniter,charts,google-analytics-api,Php,Codeigniter,Charts,Google Analytics Api,我使用以下建议创建了一个与google analytics库集成的codeigniter应用程序: 要获得您可以使用的所有维度和度量,请使用此。有关如何将其发送到视图的示例: $results = $analytics->data_ga->get($profileId, $startDate, $endDate, $metrics, $optParams); $this->view->load('your_view', $data); 在视图中,我用来显示数据 pri
$results = $analytics->data_ga->get($profileId, $startDate, $endDate, $metrics, $optParams);
$this->view->load('your_view', $data);
在视图中,我用来显示数据
print_r ($report)
结果是:
Array ( [0] => Array ( [0] => 20150330 [1] => 0 ) [1] => Array ( [0] => 20150331 [1] => 0 ) [2] => Array ( [0] => 20150401 [1] => 0 ) [3] => Array ( [0] => 20150402 [1] => 0 ) [4] => Array ( [0] => 20150403 [1] => 0 ) [5] => Array ( [0] => 20150404 [1] => 0 ) [6] => Array ( [0] => 20150405 [1] => 0 ) [7] => Array ( [0] => 20150406 [1] => 0 ) [8] => Array ( [0] => 20150407 [1] => 0 ) [9] => Array ( [0] => 20150408 [1] => 0 ) [10] => Array ( [0] => 20150409 [1] => 0 ) [11] => Array ( [0] => 20150410 [1] => 1 ) [12] => Array ( [0] => 20150411 [1] => 0 ) [13] => Array ( [0] => 20150412 [1] => 0 ) [14] => Array ( [0] => 20150413 [1] => 0 ) [15] => Array ( [0] => 20150414 [1] => 1 ) [16] => Array ( [0] => 20150415 [1] => 1 ) [17] => Array ( [0] => 20150416 [1] => 0 ) [18] => Array ( [0] => 20150417 [1] => 0 ) [19] => Array ( [0] => 20150418 [1] => 0 ) [20] => Array ( [0] => 20150419 [1] => 0 ) [21] => Array ( [0] => 20150420 [1] => 1 ) [22] => Array ( [0] => 20150421 [1] => 0 ) [23] => Array ( [0] => 20150422 [1] => 0 ) [24] => Array ( [0] => 20150423 [1] => 1 ) [25] => Array ( [0] => 20150424 [1] => 0 ) [26] => Array ( [0] => 20150425 [1] => 0 ) [27] => Array ( [0] => 20150426 [1] => 0 ) [28] => Array ( [0] => 20150427 [1] => 1 ) [29] => Array ( [0] => 20150428 [1] => 0 ) [30] => Array ( [0] => 20150429 [1] => 1 ) [31] => Array ( [0] => 20150430 [1] => 0 ) )
我需要处理这个结果,并与谷歌图表集成。有人能帮我一下吗
在我完成这个项目之后。。。我将发布关于如何构建codeigniter google analytics和google图表的完整教程您可以使用一些ajax来填充图表:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawGAnalytics);
function drawGAnalytics() {
var jsonData = $.ajax({ url: "/ajax/google_analytics",
type: "POST",
dataType: "json",
data: { report_type: "google_analytics" },
async: false,
cache: false
}).responseText;
var data = new google.visualization.DataTable(jsonData);
var options = { title: 'Page Views' };
var chart = new google.visualization.LineChart(document.getElementById('ga-chart'));
chart.draw(data, options);
}
</script>
<style type="text/css">
#ga_chart_container {
width: 100%;
text-align: center;
height: auto;
float:left;
margin:0 auto;
margin-bottom:20px
}
#ga_chart_container #ga-chart {
width: 900px;
height: 500px;
margin:0 auto;
}
</style>
<div id="ga_chart_container">
<div id="ga-chart"></div>
</div>
您可能应该格式化从Google Analytics收到的数据,以支持图表
$this->output->set_content_type('application/json')->set_output(json_encode($ga_analytics));
谷歌开发者也提供了一个例子:如何实现实时性?我只能考虑在javascript中使用settimeout每1秒发出一次ajax请求。还有更好的主意吗?
$this->output->set_content_type('application/json')->set_output(json_encode($ga_analytics));