AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

3.8K members online now
3.8K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
Guide Me

Site Search not returning a true search term

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I have site search implemented on the site (, but when I look at the site search reports, it says I have thousands of searches where the value of the search term is '1'.

It's been set up in the admin console to look for the query parameter of 'q'

Not sure where the problem exisits


Re: Site Search not returning a true search term

[ Edited ]
Participant ✭ ✭ ✭
# 2
Participant ✭ ✭ ✭

Hi Bill,


Let's dissect things a bit to get a richer understanding.


Before heading into Google Analytics, you’ll need to locate your keyword. The easiest way to do this is to go to your website and perform a search for something. Let's try to search for "bill". On the following page, take a look at the URL – do you see this keyword?


In the next phase, we'll need to identify your query parameter. But guess what? Smiley Happy

You're not using a query parameter (?q) within the page path. You're using a fragment (#q) within the page path instead of as a query parameter and that's the reason why your site search report is not working properly.


Google Analytics’ site search settings require a query parameter in the URL, e.g. Often, however, the site search tool does not apply a query parameter to the URL. Then you'll need to put in more effort to make it work.


Here are the instructions how to make it work:


1. If you're using a simple Google Analytics snippet:

You'll need to add this extra JavaScript code to your website: 


var query =;
var hash = document.location.hash.replace('#', '');
if (hash) {
  if (query) {
    query += '&q=' + hash;
  } else {
    query += '?q=' + hash;
ga('send', 'pageview', {'page' : document.location.pathname + query});


I recommend you testing it first before you go live.


2. If you're using Google Tag Manager:

You'll need to go through this process:

1) Log in to your Google Tag Manager account and head on over to the variables section and create a new Custom JavaScript variable:


function() {
  var path = document.location.pathname + + document.location.hash;
  return path.indexOf('/search') > -1 ? path.replace('#','?') : undefined;

 Screen Shot 2016-08-06 at 15.50.08.png


2. Open your Google Analytics pageview tag and use that custom JavaScript value as the value of the page field:


Screen Shot 2016-08-06 at 04.29.24.png


That would remove the hash (#) and replace it with the question mark (?) from the path sent to GA when the URL includes /search.


I highly recommend you working closely with your developers before you start implementing these things. 


Make sure you test it first before you go live because there's a risk that the /search path can have other fragments in the URL as well.


Hope this helps. Let me know how it goes.



Re: Site Search not returning a true search term

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Taavi,

Thank you so much for the reply. I use GTM to place tags on the page so followed your suggestion for #2. So far this doesn't work. I have checked and re-checked the variable and page view tag in GTM. I can see in the code that the # is being changed to a ?, but nothing is showing up in my reports. I'm wondering now if this is a timing issue of what order the scripts on the page run. I have enlisted the help of one of my developers to troubleshoot.I'm trying this in a staging environment, otherwise I'd ask you to take another look. I'll let you know how it goes.
Again, thank you for your help!

Re: Site Search not returning a true search term

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
Hi Taavi,
It was a silly mistake. I didn't have Site Search enabled in my test environment. The data is showing up in the reports now.
Thanks very much for your help!