Saturday, July 27, 2024
HomeAI in SearchHow to Track Google AI Overview (SGE) in GA4

How to Track Google AI Overview (SGE) in GA4

AI Overview is a Google Search feature that uses Generative AI to summarize search results. It was called “Search Generative Experiment” or “SGE”. They adopted AI Overview as they rolled out as a live feature in the US.

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.

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 Alos Ask – the scroll-to-text fragments.

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”

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

Found this video from KP Playbook explaining in detail

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 Group Head, SEO.
RELATED ARTICLES

7 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