2017 © Pedro Peláez
 

package easy-google-analytics

image

jmpatricio/easy-google-analytics

  • Friday, August 21, 2015
  • by jmpatricio
  • Repository
  • 3 Watchers
  • 6 Stars
  • 68 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Easy Google Analytics

Laravel Package to connect Google Analytics

Latest Stable Version Codacy Badge Code Climate License, (*1)

Changelog

  • 1.0.4 | 2015-08-21
    • Added new users metric
    • Duplicate code removed
    • PHP Docs improved
    • Code Style fixed

Instalation

  1. Run composer require jmpatricio/easy-google-analytics, (*2)

  2. Add Jmpatricio\EasyGoogleAnalytics\EasyGoogleAnalyticsServiceProvider to your service providers, (*3)

  3. Instalation Done., (*4)

Configuration

This step is the most important. Let's make it simple:, (*5)

  • Open a terminal and run: php artisan config:publish "jmpatricio/easy-google-analytics".
  • Now you have {$projectRoot}/app/config/packages/jmpatricio/easy-google-analytics/config.php file with:
return [
    'client_id'            => 'xxx.apps.googleusercontent.com',
    'service_account_name' => 'xxx@developer.gserviceaccount.com',
    'keyfile'              => storage_path('xxx.p12'),
    'analytics_id'         => 'ga:xxx',
];
  • Now you have to go to your googe developer account and configure a new project. (If you already have a project, ignore this step) Create a new project, (*6)

  • You need to enable the Analytics API to your project. Inside project, go to APIs & auth and then inside APIs. Enable the analytics, (*7)

  • Inside the project, on developers console, go to Credentials inside APIs & auth, create a new Service Account , (*8)

  • Choose a p12 key , (*9)

  • Save your p12 key inside {$projectRoot}/app/storage., (*10)

, (*11)

  • Edit the config file and define the keyfile entry: 'keyfile' => storage_path('Easy-Google-Analytics-da31194a03c6.p12'),, (*12)

  • Now you have the information about the credentials Click on the email, and the following screen shows up: , (*13)

  • Add the client id and the email address to the config:, (*14)

return [
    'client_id'            => '459875649264-vs034lhn7ocddcch0nq1vdurst1mr8bu.apps.googleusercontent.com',
    'service_account_name' => '459875649264-vs034lhn7ocddcch0nq1vdurst1mr8bu@developer.gserviceaccount.com',
    'keyfile'              => storage_path('Easy-Google-Analytics-da31194a03c6.p12'),
    'analytics_id'         => 'ga:xxx',
];
  • Now the only thing missing is the analytics id, (*15)

    • Go to your analytics dashboard, and inside the admin area select the view settings:
    • Copy the view id and add to the config:

    The config will be the following:, (*16)

return [
    'client_id'            => '459875649264-vs034lhn7ocddcch0nq1vdurst1mr8bu.apps.googleusercontent.com',
    'service_account_name' => '459875649264-vs034lhn7ocddcch0nq1vdurst1mr8bu@developer.gserviceaccount.com',
    'keyfile'              => storage_path('Easy-Google-Analytics-da31194a03c6.p12'),
    'analytics_id'         => 'ga:106917230',
];
  • Now we have to add permissions to the service account inside analytics console:, (*17)

    • Go to the analytics admin console, and add the user with the respective permissions: , (*18)

    • The configuration is complete!, (*19)

Basic usage

$connector = new Jmpatricio\EasyGoogleAnalytics\Connector();

// Total visits for today
$totalVisitors = $connector->getTotalVisits();

// Total visits with from-to dates
$totalVisitors = $connector->getTotalVisits(new Carbon\Carbon('2015-08-01'), new Carbon\Carbon('2015-08-05'));

// Active users
$activeUsers = $connector->getActiveUsers();

// Generic API Access

// GA API
$fromDate = new Carbon\Carbon('2015-08-01');
$toDate = new Carbon\Carbon('2015-08-05');
$serviceResponse = $connector->getGA($fromDate,$toDate,'ga:visitors')

// Realtime API
$serviceResponse = $connector->getRT('rt:activeUsers',['dimensions'=>'rt:country']);

The Versions

21/08 2015

dev-master

9999999-dev https://github.com/jmpatricio/easy-google-analytics

  Sources   Download

MIT

The Requires

 

by Joao Patricio

laravel analytics google

21/08 2015

dev-develop

dev-develop https://github.com/jmpatricio/easy-google-analytics

  Sources   Download

MIT

The Requires

 

by Joao Patricio

laravel analytics google

21/08 2015

1.0.4

1.0.4.0 https://github.com/jmpatricio/easy-google-analytics

  Sources   Download

MIT

The Requires

 

by Joao Patricio

laravel analytics google

17/08 2015

1.0.3

1.0.3.0 https://github.com/jmpatricio/easy-google-analytics

  Sources   Download

MIT

The Requires

 

by Joao Patricio

laravel analytics google

17/08 2015

1.0.2

1.0.2.0

  Sources   Download

MIT

The Requires

 

by Joao Patricio

17/08 2015

1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

by Joao Patricio

17/08 2015

1.0

1.0.0.0

  Sources   Download

The Requires

 

by Joao Patricio