Saturday, June 15, 2024
HomeBlogHow 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. This 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.

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:

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:
  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.
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.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments