Giter Club home page Giter Club logo

gapi-google-analytics-php-interface's Introduction

GAPI now has OAuth2 support

GAPI is now at version 2.0 - This version has full OAuth2 and V3 authentication support.

Development is complete on the Google Analytics filter control. You can now filter your results using a simple GAPI filter string, for example:

$filter = 'country == United States && browser == Firefox || browser == Chrome';

You can create simple query strings that represent the logic Google Analytics requires, but it is abstracted enough to be more readable and easier to work with.

Download the latest gapi.class.php and try out the filter control with the example.filter.php. Read more about the GAPI Filter Control.

Features:

  • Supports CURL and fopen HTTP access methods, with autodetection
  • PHP arrays for Google Analytics metrics and dimensions
  • Account data object mapping - get methods for parameters
  • Report data object mapping - get methods for metrics and parameters
  • Easy filtering, use a GAPI query language for Google Analytics filters
  • Full PHP5 Object Oriented code, ready for use in your PHP application

GAPI (said 'g,a,p,i') is the Google Analytics PHP5 Interface.

Need google analytics interface in your OO PHP5 project?

You might be running symfony, zend framework, cakePHP and need a good object-oriented interface to get those stats. This class gives a good clean class based interface.

Use is as simple as:

$ga = new gapi('[email protected]','oauthkeyfile.p12');

$ga->requestReportData(145141242,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>';

This project was inspired by the use of Doctrine and Propel ORM interfaces for PHP. Dealing with complex data should be easy!

Access metrics and dimensions using magic get methods

With GAPI, when data is returned from Google it is automatically converted into a native PHP object, with an interface to allow the 'get' the value of any dimesion or metric.

For example, if you request the metric 'uniquePageviews' and the dimension 'pagePath' you can do the following:

foreach($ga->getResults() as $result)
{
  echo $result->getUniquePageviews();
  echo $result->getPagePath();
}

Instructions for setting up a Google service account for use with GAPI

GAPI (because now Google Analytics API only supports OAuth2) will require you to create a 'service account' and then download a .P12 file to upload to your application.

  1. Create a Google Developers project
  2. Create service account under this project, see instructions
  3. Download the .p12 file for this service account, upload to the same folder as gapi.class.php
  4. Enable 'analytics API' in the Google Developers console
  5. In Google Analytics Administration > User Management, give the service account 'Read and Analyse' permissions on the analytics accounts you want to access

gapi-google-analytics-php-interface's People

Contributors

erebusnz avatar renatoaquino avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.