If you’re using rank tracking software, you likely know when your important search queries return AI Overviews (AIO), Featured Snippets, or People Also Ask (PAA) features in Google search results. But what happens when someone clicks through to your site from one of these features? How can you find out what those visitors do if they end up clicking through to your website?
Example of an AI Overview:

Example of People also ask result:

Example of a Featured snippet:

Video Tutorial
Understanding the URL Structure
The key to tracking these search results and subsequent website visits lies in the URL format. For example, when we search for “how to track URLs with a hashtag” the following URL shows up in the AI overview results:
The key information is the hashtag colon tilde colon text equals part in the URL, #:~:text= followed by the highlighted text. When someone clicks on this link, their browser takes them directly to the highlighted section of the page.
However, tracking this in GA4 requires a bit more effort than simply following how to track URLs with hashtags. These types of URLs can’t be captured with that method and you’ll need to use some JavaScript to capture the value and then send it off to GA4 for your analysis.
🚨Important Note: There is no difference in how the URL appears when visitors come from AI Overviews, Featured Snippets, or the People Also Ask feature—it all looks the same. Additionally, not every link from these features includes this URL feature, so you won’t be able to track visitors every time they follow a link from one of these search features. We know that analytics isn’t perfect, so in the spirit of tracking what you can and not stressing over what you can’t, let’s get into it.
Turn messy analytics into meaningful insights
Step 1: Add JavaScript Variables in Google Tag Manager
To capture this information from the URL, we are using a technique that was created by Brodie Clark. We’ve modified it to separate out the two parts of the text in the URL: the start of the highlighted text and the end of the highlighted text.
To track highlighted text from AIO and PAA links, we need to create two custom JavaScript variables in GTM.
Create the Snippet Start Variable
- In GTM, navigate to Variables.
- Scroll to the User-Defined Variables section and click New.
- Under Variable Configuration click the Pencil Icon and choose Custom JavaScript. Paste the following code:
function() {
var entries = decodeURIComponent(performance.getEntries()[0].name.match(“#:~:text=(.*)”)[1]);
var frag = entries.replace(/, /g,”*”).replace(/,/g,”…”).replace(/\*/g,”, “);
var splitArray = frag.split(“…”);
return splitArray[0];
}
- Name the variable whatever you like. If you would like to use our naming scheme, name it “JS – URL Snippet Start” and click Save.
Create the Snippet End Variable
- Create another Custom JavaScript Variable (following steps 1-3 above).
- Paste the following code:
function() {
var entries = decodeURIComponent(performance.getEntries()[0].name.match(“#:~:text=(.*)”)[1]);
var frag = entries.replace(/, /g,”*”).replace(/,/g,”…”).replace(/\*/g,”, “);
var splitArray = frag.split(“…”);
return splitArray.slice(1).join(“…”);
}
- Name it whatever you’d like—we would call it “JS – URL Snippet End” and click Save.
Step 2: Send the Data to GA4
Now that we have these variables set up, we can send the information off to GA4 through an event. You have two options here: add it to your page_view event (if you have a page_view tag set up in GTM), or create a new event. We’ll cover both options.
Option 1: Add Parameters to an Existing page_view Event in GTM
If your GTM container already has a page_view event, edit it to add two new event parameters:
- In GTM, find your page_view tag and Edit it.
- Scroll down to the event parameters and click Add parameter twice. Here are the parameters that you’ll add. Remember to change the value parameter if you named your variables something different!
- First parameter:
- Event Parameter: snippet_text_start
- Value: {{JS – URL snippet start}}
- Second parameter:
- Event Parameter: snippet_text_end
- Value: {{JS – URL snippet end}}
- Click Save.
- First parameter:
Don’t forget to test and publish after you’ve made your changes!

Option 2: Create a New GA4 Event in GTM
If you don’t have a separate page_view tag or prefer a dedicated event for tracking this data, follow these steps:
- In GTM, go to Triggers and click New.
- For the Trigger Configuration select Trigger Type as Page View.
- In the “This trigger fires on” section, select the option Some Page Views.
- In the “Fire this trigger” section, in the first drop down, select the variable you created. In our example we named the variable “JS – URL snippet start”. Then, select does not equal from the middle drop down. In the last box, enter undefined.

- Name the trigger whatever you’d like. We would name it “Page View – URL snippet start exists” and click Save.
- Next add the tag. Click Tags and then New.
- Click in the Tag Configuration area, then from the sidebar select Google Analytics, then Google Analytics: GA4 Event.
- Enter your GA4 Measurement ID in the Measurement ID box, or if you’re using a variable for your GA4 Measurement ID, click the block and select your variable.
- In the Event Name box, enter snippet_text or whatever you want to name this event, this is our recommendation. If you’re having trouble with event names, check out our guide!
- Scroll down to the event parameters and click Add parameter twice. Here are the parameters that you’ll add. Remember to change the value parameter if you named your variables something different!
- First parameter:
- Event Parameter: snippet_text_start
- Value: {{JS – URL snippet start}}
- Second parameter:
- Event Parameter: snippet_text_end
- Value: {{JS – URL snippet end}}
- First parameter:
- Scroll down and click in the Triggering section to pull up the list of triggers in your container.
- Select the Trigger that you saved in step 5.
- Name your tag. In our example we named it “GA4 – Event – snippet_text”
- Click Save.
- Now Add as a Custom Dimension in GA4 (see the instructions below)
Don’t forget to test and publish after you’ve made your changes!
Your clients expect great data and insights
Step 3: Add Custom Dimensions to GA4
In order to view this information in GA4, we’ll need to create two custom dimensions. Hop over to your GA4 account:
- Click the Admin gear icon at bottom left of the screen.
- Click Custom definitions in the Data display section.
- Click Create custom dimension.
- In the New custom definition sidebar, enter these options:
- Dimension Name: Snippet Start (or whatever you’d like)
- Scope: Event
- Description: (Optional)
- Event parameter: snippet_text_start (or whatever you named this event parameter in GTM)
- Click Save.
- Again, click Create custom dimension.
- In the New custom definition sidebar, select these options:
- Dimension Name: Snippet End (or whatever you’d like)
- Scope: Event
- Description: (Optional)
- Event parameter: snippet_text_end (or whatever you named this event parameter in GTM)
- Click Save.
Now you will be able to view the start and end of the snippet text in the URL when visitors come to the site with the snippet URLs.
How To Analyze AI Overview, Featured Snippet, or People Also Ask Data in GA4
Now that we’re capturing this text, what can we do with it? Once you’ve collected some data, you can:
- Create Reports: A really useful way to look at this data is by landing page. You can ask yourself questions like:
- What snippet text drives the most traffic?
- Do people who come to your site via these search features end up converting?
- Do these visitors consume your content?
- Create an Audience: You can create an audience in GA4 for people who triggered your snippet event (if you created a separate event) or who had a value in the Snippet Start or Snippet End dimensions (if you added these to the page_view event). We have a walkthrough on creating audiences in our post on tracking Black Friday traffic.
- Blend GA4 with Other Sources in Looker Studio: Use Looker Studio to blend your GA4 data with insights from your rank tracking software or Google Search Console. This can help you answer questions such as:
- What searches are bringing up these features in search results?
- Is there a particular search query or search feature that is more likely to bring engaged visitors to my site?
Let us know in the comments of our YouTube video what you’re doing with this data!