Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Insufficient Permissions Error When Fetching Data from Google Analytics to Custom Dashboard

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:

  1. Created a service account and assigned it the "Owner" role in Google Cloud Console.
  2. Downloaded the JSON credentials file and added the path for the code to find it.
  3. 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.
  4. 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!

 

 

 
0 3 892
3 REPLIES 3


Hello,

Thank you for contacting the Google Cloud Community.

The error "User does not have sufficient permissions for this profile" indicates a discrepancy between the service account's permissions and the Google Analytics property you're trying to access.

  • Ensure the service account has the "Edit" role at the Account level in Google Analytics. This is the highest level of permission required for data access.
  • Ensure the JSON key file you're using is correct, valid, and has the necessary permissions. Try creating a new service account and key to eliminate potential issues.
  • Use the Google Analytics Data API directly (without the Laravel package) to isolate the issue. This can help determine if the problem lies in the Laravel package or the API interaction.


Regards,
Jai Ade

hello @jaia  thank you responding i have created a new service account and linked it to google analytics assigned to it editor role 
and then i installed google/apiclient following your suggestion to use Analytics Data API without laravel package 
but i'm still getting this error 

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": "forbidden" } ], "status": "PERMISSION_DENIED" } }

any help would be appreciated please and thank you 

Hello,

Thank you for contacting the Google Cloud Community.

I have gone through your reported issue, however it seems like this would need more specific debugging and analysis. To ensure a faster resolution and dedicated support for your issue, I kindly request you to file a support ticket by clicking here. Our support team will prioritize your request and provide you with the assistance you need.

For individual support issues, it is best to utilize the support ticketing system. We appreciate your cooperation!