Edit
Contact us
Salocin Group Leaders in data and AI-enabled connected customer experiences
Edit Engineers of connected customer experiences
Join the Dots Independent, data-led media thinking for sustainable growth
Wood for Trees Optimisers of future fundraising performance
  • Home
  • Our services
    • Cloud solutions
    • Data science
    • Modern Data Platform
    • Privacy and AI compliance
  • Our partners
    • Microsoft
    • Apteco
    • Salesforce
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Salocin Group
    • Careers
  • Contact Salocin Group
  • Home
  • Who we are
    • B Corp
    • Careers
  • Our work
  • What we do
    • Intelligent data
    • Marketing technology
    • Transformational CRM
    • Our technology partners
    • Privacy review
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • Contact Edit
  • Home
  • Broadcast media
  • Digital media
  • Print
    • Direct mail
  • Data
    • Our work with Herdify
    • EPiC
  • Media agency
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Join the Dots
    • Careers
  • Contact Join the Dots
  • Home
  • Services
    • Actionable insight
    • Data discovery
    • Data engineering
    • Data hygiene
    • Privacy review
  • Products
    • InsightHub
    • Apteco
    • Microsoft
    • Data management
    • Consent and preference management
  • Our insights
    • Blog
    • Case studies
    • Reports
    • Webinars
    • Whitepapers
  • About Wood for Trees
    • Operating principles
    • Careers
  • Contact Wood for Trees
Blog

How to track internal site search using Google Tag Manager

By Edit | 21 Jun 2017

We published this a long time ago…

Some of the content in this post might be out of date, and some images and links may no longer work.

Discover who we are and how we may be able to help you today:

Learn more

I hope you all enjoyed Search Leeds 2017. I had a fun time, too. One talk in particular stood out, Stephen Kenwright’s How to be Amazon (and beat Google at Search).

I’d like to thank @stekenwright for saying I’ve written a blog post on tracking site search via GTM… I guess I need to finish that one.

Emma Barnes (@ejbarnes89) June 15, 2017

Guess I need to get cracking.

To be fair to him, I have written a few blog posts about this topic…

How to double conversion by using Site Search

How to automatically track events with Google Tag Manager

The time I did an investigation as to why everyone searches for “Stardoll” on the B3 site”

How to extract site search terms from subfolders in Google Analytics

So, he’s not wrong, I’ve sort of done this already. Just not as one piece.

Forget about GTM for a minute, let’s focus on Google Analytics

By default, Google Analytics does not track any internal site search for you, meaning you have to tell it “please can you tell me what keywords people type into my search bar”. This is how to track internal site search in Google Analytics:

  • Go to Admin
  • Go to View Settings
  • Go to Site Search Setting
  • Tick Site Search Tracking>On
  • Add your query parameter
  • Optional: Add categories if your site search uses categories
  • Save

PROTIP: Create a Lowercase Filter for Search Term, it means that people searching for “SEO” and “seo” are both tracked under the search term “seo”. Without this, they’re treated as separate keywords.

To view the internal site search report it’s in Behaviour>Site Search.

And you can see all sorts of delights and wonders:

Percentage of people who use site search on your site

Search terms

Tracking “No Results” with Google Tag Manager

By default, you don’t get to see whether the searches returned any results. Tracking searches with “no results” is a really good way to generate ideas for content, among other things.

Every website’s site search is configured differently, so this explanation is for Branded3 – hopefully you can use the same methods for your own website. If you’d like additional  help, please contact us.

Search your website for a query you know will return no results

If you can’t think of a phrase, just mash your keyboard and hit enter.

Take note of the message that displays

In the above, you can see that “No Results found” displays. In Google Analytics, I want to see the amount of pages where this message fires. Inspect the element to find the element ID.

In this case, it’s #search-results, which funnily enough is our motto (or close enough).

Create a Variable in Google Tag Manager to extract the element

In GTM, go to Variables>User-Defined Variables>New to create a new variable.
Create a Dom Element variable with the Selection Method CSS Selector, and input your selector name. I’ve used #search-results in this case.

Create a lookup table variable to sort between “No Results” and “Results”

Create another new variable, this time choosing Lookup Table. Give it the Input Variable that you just created (I called it “Search Result”). Here, I am able to create a rule that says “if the CSS Selector #search-results says “No results found”, call this “No Results”, and if it doesn’t say that, call it “Results””. I do this by giving it one lookup value (match No results found to -> No results) and a default value of “Results”. Save your query

Bonus round – Create a variable to track the keyword used

You don’t have to do this, but it will add value to your report. I created a variable to extract the search query from the URL. You need to create a URL variable with the Query component type. Add your Query Key (which should be the same as the Query Parameter from Google Analytics). Save your query.

Create a trigger to fire on search results pages

Go to Triggers>New to create a new trigger. You need to choose a Page View – Dom Ready trigger. Choose Some DOM Ready Events. Create a rule for “url contains [search results page string]”. In my case, this is any page including /?s=.

Create an event tag to fire search results as an event to Google Analytics

Go to Tags>New to create a new tag. You need to choose a Universal Analytics tag (if you’ve not migrated to Universal Analytics… please do, I wrote a guide). You need to choose Track Type Event. I’ve given the events the Category: Search Used, the Action: {{Search Value Results}} (this is the lookup table we created earlier) and Label: {{page query}} (the keyword extractor variable). Set Non-Interaction Hit to True and configure your Google Analytics as you normally would.

Set the Trigger to the Search results trigger that we just created and save the tag.

PROTIP: Use the GTM Debugger to see if this works, and amend as required! Every website will be different.

Once tested, push the tag live.

Analyse your results using the event report

To see your new events, go to the Google Analytics report called Behaviour>Events>Top Events and search for the “Search Used” event category (or whatever you named it).
Click it and you can see what searches had results or not:

You can then click into Results or No Results to analyse which keywords came back with or without results.

And there you have it! Please enjoy your new data!

We published this a long time ago…

Some of the content in this post might be out of date, and some images and links may no longer work.

Discover who we are and how we may be able to help you today:

Learn more

Share this

  • Email
  • WhatsApp
  • LinkedIn
  • Facebook
  • X (Twitter)

More insights

AI isn’t going to take your job (unless you really want it to) 
Blog

AI isn’t going to take your job (unless you really want it to) 

By Edit | 18 Jun 2024
Customer relationship marketing: How generative AI is revolutionising engagement  
Blog

Customer relationship marketing: How generative AI is revolutionising engagement  

By Edit | 4 Apr 2024
Personalisation as a process
Blog

Personalisation as a process

By Edit | 8 Mar 2024
  • Privacy policy
  • Cookie policy
  • Ts&Cs
  • Report a concern

© 2025 Edit, part of Salocin Group Ltd. All rights reserved. Company no.: 0362​4881. VAT no.: 4208​34911.

Salocin Group Certified B Corporation | Cyber Essentials Certified | British Assessment Bureau, ISO 27001 Information Security Management
Salocin Group
Your cookie preferences

We use cookies to ensure this website functions properly, to analyse website traffic and for marketing purposes.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}