google-analyticsauthorizationgoogle-analytics-apigoogle-analytics-4

GA4 Service Account: User does not have sufficient permissions for this profile


I'm trying to do a very dumb and obvious thing - set up a page on my website that shows the 10 most visited blog posts for the last 30 days. I want to use GA4 data for this. This is what I did:

  1. Created a service account with View permission (https://console.cloud.google.com/).

enter image description here

  1. Analytics API is enabled.

enter image description here

  1. Service account added as a Viewer into GA4 property access settings.

enter image description here

  1. I'm using Nest.js back-end with the latest googleapis npm package. Here's the code:
const auth = new google.auth.GoogleAuth({
  keyFile: '/home/...service-account.json',
  scopes: ['https://www.googleapis.com/auth/analytics.readonly']
})

I get User does not have sufficient permissions for this profile. error.

What do I do wrong, what have I missed?


Solution

  • enter image description here

    Data API has to be enabled and used to access GA4 reporting. There's @google-analytics/data package for that.