Google Analytics Site Search: Setup Options

IMPORTANT:

This is a historical post from 21 May 2009. Tracking code examples will be out of date.

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-01

google-analytics-site-search-01

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-02

google-analytics-site-search-02

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-03

google-analytics-site-search-03

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

These filters will modify your Top Content reports:

site-search-report-01

site-search-report-01

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

site-search-report-02

site-search-report-02

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 action="search.php" method="post" name="gs">

Then try changing the method to 'get'. Your source code should look something like this:

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

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:

try { var pageTracker = _gat._getTracker("UA-123456-1"); pageTracker._trackPageview('/search?q=analytics'); } catch(err) {}

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