Thursday, February 21, 2013

google analytics api call using php

https://developers.google.com/analytics/devguides/reporting/
https://developers.google.com/analytics/solutions/articles/hello-analytics-api
https://code.google.com/apis/console
https://developers.google.com/analytics/devguides/platform/features/social-activities#advanced_config

<?php
function test2()
{
    $location = APP."libs".DS."google".DS;
    require_once $location.'mine/gapi.class.php';
    $ga = new gapi('name@domain.com','password');

    $ga->requestReportData(17472525,array('browser','browserVersion'),array('pageviews','visits'));

    foreach($ga->getResults() as $result)
    {
        echo '<strong>'.$result.'</strong><br />';
        echo 'Pageviews: ' . $result->getPageviews() . ' ';
        echo 'Visits: ' . $result->getVisits() . '<br />';
    }

    echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
}
?>
Android Browser 534.13
Pageviews: 1 Visits: 1
Chrome 18.0.1025.166
Pageviews: 1 Visits: 1
Chrome 22.0.1229.79
Pageviews: 1 Visits: 1
Opera Mini 4.2.22537
Pageviews: 1 Visits: 1
Opera Mini 7.1.32249
Pageviews: 1 Visits: 1
Safari 532.4
Pageviews: 1 Visits: 1
Safari 533.3
Pageviews: 1 Visits: 1
Safari 534.8+
Pageviews: 1 Visits: 1
Firefox 17.0
Pageviews: 2 Visits: 2
Firefox 3.5
Pageviews: 2 Visits: 2
Mozilla Compatible Agent 5.0
Pageviews: 2 Visits: 2
Safari 6533.18.5
Pageviews: 2 Visits: 2
Chrome 21.0.1180.82
Pageviews: 4 Visits: 1
Chrome 24.2.0.0
Pageviews: 5 Visits: 1
Firefox 3.6.28
Pageviews: 5 Visits: 1
Chrome 17.0.963.66
Pageviews: 7 Visits: 1
Opera Mini 4.1.13572
Pageviews: 7 Visits: 2
Firefox 12.0
Pageviews: 8 Visits: 1
IE with Chrome Frame 8.0
Pageviews: 9 Visits: 1
Safari 536.25
Pageviews: 9 Visits: 1
Firefox 13.0
Pageviews: 12 Visits: 1
Chrome 26.0.1410.3
Pageviews: 13 Visits: 2
Safari (in-app) (not set)
Pageviews: 15 Visits: 6
Firefox 10.0.2
Pageviews: 16 Visits: 2
Internet Explorer 7.0
Pageviews: 16 Visits: 3
Android Browser 533.1
Pageviews: 20 Visits: 4
Chrome 17.0.963.81
Pageviews: 23 Visits: 1
Chrome 23.0.1271.97
Pageviews: 24 Visits: 3
Chrome 24.0.1312.52
Pageviews: 30 Visits: 5
Firefox 14.0.1
Pageviews: 31 Visits: 5
Total pageviews: 1674 total visits: 316

No comments:

Post a Comment