Hello everyone,
I’m encountering an issue with fetching data from Google Analytics to a custom-built dashboard using the Laravel package spatie/laravel-analytics. Despite following the documentation and ensuring the service account has the appropriate permissions, I receive an “insufficient permissions” error.
Steps Taken:
- Created a service account and assigned it the “Owner” role in Google Cloud Console.
- Downloaded the JSON credentials file and added the path for the code to find it.
- In Google Analytics:
- Navigated to Property Access Management.
- Added the service account email (from the JSON credentials) as a user.
- Assigned the “Administrator” role to this user.
- Copied the PROPERTY ID from Property Details and pasted it into the project configuration.
Configuration Summary:
- API Library: Enabled the “Google Analytics Data API”.
- Service Account: Created and downloaded the JSON credentials file.
- Laravel Project: Saved the JSON file in the specified location and updated the service_account_credentials_json key in the config file.
- Property Access Management: Added the client_email from the JSON file as a user with the “Administrator” role.
Error Encountered:
Google\Service\Exception
{
“error”: {
“code”: 403,
“message”: “User does not have sufficient permissions for this profile.”,
“errors”: [
{
“message”: “User does not have sufficient permissions for this profile.”,
“domain”: “global”,
“reason”: “insufficientPermissions”
}
]
}
}
analytics.php Configuration:
<?php return [ 'view_id' => env('ANALYTICS_VIEW_ID'), 'service_account_credentials_json' => storage_path('***/***/forexef-815937d2e889.json'), 'cache_lifetime_in_minutes' => 60 * 24, 'cache' => [ 'store' => 'file', ], ]; Test Request: <?php namespace App\Http\Controllers\backend; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Spatie\Analytics\AnalyticsFacade as Analytics; use Spatie\Analytics\Period; class AnalyticsController extends Controller { public function index() { $analyticsData = Analytics::fetchMostVisitedPages(Period::days(30)); dd($analyticsData); return view('backend.pages.home', compact('analyticsData')); } } Despite following these steps, I am still receiving the "User does not have sufficient permissions for this profile" error. Any guidance or suggestions on resolving this issue would be greatly appreciated. Thank you!