-
Retrieving a List of Accounts in Google Analytics 4 Admin
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?
Log in to reply.