Setting up Google Analytics site search (with and without parameters)

If you have a search function on your website, then you need to be tracking what people are searching. The Google Analytics Site Search reports allow you to see the search terms people use, the pages where they start their search, and the pages they navigate to from your search results page. These reports can provide insights into your content, navigation, and even your search campaigns.

Before you can begin using the reports, you’ll need to configure Site Search in Google Analytics. Let’s walk through the different ways you can set up the reports, starting with the simplest option (finding the query parameter) through to configure the reports using Google Tag Manager. Here are the approaches we're going to cover...

  1. Using a Query Parameter
  2. Using a Filter
  3. Modifying Your Search Function
  4. Using Google Tag Manager

Time to get started!

1. Using a Query Parameter

The easiest way to configure the Site Search reports is to find the query parameter that drives your website’s search function. 

Start by performing a search for ‘contact’ on your website and look at the URL for the search results page. If your search function has a query parameter, you’ll have a URL a bit like one of these...

example.com/search?q=contact
example.com/index.php?id=search&term=contact
example.com/search.asp?search_term=contact&id=ac9024

Now if your URL looks completely different. If you can’t see a question mark, an ampersand or ‘contact’ in the URL, then you’ll need to use another approach for setting up the Site Search reports. If this is you, then feel free to jump to 2. Using a Filter.

Step 1

The first thing you need to do is identify the query parameter for the search function. You need to look for the term you searched for and then just before the term you should see an equals sign. Before this, you should see a character (or word), and before this, you should see a question mark or an ampersand. The character or word between the question mark or ampersand and the equals sign is your query parameter.

Google Analytics Site Search
 


Looking at the examples where we searched for ‘contact’, the first URL was example.com/search?q=contact in this case we can see ‘q’ is the query parameter because it’s between the question mark and the equals sign.

In the second example the URL was example.com/index.php?id=search&term=contact and in this case ‘term’ is the query parameter because it’s between the ampersand and the equals sign.

In the final example, the URL was example.com/search.asp?search_term=contact&id=ac9024 and this means the query parameter is ‘search_term’.

Once you’ve found the query parameter for your website, it’s time to configure Google Analytics.

Step 2

Log into your Google Analytics account and head to the ‘Admin’ section. Then find the view you want to configure and click on the ‘View Settings’ option.

 
Google Analytics Site Search
 

Step 3

Scroll down to the ‘Site Search Settings’ area and set ‘Site Search Tracking’ to ‘On’, and enter your query parameter. As some websites have more than one query parameter, Google Analytics allows you to enter up to five of them separated with commas. For example ‘q,query’.

 
Google Analytics Site Search
 

Selecting ‘Strip query parameters out of URL’ will prevent your search from showing up in your content reports. If you leave the option deselected, you’ll see rows in your content reports for each distinct search term used, for example, ‘/search?q=contact’.

Site Search also allows you to set up categories. You should use this if people can refine the search results or search within particular sections of your website. To set up categories, you’ll need to know the parameter that is used to refine the search results. You can use a similar approach to the one we’ve just covered to find the query parameter used for the search term. If your search function doesn’t have categories, then you can leave this option off.

2. Using a Filter

If you don’t have a query parameter for your website’s search function, then you’ll need to take a different approach to configure the Site Search reports. Search for ‘contact’ and look at the URL for your search results page. You might have a URL like one of these...

example.com/index/search/contact
example.com/search.php/keyword/contact/id946
example.com/searchterm/contact

These examples include the term you searched for, but since there is no query parameter we’ll need to use a filter to get the search terms into your reports.

Possible filter:

If your URL looks like ‘example.com/index/search/contact’, you’ll need to set up the following filter:

Field A -> Extract A: Request URI: ‘^/index/search/(.*)’
Output To -> Constructor: Search Term: ‘$A1’
Select ‘Field A required’ and ‘Override Output Field’

 
Google Analytics Site Search
 

If your URL looks like ‘example.com/search.php/keyword/contact/id946’ you’ll need to set up the following filter:

Field A -> Extract A: Request URI: ‘^/search.php/keyword/(.*)/id’
Output To -> Constructor: Search Term: ‘$A1’
Select ‘Field A required’ and ‘Override Output Field’

 
Google Analytics Site Search
 

If your URL looks like ‘example.com/searchterm/contact’ you will need to set up the following filter:

Field A -> Extract A: Request URI: ‘^/searchterm/(.*)’
Output To -> Constructor: Search Term: ‘$A1’
Select ‘Field A required’ and ‘Override Output Field’

 
Google Analytics Site Search
 

You will start to see the search terms within the Site Search reports after you’ve created the filter. You can use a similar approach if you also have a search category you want to see in your reports.

3. Modifying Your Search Function

Okay, so if the URL for your search results page doesn’t have a query parameter and doesn’t even include the keyword, then there are still two ways you can configure the Site Search reports. 

After you’ve searched for ‘contact’, look at the URL for your search results page. You’re probably going to see a URL like one of these...

example.com/search
example.com/index.php?id=search
example.com/search-results.asp

Start by heading back to the page where you started your search (just hit the back button). Now view the source code for the page and look for the form used for your website’s search function.

If the form looks something like this... 

<form action="search.php" method="post" name="gs">

Then you can try changing the method of ‘post’ to ‘get’. Your source code should then look something like this...

<form action="search.php" method="get" name="gs">

Now when you perform the search again you should see a query parameter in the URL for the search results page. Now you can head back to 1. Using a Query Parameter to configure the Site Search reports.

If you can’t change the method for your form or changing the method to ‘get’ doesn’t provide a query parameter in the URL, then you can use Google Tag Manager to capture the search terms people use.

4. Using Google Tag Manager

You can also use Google Tag Manager to pass search terms through to Google Analytics. Start by searching for ‘contact’. If your search results page includes the search term then we can get the term using Google Tag Manager.

View the source code of the search results page, and you might see something like this…

<h2 id="search-term">contact</h2>

We can then use the ID of this heading tag to capture the search term. To do this create a new Google Analytics tag inside Google Tag Manager and select the option to ‘Enable overriding settings for this tag’. Then select ‘Fields to Set’ and click ‘Add Field’. Select ‘Page’ as the ‘Field Name’ and then enter ‘/search?q=’ as the value.

Google Analytics Site Search

Now you’ll need to create a new variable that uses ‘DOM Elements’ and enter the ID that corresponds to the ID of the heading tag. In our example, this is ‘search-term’. 

Google Analytics Site Search

Finally, you’ll need to add a trigger to your new tag. I recommend creating a trigger that will only fire the tag on the search results page (and none of the other pages on your website). You can then add this as an exception trigger to your existing Google Analytics tag inside Google Tag Manager – this prevents double pageviews for your search results page.

Conclusion

Now that you’ve configured the Site Search reports in Google Analytics you’ll be able to see what people are searching for on your website. People are taking the time to tell you what they want, so take a moment and listen! You might be surprised at what people are searching.

Need inspiration? Read my post on ways to use the Site Search reports, and you might also find my post on understanding search intent useful too.

Need help identifying your query parameter? Have a tip for using the Site Search reports? Let me know in the comments below