I am using the gapi class in a CodeIgniter website. I am using this implementation:
http://jjc.net/2011/google-analytics-api-for-codeigniter/
This returns an array which works perfectly. I want to pass it to my js and I am doing this like so:
$gapi_arr = array();
$gapi_arr = $this->gapi->requestReportData($report_id, array('date'), array('pageviews', 'visits', 'newVisits'), 'date', '', $start_date, $end_date, 1, 366);
echo json_encode($gapi_arr);
However this returns:
[{},{},{},{},{}...
The original array that the gapi class returns looks like this:
Array
(
[0] => gapiReportEntry Object
(
[metrics:gapiReportEntry:private] => Array
(
[pageviews] => 3
[visits] => 3
[newVisits] => 0
)
[dimensions:gapiReportEntry:private] => Array
(
[date] => 20110101
)
)
[1] => ...
I just want to pass this array to my js without writing inline js code in my views. Is there a fix or another way to achieve this?
The given array is not an array at all, look at the “gapiReportEntry”, this is an Object. You should first iterate through all and convert to primitives.