Last Updated on May 25, 2019 by Ritwik B
Site search is one of the most important elements on your website which helps you analyze your customer needs.
It’s also a good way to enhance user engagement esp. for ecommerce sites. But capturing site search terms may not always be an easy task.
In this article, we’ll be looking at a whole lot of things related to google analytic’s site search feature. So without further ado, let’s get started…
1.) How Does Site Search Tracking Work & Ways To Properly Setup in Google Analytics?
2.) List of All The Search Metrics in Site Search Reports?
3.) Reasons Why Your Site Search Doesn’t work & Ways To Fix It.
How Does Site Search Tracking Work & Ways To Properly Setup in Google Analytics?
Let’s first understand how google analytics captures site search terms by default.
In fact, just by placing the analytics code on your website doesn’t enable Google Analytics to track site search terms. There’s one more thing you have to enable to get it going.
Here are the steps to properly set it up:
- Go To Admin & Select a VIEW from the dropdown.
- Go To View Settings (& Scroll down a bit)
- Enable the Site Search Tracking feature.
- Enter the query parameter, (say ‘s’) click Save.
And it’s done..!!
So, How Does Google Analytics Knows When to Track Search Terms.??
The way this works is
- On every page load, Google Analytics will check the URL & the parameters.
- If the parameter matches the one you mentioned in the view settings > site search feature, google analytics will start capturing various site search metrics for that session. Such as
- Sessions with Search
- Avg. Search Depth
- Unique Searches
- & more…
So, even if you manually type the query parameter on the page, say www.example.com?s=black+shoes & hit refresh…
Google Analytics will think it’s a site search & will capture the “black shoes” terms along with its related site search metrics.
Btw, its good way of testing if your site search works or not.
List Of All The Site Search Metrics Available In Site Search Reports.
Once Everything has been set up correctly, the reports will get populated in the Behaviour > Site Search section in 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?
Here are some of the site search metrics available.
- Sessions with Search
- Total Unique Searches
- Results Pageviews / Search
- % Search Exits
& Here are some of the dimensions
- Site Search Status
- Start Page
- Destination page
- Search Destination Page
Here’s the full list below:
Dimension/Metrics | Description |
---|---|
Site Search Status | A boolean, either Visits With Site Search or Visits Without Site Search, to distinguish whether internal search was used in a session. |
Site Search Category | The category used for the internal search if site search categories are enabled in the view. For example, the product category may be electronics, furniture, or clothing. |
Start Page | The page where users initiated an internal search |
Destination Page | The page users immediately visited after performing an internal search on the site. This is usually the search results page. |
Search Destination Page | The page that users visited after performing an internal search on the site. |
Sessions with Search | The total number of sessions that included an internal search. |
Total Unique Searches | Total number of unique keywords from internal searches within a session. For example, if "shoes" was searched for 3 times in a session, it would be counted only once. |
Results Pageviews / Search | The average number of times people viewed a page as a result of a search. |
% Sessions with Search | The percentage of sessions with search. |
Search Depth | The total number of subsequent page views made after a use of the site's internal search feature. |
Avg. Search Depth | The average number of pages people viewed after performing a search. |
Search Refinements | The total number of times a refinement (transition) occurs between internal keywords search within a session. For example, if the sequence of keywords is "shoes", "shoes", "pants", "pants", this metric will be one because the transition between "shoes" and "pants" is different. |
% Search Refinements | The percentage of the number of times a refinement (i.e., transition) occurs between internal keywords search within a session. |
Time after Search | The session duration when the site's internal search feature is used. |
Search Exits | The number of exits on the site that occurred following a search result from the site's internal search feature. |
% Search Exits | The percentage of searches that resulted in an immediate exit from the property. |
Site Search Goal Conversion Rate | The percentage of search sessions (i.e., sessions that included at least one search) which resulted in a conversion to at least one of the goals. |
Per Search Goal Value | The average goal value of a search. |
Reasons Why Your Site Search Doesn't work & Ways To FIX It.
Well, there’s always something in google analytics which doesn’t work as expected & one of them is site search tracking.
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
There might be several reasons but they are mainly categorized as follows:
- Site Search Term in present in the URL
- As Query Parameter
- Single Term
- Multiple Term
- Not As Query Parameter
- Single Term
- Multiple Term
- As Query Parameter
- Site Search Term NOT present in the URL
1.) Site Search Term Is Present in the URL: As Query Parameter
If the URL contains site search term as query parameter & still the reports are not getting populated, then check the following steps.
1.) 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 single Site Search Terms like
- ?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.
IF you have multiple Site Search Terms
- ?d=desktop&search-term=facebook+custom+events‘ it would be ‘search-term’ & ‘d’
- ?q=facebook+custom+events&page=/‘ it would be ‘q’ &’page’
You can enter every term with “,” in between. (search-term,d or q,page)
2.) Check if the Google Analytics Hit contains the URL parameters.
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.
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 variable “dl” in the pageview hit contains the search term in URL Query string parameters.
If it doesn’t…
then ask your developer to retain the query parameters, you have the option to strip it out in analytics too.
If you don’t see the pageview hit request, then check if you have installed GA code on search results page.
3.) Avoid Redirects if possible.
2.) Site Search Term Is Present in the URL: NOT As Query Parameter (Single Term)
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
- Use Advanced View Filter.
- 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’
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.
3.) Site Search Term Is Present in the URL: NOT As Query Parameter (Multiple Terms)
So, if you have a site where search URL has one or more site search terms in the URL in a format like
- Location+Service
- Category+Sub-Category
- & so on..
we can use GTM to modify the URLs & send it to Google Analytics with site search query parameter.
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’.
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)
function URL2Query() { var url = '/search/{city}-{service}' // Input The Search URL Format var urloutput = location.href; var variableReg = new RegExp(/({\w+})/g) var url_variable = url.match(variableReg); var txt = '' var reg = new RegExp(url.replace(/({\w+})/g, '([^\?|\/|&]+)')) var variable = reg.exec(urloutput) for(var i=0; i< url_variable.length; i++) { if(i==url_variable.length-1) { txt+=url_variable[i].replace(/{|}/g,'')+"="+variable[i+1] }else{ txt+=url_variable[i].replace(/{|}/g,'')+"="+variable[i+1]+"&" } } if (location.search.length == 0) // if no query parameters {return urloutput + "?" + txt} else {return urloutput + "&" + txt} }
You can use the above script for variety of URL formats
- /search/newyork/gyms —-> Format: /search/{city}/{service}
- /search/newyork/gyms/premium —> Format: /search/{city}/{service}/{membership}
- /search/newyork-gyms/premium —>Format: /search/{city}-{gyms}/{membership}
- 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.
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)
4.) Site Search Term Is Present in the URL: One As Query Parameter & Other In the URL (Multiple Terms)
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 &
- Enable Site Search Tracking & Enter The Parameter.
OR
- Modify the URL to Query parameter &
- Enable Site Search Tracking & Enter The Parameter.
5.) Site Search Term Is NOT Present in the URL
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
Once you have the query parameter you can implement our normal site search tracking method.
Other method you can use is to ask the developer…
- To pass the search term in a javascript global variable.
- Then you can, fetch it as a variable in the GTM.
- And add it as a parameter to the page variable before sending it to Google analytics. (check the previous GTM method which we used)
How To Strip Query Parameters in the Analytics Reports?
In your Google Analytics reports, what URL 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.
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…
Super Guide To Enhanced Ecommerce Tracking via Google Tag Manager [2018]
Hi Ritwik,
thanks for his post. I had already set it up and was waiting for results. After a couple i noticed the search pages does show data, i got a searchfield on almost all pages. When i click one page i can see the search terms being used on that page. However when i use the Search Term link on the left, sometimes it does show data and other times it doesnt. When it does show the data, it shows 19 hits and shows 1-10 rows, when i than want to view the other rows suddenly all data is gone and its back to 0???
https://uploads.disquscdn.com/images/2ba40b03a2bc046e3a9f3cb4a87286653c64346cb7c0f0c44a59da7784f730e1.png
Say i click the index page / than after that sometimes it does show the queries and othertimes it doesnt seem to work. It looks like its very buggy or something. Im no guru at this and hardly understand all of this. I just tried this today and see if this could help us. The site isnt really published or given any social appearance, no traffic at the moement.
Hello, I have 2 separate search boxes (simple and advanced search), each with its parameters (“q” for simple, “sku” and “manufacturer” for advanced.) I put all 3 in the search parameter box. It works but I can’t distinguish between the 2 types, there’s no way to set the parameter as a secondary dimension. Any clue on a workaround? Thanks!!!
Thanks for the article. It helps in configuring complicated url
Pingback: grandpashabet