Google Analytics Site Search: Setup Options

There are a number of ways to setup Google Analytics Site Search depending on the way your website functions and the URLs your search function creates.

Site Search: Option 1

Perform a search for 'analytics' on your website and look at the URL.

What do your Site Search URLs look like?

If the resulting URL looks like one of the following:

http://www.example.com/search?q=analytics
http://www.example.com/index.php?id=search&term=analytics
http://www.example.com/search.asp?search_term=analytics&id=ac9024

You can follow our steps to setup Google Analytics Site Search.

Site Search: Option 2

If the resulting URL looks like one of the following:

http://www.example.com/index/search/analytics
http://www.example.com/search.php/keyword/analytics/id946
http://www.example.com/searchterm/analytics

Because Site Search reports are processed before filters are processed you cannot simply create a filter to modify your Site Search URL within Google Analytics. Instead you need to modify the tracking code on the search results page to dynamically pass the search term using a virtual pageview (see 'option 3 below').

If you or your web developer is unable to modify the tracking code on the search results page, then you might want to consider one of the following filters to at least make the Top Content report easier to scan for internal search terms. Remember, that this does not allow you to use the Site Search reports within Google Analytics.

Possible filters:

If your URL looks like http://www.example.com/index/search/analytics you will need to setup the following filter:

Google Analytics Site Search

Field A -> Extract A: Request URI: ^/index/search/(.*)
Output To -> Constructor: Request URI: /search?q=$A1

If your URL looks like http://www.example.com/search.php/keyword/analytics/id946 you will need to setup the following filter:

Google Analytics Site Search

Field A -> Extract A: Request URI: ^/search.php/keyword/(.*)/id
Output To -> Constructor: Request URI: /search?q=$A1

If your URL looks like http://www.example.com/searchterm/analytics you will need to setup the following filter:

Google Analytics Site Search

Field A -> Extract A: Request URI: ^/searchterm/(.*)
Output To -> Constructor: Request URI: /search?q=$A1

These filters will modify your Top Content reports:

Google Analytics Site Search Report

But won't allow you to use Site Search reports:

Google Analytics Site Search Report

Site Search: Option 3

If the resulting URL does not contain the keyword you searched for then you will either need to modify your search form or modify your Google Analytics Tracking Code to create a virtual pageview.

For example you search for 'analytics' and the URL of your search results page looks like:

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

View the source of a page on your site that contains the search input, if your form looks something like this:
<form name="gs" method="post" action="search.php">
Then try changing the method to 'get'. Your source code should look something like this:
<form name="gs" method="get" action="search.php">
If you now perform a search you should see a URL along the lines of those in 'Option 1'.

If you are unable to modify the form method or the change does not provide the search parameter in the URL then you will need to modify the Google Analytics Tracking Code to dynamically create a URL that is correctly structured for Site Search.

For example:
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-123456-1");
pageTracker._trackPageview('/search?q=analytics');
} catch(err) {}</script>
The keyword ('analytics' in the example above) will need to be dynamically passed to the tracking code for each term that is searched. Talk to your web developer if you need help achieving this, you can then look at 'Option 1' because you are creating a virtual pageview for http://www.your-site.com/search?q=analytics

Share

Posted on Thursday, May 21, 2009

2 Comments:

Blogger ben.griffiths said...

What if you are using a Google Site Search or Google Custom Search? What would the query parameter be? Viewing the source wouldn't tell me, nor would I be able to change the GET vs. POST method because Google uses an iframe.

Any ideas?

February 3, 2010 6:03 AM  
Blogger Benjamin Mangold said...

Hi Ben,

You will need to check the following;

1) Log into Google Custom Search and go to 'control panel' > 'look and feel'.

2) Select 'iframe' under hosting options.

3) Place the code on your results page.

4) Enable site search and use enter q as the query parameter.

And you are done!

March 4, 2010 4:27 PM  

Post a Comment

Links to this post:

Create a Link

Mangold Sengers provides Google Analytics consulting, Google Analytics onsite training and Google Analytics online training. Contact us to discuss your needs.