How To Track Internal Site Search [All URLs] in Google Analytics

Capturing Internal Site Search data is critical to understand the user’s search intent. It will also help you analyze your website UI/UX.

 

The Site Search Reports are available at Behavior > Site Search

Internal_Site_Search_-_Google_Analytics

 

As per Avinash Kaushik, here are some of the questions answered through the site search reports.

  • What is the Frequency of Site Search Usage?
  • What are the Pages from where the Users Initiate Searches?
  • Are Users satisfied with the Search Results?
  • How Different Groups of Users Search Your Site?
  • What is the business outcome if users search on your site?

 

Contents:

 

But Why My Google Analytics Site Search Doesn’t Work?

When the user searches for any keyword in your internal website site search, the URL pattern is generated.

This URL Pattern varies for different types of website, & it depends on your CMS.

Sometimes even after the successful search, the Search URL may or may not contain the Query Parameter or even worse, the Search Term itself!!

But Remember, You can always have a hack around it.

Google Analytics has the option to track the site search, ONLY IF you have the Search Term in Query String Parameter of URL.

example.com?s=google
OR
example.com/search-keyword?d=Desktop&s=google‘, etc

 

Internal_Site_Search_-_Google_Analytics

 

What If..

Query Parameter is present in the URL, but still, Site Search Doesn’t Work

You have to ensure that the google analytics code fires when the URL contains the search parameter. To make sure that the analytics will capture the search term, do the following check.

 

Step – 1: Check if the Google Analytics Hit contains the URL parameters.

Open your Browser Debugger by pressing Ctrl+Shift+C (windows) or  Command + Option + I (MAC)

Do a search > Go To Networks Tab > Filter GA requests by ‘collect?‘ & check if the pageview hit contains the search term in URL Query string parameters.

 

Internal_Site_Search_-_Google_Analytics_Hit

 

If it doesn’t…

then ask your developer to retain the query parameters, you have the option to strip it out in analytics too.

Avoid Redirects if possible.

 

Step – 2: Choose Correct View & Turn on Site Search Feature.

Make sure to choose the correct view & turn on the site search feature.

After turning it on, add the search query parameter, in the last case it would be ‘s’

So for

  • ?d=desktop&search-term=facebook+custom+events‘ it would be ‘search-term’
  • ?q=facebook+custom+events‘ it would be ‘q’
  • & so on..

It doesn’t matter what comes before the ‘?’ , if your search term is in the query string.

& then you’re ready to go.

 

Now…

What If Query Parameter is not present in the URL

Kind of like ‘/search/[KEYWORD]’…

Then, it is obvious that google analytics site search won’t work just by enabling it in View Settings.

There are 2 ways to get around with it

  1. Use Advanced View Filter.
  2. Modify The URL to add the Query Parameter.

 

1.) Using Advanced View Filter

Go To View > Filters > Select Custom > Select Advanced Checkbox.

In the Field A — > Extract A

  • Select Request URI
  • Enter Search URL Format

Eg: If your user searches for ‘facebook events’ & your URL is of type

  • “example.com/search/facebook+events”   then enter /search/(.*)
  • “example.com/search-keyword/facebook+events”  then enter /search-keyword/(.*)
  • “example.com/find/facebook+events/search”  then enter /find/(.*)/search

In the Output To –> Constructor:

  • Select Search Term
  • Enter ‘$A1’

 

Site Search Filter

Note: Select Request URI in Field A  –> Extract A (I forgot this in the gif :/)

 

Click Save & You’re Done.

 

2.) Modifying the URL to contain the Query Parameter.

So in simple words, if you have the URL like ‘example.com/search/{Keyword}

You can simply modify it & send it to analytics as ‘example.com/search?q={Keyword}’.

Now you can enter ‘q’ parameter in the GA site search & start tracking.

Check out the method described below.

 

What if…

URL has 1+ search terms with no Query Parameter

So, if you have a site where search URL has one or more parameters in the format

  • Location+Service
  • Category+Sub-Category
  • & so on..

Lets, take an example

“example.com/search/newyork-gyms”

 

If you are using GTM, you can create a Custom Javascript variable named ‘Modified URL’ & use it to fire Analytics Pageview.

In the below code, enter the URL format as ‘example.com/search/{city}-{service}’  the output would be

‘example.com/search/newyork-gyms?city=newyork&service=gyms’

 

Site Search URL Tracking in Google Analytics

 

Then you can simply use the site search option & enter ‘city’ & ‘service’.

 

Follow the below steps if you are using GTM.

Step – 1:

In GTM, Create a Custom JS Variable (Modified Search URL)  & paste the following code.

Custom Javascript Code: (Modify the URL variable to match your search format)

 

You can use the above script for variety of URL formats

  1. /search/newyork/gyms  —-> Format: /search/{city}/{service}
  2. /search/newyork/gyms/premium —> Format: /search/{city}/{service}/{membership}
  3. /search/newyork-gyms/premium —>Format: /search/{city}-{gyms}/{membership}
  4. etc

 

Note: You can use any named variable. 

 

Step – 2:

Create/Modify Your Analytics. In the Fields To set options, enter the page & the value as the Custom JS variable.

 

Site_Search_URL_Modification

 

Step – 3:

You can use All Pages or Only search pages trigger.

Note: The Modified URL will only be sent when the actual search URL matches the Search URL format you inserted. On the rest of the pages, it will send the normal URL.

Make sure to debug if your trigger is all pages. (Test Image)

D:\Rutu\Digital Analytics\Demo_Site_Search_Digishuffle-_GTM

 

What if

URL has search terms in URL as well as in Query Parameter

So, If your site uses IP tracking & When the user searches for “Best gyms in new york”  & URL is like

example.com/newyork/search?q=Best+gyms+in+new+york

 

In this case, you’ll have to use

  • Advanced View Filter. 
  • Site Search Parameter Option.

OR

  • Modify the URL to Query parameter & Use
  • Site Search Parameter Option.

 

URL has NO search terms in URL as well as in Query Parameter

If you have POST based search on your website,  you can take help of your developer to pass the search term as the query parameter.

For Eg:

Search URL : example.com/search.php to

Modified URL: example.com/search.php?q=facebook+events

Then you can implement our normal site search tracking method.

 

Lastly,

Do You Want To Strip Query Parameters in the Analytics Reports?

What format do you prefer??

 

Page Pageviews
/search/ 12

OR

Page Pageviews
/search/facebook+events 6
/search/google+analytics 4
/search/how+to+do+analytics+audit 2

 

If you prefer the first one & you are using Query Parameters, you can simply check the box in site search settings.

If not…

Then create view filter > Search & Replace & paste the following as per your URL format.

Strip_Search_Query_From_URL

Important Points:

  • Make sure to check the URL in the console, if it has the Query parameters.
  • If you are using one or more search terms in the URL, make sure to input the same format in the GTM url variable.
  • Lastly, comment if you have any doubts or I have missed any URL format. 🙂

 

More Awesome Articles…

6 More Powerful Facebook Custom Events – Part II

Super Guide To Enhanced Ecommerce Tracking via Google Tag Manager [2018]

Google Analytics Audit Checklist – Complete Guide

Automated Cost Data Import – Facebook To Google Analytics

Advanced Guide To Cohort Analysis in Google Analytics

Ritwik is Web Analyst & Growth Hacking Consultant. He loves to write technical & easy to understand blogs for Marketers & Entrepreneurs. Focused on Google Analytics, Tag Management, GScripts & more. Google Certified Professional. A Firm Believer in Teaching -> Learning -> Growing. :)

Privacy Preference Center

Necessary

Advertising

Analytics

Other