Learn business growth with Google Analytics 4 Forums Google Analytics 4 Retrieving a List of Accounts in Google Analytics 4 Admin

  • Retrieving a List of Accounts in Google Analytics 4 Admin

    Posted by Mathew on 18 October 2022 at 7:56 pm

    Heya pal, could use your help here!

    So I’m messing around with the PHP library for the new GA4 Admin, trying to get a list of all the accounts I’ve got under my name. In total, should be 5:

    Andy Test 1  (old google analytics account - account id 1)
    Andy Test 2  (old google analytics account - account id 2)
    Andy Test GA4 - 1  (GA4 account - account id 3)
    Andy Test GA4 - 2  (GA4 account - account id 4)
    Andy Test GA4 - 3  (GA4 account - account id 5)
    

    I thought running this piece of code would do the trick:

    echo("Poking around listAccountSummaries:");
    foreach( $analyticsAdminServiceClient->listAccountSummaries() as $account_summary ){
        echo(" -- Name: {$account_summary->getName()}");
        echo(" -- Account: {$account_summary->getAccount()}");
    }
    echo("Done poking around listAccountSummaries");
    

    But nope, instead it just spit out:

    Starting with listAccountSummaries:
      -- Name: accountSummaries/236841924
      -- Account: accounts/236841924
    That's the end of listAccountSummaries
    

    On top of that, the function “listAccounts” doesn’t work any better:

    echo("Now testing listAccounts:");
    foreach( $analyticsAdminServiceClient->listAccounts() as $account ){
        echo(" -- " . $account->getName());
    }
    echo("Finished testing listAccounts");
    

    It just says:

    Testing listAccounts:
      -- accounts/236841924
    The test ends here
    

    What’s the deal? Why aren’t I seeing all the accounts? Sure, maybe it doesn’t show the older analytics accounts, that’s fine. But then why only one of the GA4 accounts when I have three?

    Jesse replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Isaiah

    Member
    23 June 2023 at 12:59 pm

    It’s possible that the code is working correctly, and only showing accounts that are associated with your GA4 Admin. It might be that only one of your GA4 accounts is registered with the GA4 Admin and the others are not. Another possibility is that your query only has clearance to see a certain number of accounts and not others. Alternatively, it could be a bug with the PHP library itself. The best way to determine what’s going wrong would be to cross-check the accounts that the code is able to see with the accounts associated with your GA4 Admin, to confirm if all of the accounts are being accounted for. If they’re not, it might be a problem with the PHP library, and if they are, it might be an issue with how the accounts are registered with GA4 Admin.

  • Jesse

    Member
    4 July 2023 at 5:55 am

    The issue you’re experiencing might be linked to the permissions of the account used to create and authenticate your PHP client. Whether you’re using OAuth 2.0 or a Service Account for authentication, the account needs to have sufficient rights across all the accounts you’re trying to access. If the account only has access to one of your GA4 accounts, it would explain why you’re only seeing one result. To fix this issue, review the account’s permissions on all your GA4 and old Google Analytics accounts, ensuring it has enough access. If your account has appropriate permissions yet you’re still facing the issue, there may be a problem with the Google Analytics Admin API, specifically with the “listAccountSummaries()” and “listAccounts()” methods. You might want to refer to the API documentation or reach out to Google’s support for a possible solution or workaround.

Log in to reply.