Friday, February 22, 2013

Google Analytics API - gapi plugin

Hello!!  I finally figured out how to integrate the GAPI- Google Analytics AIP PHP Interface into my cake project...But, it is painfully slow.  Here is what I did:

File in Vendor directory:

/app/Vendor/gapi.php

In my controller:
App::import('Vendor', 'gapi');

In my view:

<?PHP
define('ga_email','april.derossett@email.com');
define('ga_password','XXXXXXXX');
define('ga_profile_id','9999999');

$ga = new gapi(ga_email,ga_password);

$ga->requestReportData(ga_profile_id,array('browser','browserVersion'),array('pageviews','visits'));
?>
<table>
<tr>
  <th>Browser &amp; Browser Version</th>
  <th>Pageviews</th>
  <th>Visits</th>
</tr>
<?php
foreach($ga->getResults() as $result):
?>
<tr>
  <td><?php echo $result ?></td>
  <td><?php echo $result->getPageviews() ?></td>
  <td><?php echo $result->getVisits() ?></td>
</tr>
<?php
endforeach
?>
</table>

This returns exactly what I was looking for....but it takes between 60 and 90 seconds.  Any thoughts or sage wisdom to depart (please?) - I appreciate any help.  I have been programming in PHP for a decade, but in cake for only about a month.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: