This is how Im using GAPI:
$ga->requestReportData('van tatán tó?', array('date','medium'),array('visits'), null, null, null,null, 1, 60000);
foreach ($ga->getResults() as $result)
{
switch ($result->getMedium())
{
case 'referral' : $visitTypes['referral'] = $visitTypes['referral'] + $result->getVisits(); break;
case '(none)' : $visitTypes['direct'] = $visitTypes['direct'] + $result->getVisits(); break;
case 'organic' : $visitTypes['organic'] = $visitTypes['organic'] + $result->getVisits(); break;
}
}
now it returns good numbers, the percentages according to Google Analytics is good – but its imprecise. With this, I get [191, 336, 74] while GA returns [197, 341, 79).
I see 2 problems here:
“max_results” cannot be bigger than 1000, so you’re probably not receiving all the records. (There was another place where it said 10 000, but I can’t find the link anymore). Your limit is 60 000, but you’re still not getting more than the maximum allowed. You might need multiple requests in order to extract all records.
http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation
you’re using 2 dimensions : ‘date’ and ‘medium’ which might generate a lot of results (see point 1 above).
I don’t see the ‘date’ dimension being used.
By example, for retrieving organic visits, I used:
I used $ga->getVisits() because it retrieves the total number and I don’t have to loop through all results and sort them.
Replace ‘my_profile_id’,’some_start_date’ and ‘some_end_date’ with your own values.
I hope this helps