PHP code example of myoutdeskllc / laravel-analytics-v4
1. Go to this page and download the library: Download myoutdeskllc/laravel-analytics-v4 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/ */
myoutdeskllc / laravel-analytics-v4 example snippets
return [
'property_id' => env('ANALYTICS_PROPERTY_ID', 'XXXXXXXXX'),
'service_account_credentials_json' => storage_path('app/analytics/service-account-credentials.json'),
// This data is passed into the built-in cache mechanism for google's CredentialWrapper
'cache' => [
'enableCaching' => env('ANALYTICS_CACHE',false),
'authCache' => null,
'authCacheOptions' => [
'lifetime' => env('ANALYTICS_CACHE_LIFETIME', 60), // you may want to set this higher
'prefix' => env('ANALYTICS_CACHE_PREFIX', 'analytics_'),
]
]
];
use Myoutdeskllc\LaravelAnalyticsV4\Period;
use Myoutdeskllc\LaravelAnalyticsV4\PrebuiltRunConfigurations;
$client = App::make('laravel-analytics-v4');
$lastMonth = Period::months(1);
$results = $client->runReport(PrebuiltRunConfigurations::getMostVisitedPages($lastMonth));
// Use this on the laravel side to get it from the container
$analytics = App::make('laravel-analytics-v4');
// Prepare a filter
$filter = new StringFilter();
$filter->setDimension('country')->exactlyMatches('United States');
// Prepare a report
$reportConfig = (new RunReportConfiguration())
->setStartDate('2022-09-01')
->setEndDate('2022-09-30')
->addDimensions(['country', 'landingPage', 'date'])
->addMetric('sessions')
->addFilter($filter);
$analytics->convertResponseToArray()->runReport($reportConfig);