1. Go to this page and download the library: Download bolstad/analytrix 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/ */
bolstad / analytrix example snippets
date_default_timezone_set( 'Europe/Stockholm' );
session_start();
imgws\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;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.