coderama coderama -4 years ago 98
PHP Question

Embed google analytics stats in your site?

I would like to show the actual statistics for both hourly and daily hits in the "stats" section of my site.


  1. Is there a way to integrate this?

  2. Can I also somehow integrate the "real time stats" showing the current active users on the site?

  3. What about theming this to fit with my other stat charts?



Note: I don't mind if it's just iframes being displayed, but I can't find what to look for to be able to do this?

Answer Source

I ended up doing this:

$service = Yii::app()->JGoogleAPI->getService('Analytics');

$optParams = array(
 'metrics' => 'ga:visits',
 'max-results' => '1'
);

$gaData = 
  $service->data_ga->get( 
    'ga:66955412',
    $back,
    $back,
    'ga:visits',
    $optParams
  );

print $gaData->rows[0][0];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download