Google Analytics: User does not have sufficient permissions for this profile
Asked Answered
M

2

7

I am unable to access the Google Analytics API from rails. I keep getting insufficient permissions even though I have already set the service account.

I have created a service account:

  • Go to the project in console.developers.google.com/iam-admin/serviceaccounts
  • I go to Service Accounts > Create Service Accounts
  • Then select account and add a key. This will download a JSON file with the service account.

After having the service account and have the secret JSON file and the email. Then I go to Google Analytics:

  • Go to Admin > Select Property > Property User Management > Add User
  • Copy the Service Account email and select Read & Analyze

Once I have that, pretty much use the following code: https://gist.github.com/CoryFoy/9edf1e039e174c00c209e930a1720ce0 to get the reports.

But I keep getting forbidden: User does not have sufficient permissions for this profile. Even when I try to get the access_token and use it in javascript:

gapi.analytics.auth.authorize({
  serverAuth: {
    access_token: 'accessToken'
  }
});

I get:

error:{
  code: 403
  errors: [  
    {  
      domain: "global"
      message: "User does not have sufficient permissions for this profile."
      reason: "insufficientPermissions"
    }
  ]
}

Am I missing something? This used to work and I never had a problem with it, but for some reason it stopped working. Any guidance will be appreciate it.

Thank you!

UPDATE

UA (Universal Analytics) will stop processing data on July 1st 2023. It means will stop support for it, so you will need to update to Analytics 4.

Articles by Google

Metre answered 18/11, 2020 at 17:37 Comment(0)
M
5

This has something to do with how you create an analytics property. Since they remove the views from analytics 4, now you need to create a universal analytics property.

  • In account click on "Create Property"
  • Fill the fields and click on "Show advance options"
  • Activate "Create a Universal Analytics property"
  • Add the website url in the field and then make sure "Create both a Google Analytics 4 ...." and "Enable enhanced measure interactions on your sites...." are marked.
  • Then click next and that is it.

The code stays the same as this is an analytics change.

UPDATE

UA (Universal Analytics) will stop processing data on July 1st 2023. It means will stop support for it, so you will need to update to Analytics 4.

Articles by Google

Metre answered 2/12, 2020 at 14:11 Comment(9)
this helped me. thanks. funny google doing it's thing, making the new more difficult to use. what a crap companyVanna
Is there a way to edit an existing property and activate "Create a Universal Analytics property" ? (I can find the option when creating as you describe but not when editing...)Astera
@Astera not sure is possible to edit, but I think you can try to create a new universal analytics property and link it to the existing one. After creation of the new property you can go to your current GA4 property, then go to Data Steams > Select the application > Under "Additional Settings" Select "Connected Site Tags" > Then copy paste the tracking code "(UA-12345)" there. I think this is for linking properties. Let me know if that works and I will update my answer to include this part.Metre
Is there a way to access the new Stream ID properties through the API?Pylle
It seems there's a new API; developers.google.com/analytics/devguides/reporting/data/v1/…Pylle
Depending on the language you use you might be able to use the new API. In my case, the rails one is still in alpha I think.Metre
@VictorLuna I'm a bit confused.. I just created a new property (both GA4 and UA), name it "P2" for the exemple. My previous property "P1" is only GA4 (the one I'm trying to access from API). I went to P1 > Data Steams > "Additional Settings" > App > "Connected Site Tags" and added ID UA of P2. Now I can access to P2 UA from API with 0 visits as it's a new property. Should I see P1 visits ?Astera
@Astera that is a good question. To be honest I have not tested it myself. I would assume there is a way to access them I am just not sure how.Metre
@VictorLuna It seems that the visits from P1 (GA4) are visible in P2 (UA) for the time they are connected. But not 100% sure..Astera
P
0

Either UA or for those using GA4 (Google Analytics Reporting for API v4), the solution is the same: use https://ga-dev-tools.google/account-explorer/ logged as some google account who is the owner of your Google Analytics Account (remember that several users can have this permission). Using that tool, you'll be able to easily find your View ID. Besides, it's perfect to those who want to know if their property have or doesn't have a View ID. That tool will show that!

Phenylalanine answered 6/7, 2023 at 21:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.