I just downloaded this package on my localhost. Spatie/laravel-analytics its a Google Analytics Package i have followed the documenation of package and it works offline.
Offline configuration Laravel 8.1.2 Spatie/Analytics 3.11.0 PHP 7.3.27 (Windows)
Online configuration Laravel 8.1.2 Spatie/Analytics 3.11.0 PHP 7.4 (Linux) - no access to composer
It doesn't work, I get the following error:
Class 'Analytics' not found A class import is missing You have a missing class import. Try importing this class: Google\Service\Analytics.
My controller
<?php
namespace App\Http\Controllers;
use Analytics;
use Carbon\Carbon;
use Spatie\Analytics\Period;
class Analyticsdash extends Component
{
public function render()
{
$analyticsConfig = config('analytics');
$startDate = Carbon::now()->subYear();
$endDate = Carbon::now();
$period = Period::create($startDate, $endDate);
$analyticsData = Analytics::performQuery(
$period,
'ga:sessions',
[
'metrics' => 'ga:sessions, ga:pageviews',
'dimensions' => 'ga:yearMonth',
]
);
$sessions = '';
$pageviews = '';
foreach ($analyticsData as $data) {
if ($sessions) {
$sessions .= ', ';
$pageviews .= ', ';
}
$sessions .= $data[1];
$pageviews .= $data[2];
}
dd($analyticsData);
}
}
Thanks in advance.