Learn business growth with Google Analytics 4 Forums Google Analytics 4 Troubleshooting issue with fetching Google Analytics 4 accounts in PHP

  • Troubleshooting issue with fetching Google Analytics 4 accounts in PHP

    Posted by Liam on 2 December 2022 at 2:15 pm

    “Hey folks, I’ve hit a snag. I’m trying to shift code from our development set-up to a staging environment. I’ve set up a project, an oauth client, user, and a service account in it. My Analytics console shows me the first account with a property attached.

    Now, here’s the curve-ball: when I run the attached code, it says there are no accounts. I’m confused because the right key file is used for my Google project and the project_id is right there in the key file. I even gave admin access to the service account temporarily. Can anyone shed some light on why the listAccountSummaries call doesn’t give back anything? By the way, this code does its magic in the development environment which is a different Google project. Thanks!”

    Liam replied 11 months, 2 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Emily

    6 December 2022 at 2:54 pm

    Hey there! So, turns out it was a small hiccup really. I had granted access to my User, instead of the service account itself. But once I switched that around and gave the access to the service account, everything started working perfectly. Oh boy, it was right there all along!

  • Liam

    26 March 2023 at 10:23 pm

    Your issue might be related to the permissions of the service account you set up in the Google Cloud Platform console. It could be possible that your service account doesn’t have the proper permissions in Google Analytics to access account data. If you’ve given the service account the necessary permissions temporarily, it might still take some time for permissions to propagate. Make sure that in the Google Analytics Admin settings, under Account User Management, your service account email is listed with “Read & Analyze” permissions at minimum. If the problem insists, you might want to cross-check if the key file is associated with the same account that has been granted the permissions.

Log in to reply.