Sunday, December 22, 2024
HomeAI in SearchHow to Track Google AI Overviews (SGE) in GA4

How to Track Google AI Overviews (SGE) in GA4

Google AI Overviews is a Google Search feature that uses Generative AI to summarize search results. It was called “Search Generative Experiment” or “SGE”. Google Overviews is now part of search results in the US and not an experiment. It shows up for both signed-in and signed-out users.

AI Overviews works similar to a “Featured Snippet” but with more context & citations. AI Overviews is live in the US for logged-in users and continues to be an experimental feature outside the US.

To enable the feature outside the US, log into Google Search Labs and click the “Turn On” button.

AI Overviews experiment in search labs
Clicking on “Turn on” enables AI Overview Experiment on Google Search

Recently I noticed that links cited in AI Overviews have fragments (the part of the URL after the #, such as #section). This takes the users to the specific part of the content that answers the search or is cited in the AI Overview.

In the case of Google AI Overviews (SGE), the Fragment path is “#:~:text=“. This is similar to the fragments seen for Featured Snippets & People Also Ask – the scroll-to-text fragments.

URL fragments in AI Overviews
The part of the URL highlighted in yellow is the Fragment

Tracking URLs with fragments in Google Analytics 4 (GA4) can be tricky because fragments are not sent to GA4 by default. However, you can set up custom tracking to capture these fragments using Google Tag Manager (GTM) and GA4 event tracking. Here’s a step-by-step guide on how to do this:

Method 1: Using Custom JavaScript

Step-by-Step Guide to Track URL Fragments in GA4

1. Set Up Google Tag Manager (GTM)

Ensure you have GTM installed on your website and that it is properly linked to your GA4 property.

2. Create a Custom JavaScript Variable in GTM

You would need a variable that captures the URL fragment.

  1. In GTM, go to Variables.
  2. Click New and choose Variable Configuration.
  3. Select Custom JavaScript.
  4. Enter the following code to create a variable that captures the URL fragment:
function() 
{
  return window.location.hash;
}

5. Name this variable, e.g., URL Fragment.

3. Create a GA4 Event Tag in GTM

Set up a tag that sends the fragment data to GA4.

  1. Go to Tags and click New.
  2. Choose Tag Configuration and select GA4 Event.
  3. Configure your GA4 Event tag:
    • Configuration Tag: Select your GA4 configuration tag.
    • Event Name: Enter an appropriate event name, like fragment_view.
    • Event Parameters: Add a parameter to capture the fragment.
      • Parameter Name: url_fragment
        • Value: Choose the URL Fragment variable you created earlier.
  4. Set up a trigger for this tag:
    • Click Triggering and select Page View.
    • Click the plus icon to create a new trigger.
    • Name the trigger, e.g., All Page Views.
    • Choose Page View as the trigger type.

4. Configure GTM to Capture Fragment Changes

By default, GTM only captures the initial page load. To track fragment changes, you need an additional setup.

  1. Go to Triggers and click New.
  2. Choose Trigger Configuration and select History Change.
  3. Name this trigger, e.g., Fragment Change.
  4. Set up the trigger with the following configuration:
    • Enable this trigger when all of these conditions are true: Select Page URL matches .* (using Regex).
  5. Save the trigger.

5. Link the Fragment Change Trigger to Your GA4 Event Tag

Ensure the event tag also fires on fragment changes.

  1. Go back to the GA4 event tag you created.
  2. Under Triggering, add the Fragment Change trigger.

6. Publish Your GTM Container

After setting up the tags and triggers, publish the changes in GTM.

7. Verify Data in GA4

Check GA4 to ensure the event with the URL fragment parameter is being captured correctly.

  1. Go to your GA4 property.
  2. Navigate to Events and look for the fragment_view event.
  3. Check the event parameters to see if url_fragment is being recorded.

Method 2 – Using location.href

The location.href returns the full URL path including the fragments. To see this, go to the page and inspect elements >console> type “location.href”

using location.href to track AI overviews
location.href returns the URL with Fragments (here: #test)

Using Javascript Variable in Google Tag Manager

  1. Go to Google Tag Manager
  2. Click on “Variables” in the left-hand menu of Google Tag Manager
  3. Scroll down to “User-Defined Variables” section and click “New”
  4. Add a name for the new variable. Name the Variable as “location.href_jsv”
  5. For Variable Type select “JavaScript Variable”
  6. Then under Global Variable Name type in “location.href”
  7. Click “Save”
Adding the JavaScript Variable for location.href

Now we need to add this Variable to the GA4 page_location parameter:

  1. Click on “Tags” in the left-hand menu
  2. Select the Google tag or create a new tag with “google tag” as tag type
  3. Open the “Shared event settings” section
  4. Add “Add parameter” in the Event Parameter section
  5. In the Event Parameter field, enter: page_location
  6. Add {{location.href_jsv}} as the Value (or you can click on the block to select the Variable added before – “location.href_jsv”)
  7. Click “Save”
Adding GA4 page_location parameter in GTM

To Track in GA4, create a new event:

  1. Go to GA4 >Admin>Events
  2. Click on “Try it now” which allows you to create and manage custom dimensions and metrics in Custom definitions.
  3. Add Dimension name and Description
  4. Now choose “page_location” as Event parameter
  5. Click on Save
Adding the Custom dimension in GA4 for page_location

Limitations of using GA4 to Track Google Overviews

Using URL Fragments to track GA4 has a few limitations:

1. URL Fragments is not limited to Google Overviews

The Fragment path is “#:~:text=” also applies to Featured Snippets and People Also Ask SERP elements. Therefore, not all events reported in GA4 may not be from Google Overviews alone.

Solution: With tools like Semrush or Ahrefs, you can track SERP elements like Featured snippets and PAA. This data can be used to attribute the events in GA4 accordingly.

2. Events may be double-counted

Reloading the page with URL Fragments can trigger the event again leading to double counting the event tracked in GA4 for URL Fragments.

Solution: You can set the event to trigger once in Google Tag Manager. This could potentially remove duplication of event tracking.

3. In some cases, Links in Iverviews may not have URL Fragments

I have seen in some rare instances where Google Overviews cites the page without URL fragments. This can be due to Google not being able to highlight what text to scroll into or the information cited in the Overviews being in tables or other data formats that Google can’t highlight.

Solution: If your links cited in Overviews don’t have URL fragments, add a line or a paragraph addressing the query. This will allow Google to highlight the text and append the URL fragment to the relevant section.

Does Google Search Console (GSC) report AI Overviews?

Yes GSC reports clicks, impressions, and positions of links in AI Overviews. However, GSC doesn’t include data from the AI Overviews experiment.

Since the AI Overviews is live across 100 countries, we will have more data reported in GSC.

Google documentation on AI Overviews reporting in GSC

Subscribe to Our Newsletter!

Sachin Shaji Kalloothara
Sachin Shaji Kalloothara
Sachin Shaji Kalloothara is a Digital marketer with 6 years of experience in SEO and PPC. He currently works in HiveMinds as Senior Account Director.
RELATED ARTICLES

15 COMMENTS

  1. Thanks for making the documentation simple and easy to follow for non tech people. I implemented it on my blog and this works. Went with the location.href method

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments