Learn business growth with Google Analytics 4 Forums Google Analytics 4 Retrieving Organic Search Data with Google Analytics 4 API

  • Retrieving Organic Search Data with Google Analytics 4 API

    Posted by Logan on 30 June 2022 at 11:52 pm

    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?

    Isabella replied 1 year, 2 months ago 3 Members · 2 Replies
  • 2 Replies
  • Daniel

    Member
    20 November 2022 at 2:15 am

    Sure thing! I think you might have better luck using sessionDefaultChannelGrouping instead of defaultChannelGrouping. This guidance comes from Google Analytics 4’s migration guides, which suggests the use of sessionDefaultChannelGrouping in GA4, much like how we used ga:channelGrouping in Universal Analytics.

    Here’s the thing to note though: defaultChannelGrouping is an attribution dimension. Meaning, if your GA4 property’s event attribution model is set to Data-driven, you aren’t going to get any rows from defaultChannelGrouping if your GA4 property hasn’t had a conversion during the date range you’ve selected.

    I know, it’s a little finicky, but swap it around and you should start seeing that Organic search data roll in. Fingers crossed!

  • Isabella

    Member
    28 June 2023 at 8:35 am

    The problem seems to be that Google Analytics 4 (GA4) doesn’t provide the built-in dimension defaultChannelGrouping that was available in Universal Analytics. GA4 uses a different approach for reporting and doesn’t come with pre-processed data, hence things like Acquisition channels are not readily available. It is recommended to use traffic sources dimension instead. Since GA4 seems to focus more on raw data, it provides more data handling possibilities but requires more processing. You may have to build your own defaultChannelGrouping dimension using the available dimensions in GA4. For Organic search data specifically, you can also consider sending utm parameters to Google Analytics to categorize the traffic, which could be done using the Medium dimension to identify the organic traffic. However, one key is to remember that reports/data pulling might be a bit different with GA4 as it requires a bit more of pre-processing.

Log in to reply.