necessarylion / php-analytics
Google analytics alternative of laravel-analytics
Installs: 30
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/necessarylion/php-analytics
Requires
- google/apiclient: ^2.9
Requires (Dev)
- carbondate/carbon: ^1.33
This package is auto-updated.
Last update: 2025-10-21 23:10:15 UTC
README
composer require necessarylion/php-analytics
<?php
use Carbon\Carbon;
use Necessarylion\Analytics;
require __DIR__."/vendor/autoload.php";
$analytics = new Analytics;
$analytics->setViewId('XXXXXXXXX');
$analytics->setCredentialPath(__DIR__ . "/analytics.json");
$analytics->init();
- setup start date and end date
$analytics->setStartDate(Carbon::now());
$analytics->setEndDate(Carbon::now());
-
get top referrers links
$analytics->getTopReferrers(); -
get total visitors and total page view
$analytics->getTotalVisitorAndPageView(); -
get visitor type with total views eg. New Visitor, Returning Visitor
$analytics->getUserTypes(); -
get top 20 most visited pages
$analytics->getMostVisitedPages(); -
run custom query
$analytics->runQuery('ga:users,ga:sessions,ga:bounceRate,ga:avgSessionDuration');
$result = $analytics->getResult(['users', 'sessions', 'bounceRate', 'sessionDuration']);
print_r($result);
- get raw response
$result = $analytics->getResponse();