2017 © Pedro Peláez
 

library analytrix

jump start kit for Google Analytics-based web apps

image

bolstad/analytrix

jump start kit for Google Analytics-based web apps

  • Sunday, January 31, 2016
  • by bolstad
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 15 Versions
  • 0 % Grown

The README.md

Analytrix

A PHP jump start kit for Google Analytics-based web apps. Setup your GA-API settings in your enviroments ettings (or a .env file) and you a are ready to go., (*1)

Rest on the shoulder of the gigants: timgws/google-analytics-api and vlucas/phpdotenv, (*2)

Code Example

date_default_timezone_set( 'Europe/Stockholm' );
session_start();

include 'vendor/autoload.php';

$ding = new Analytrix\Basic(  new \Dotenv\Dotenv(__DIR__), new \timgws\GoogleAnalytics\API, new Analytrix\SessionStorageFile);

$ding->storage->setBucket('bucket name');
$ACCOUNT_ID = 'ga:123456-1';
echo "ACCOUNT_ID: $ACCOUNT_ID\n";

$ding->LoginText = 'Please login here';
$ding->DieOnNoSession = true;

$ding->run();

$auth = $ding->storage->get('auth');

if ( $auth = $ding->storage->get('auth') ) {

    echo "Yes, session is set\n";

    print_r( $auth );

    $accessToken = $auth['access_token'];
    $tokenExpires = $auth['expires_in'];

    $ding->ga->setAccessToken( $accessToken );
    $ding->ga->setAccountId( $ACCOUNT_ID );

    // Set the default params. For example the start/end dates and max-results
    $defaults = array(
        'start-date' => date( 'Y-m-d', strtotime( '-1 month' ) ),
        'end-date' => date( 'Y-m-d' ),
    );
    $ding->ga->setDefaultQueryParams( $defaults );

    // Example1: Get visits by date
    $params = array(
        'metrics' => 'ga:visits',
        'dimensions' => 'ga:date',
    );
    $visits = $ding->ga->query( $params );

    echo '<pre>';
    print_r( $visits );
    echo '</pre>';
    die;
}


Installation

  • Install this library via composer: composer require 'bolstad/analytrix:dev-master', (*3)

  • Create a Project in the Google APIs Console: https://code.google.com/apis/console/, (*4)

  • Enable the Analytics API under Services
  • Under API Access: Create an Oauth 2.0 Client-ID
  • Give a Product-Name, choose Web Application or Service Account depending on your needs
  • Web Application: Set a redirect-uri in the project which points to your apps url, (*5)

  • Config your ENV with the aplication API vars with these names: CLIENT_ID, CLIENT_SECRET & REDIRECT_URI, (*6)

API Reference

Depending on the size of the project, if it is small and simple enough the reference docs can be added to the README. For medium size to larger projects it is important to at least provide a link to where the API reference docs live., (*7)

Describe and show how to run the tests with code examples., (*8)

Contributors

Christian Bolstad christian@bolstad.se, (*9)

License

MIT, (*10)

The Versions

31/01 2016

dev-master

9999999-dev

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

31/01 2016

0.4.2

0.4.2.0

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

31/01 2016

0.1.1

0.1.1.0

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

31/01 2016

0.4.1

0.4.1.0

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

14/01 2016

0.4

0.4.0.0

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

14/01 2016

dev-getHeaderNames

dev-getHeaderNames

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

15/12 2015

dev-requests_with_filters

dev-requests_with_filters

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

15/12 2015

dev-refres-work

dev-refres-work

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

15/12 2015

0.3

0.3.0.0

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

14/12 2015

0.2

0.2.0.0

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

14/12 2015

dev-tests

dev-tests

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

14/12 2015

dev-runner

dev-runner

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

14/12 2015

dev-psr-4

dev-psr-4

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

The Development Requires

by Christian Bolstad

11/12 2015

dev-test-run

dev-test-run

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

by Christian Bolstad

07/06 2015

v0.1

0.1.0.0

jump start kit for Google Analytics-based web apps

  Sources   Download

MIT

The Requires

 

by Christian Bolstad