-
Retrieving Organic Search Data with Google Analytics 4 API
Hey there, I’m digging into the google analytics 4 API these days, pulling some of the analytical data out into the open. But, I just can’t seem to nab that pesky Organic search data – it’s a slippery little sucker. Has anyone else had this issue before?
Now, I’ve got the code for the other metrics taped down, it’s working a charm. Got my totalUsers, newUsers, sessions, screenPageViews, engagedSessions, and activeUsers all reporting in, nice and neat.
You know, I thought I’d use the defaultChannelGrouping to pull in the organic search data, but I’m coming up empty handed. Not a single helpful document to give me a hint! Check out the sample of what I’ve been trying:
$response = $this->data_client->runReport([ 'property' => $propertyId, 'dateRanges' => [new DateRange(['start_date' => '7daysAgo', 'end_date' => '1daysAgo'])], 'dimensions' => [ new Dimension(['name' => 'defaultChannelGrouping']), ] ]); foreach ($response->getRows() as $row) { foreach ($row->getDimensionValues() as $dimensionValue) { print 'Dimension Value: ' . $dimensionValue->getValue() . "<br/>"; } }
As you see, I’m running in circles. Anyone up for helping a fellow coder out?
Log in to reply.