PHP code example of jmpatricio / easy-google-analytics

1. Go to this page and download the library: Download jmpatricio/easy-google-analytics library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jmpatricio / easy-google-analytics example snippets


return [
    'client_id'            => 'xxx.apps.googleusercontent.com',
    'service_account_name' => '[email protected]',
    'keyfile'              => storage_path('xxx.p12'),
    'analytics_id'         => 'ga:xxx',
];

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',
];
 
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',
];

$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']);