Tracking People Also Ask in GA4 (Google Analytics 4)

Following is an example of PAA (People Also Ask) on Google SERPs (Search Engine Result Pages):

people also ask

For PAAs on Google SERPs, many of the URL paths contain #:~:text=.

For example, when you click on the link below:

people also ask click on the link 2


You will be redirected to the following URL:

https://www.wrp.team/blog/why-is-google-moving-from-universal-analytics-to-ga4-amp-what-is-going-to-change#:~:text=Privacy%20has%20been%20a%20big,privacy%20front%2Dof%2Dmind.
text fragment


The #:~:text= in the URL above is called Text Fragments

This feature allows a link to specify a text snippet in the linked document, and upon clicking the link, the browser will scroll to and highlight that specific text snippet if it is found on the page.

This feature is particularly useful for highlighting specific parts of long articles or documents online.

In its SERPs, Google often uses text fragments for ‘featured snippets’, ‘People Also Ask’, or other highlighted search results. 

This feature primarily enhances the user experience by directly pointing them to the most relevant part of a webpage based on their search query.

This functionality is a part of Google’s ongoing efforts to make information more accessible and to improve the efficiency of search results by reducing the time users spend looking for specific information on a webpage. 

For PAA tracking in GA4, follow the steps below:

1) Create a JavaScript variable in GTM to detect the ‘#:~:text=’ fragment in the URL:

JavaScript variable
function() {
    var url = window.location.href;
    var textFragmentIndex = url.indexOf('#:~:text=');
    if (textFragmentIndex !== -1) {
        // Extracting and decoding the text fragment
        return decodeURIComponent(url.substring(textFragmentIndex + 11));
    }
    return undefined; // Return undefined if the fragment is not present
}

Name this variable something like ‘URLTextFragment‘.

2) Create a ‘History Change’ trigger that listens for changes to the URL fragment.

This type of trigger listens for changes in the URL after the page loads (useful for single-page applications or instances where the URL fragment changes after the initial page load).

Name your trigger, such as ‘HistoryChangeForTextFragment‘.

3) Create a GA4 Event tag to send an event to GA4 whenever the trigger (‘HistoryChangeForTextFragment’) fires.

Set the event name to something indicative of the action, like ‘paa_click‘.

4) Test the tracking setup by visiting your website and simulate the conditions for triggering the tag (like navigating to a URL with the #:~:text= fragment).

5) Check that the trigger fires and the tag sends an event to GA4.

6) Once you’ve confirmed everything is working, publish your changes in GTM.

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

About the Author

Himanshu Sharma

  • Founder, OptimizeSmart.com
  • Over 15 years of experience in digital analytics and marketing
  • Author of four best-selling books on digital analytics and conversion optimization
  • Nominated for Digital Analytics Association Awards for Excellence
  • Runs one of the most popular blogs in the world on digital analytics
  • Consultant to countless small and big businesses over the decade