Learn business growth with Google Analytics 4 › Forums › Google Analytics 4 › Obtaining segmented data from GA4 property report using the Google Analytics API › Reply To: Obtaining segmented data from GA4 property report using the Google Analytics API
-
Dealing with the v1Beta API can feel like you’re trying to have a chat with a stubborn mule, mate. But it’s not all bad, I’ve got a neat PHP workaround that might just do the trick for you.
Check out this PHP class called ‘analytics’. With it, I can set my property ID with setPropertyId, grab the credentials file using private function getCredentials, and get my client set up with getClient.
The clincher is in this ‘get’ function, where I make a ‘runReport’ request. You can input your property id, start and end dates, dimensions, and metrics. It’s a bit like ordering a meal – asking it nicely (obviously) to fetch your desired data within a certain timeframe.
After the response comes in, I use a simple foreach loop to go through the rows, returning the values I need.
So, give this a stab, mate. Incorporating segments is a bit like requesting extra gravy on your chips. Customize as needed and look at your result in different ways by changing the dimensions and metrics. Happy coding!