Got a site search engine on your website? Have you set up set up site search? If so, good on you! If not, go read Avinash Kaushik’s post on why you should be analyzing your site search and our post on how to use the site search report.
On most search forms, there’s only one keyword field and one category field. However, some search forms (like advanced search forms) have multiple keyword fields and categories the visitor can fill out. From the GA help, you would think this is easily accomplished by specifying the query parameters in a comma-delimited list. Here’s a quote of the relevant line:
Enter your ‘Query Parameter’ in the field provided. Please enter only the word or words that designate an internal query parameter such as “term,search,query”. Sometimes the word is just a letter, such as “s” or “q”. You may provide up to five parameters, separated by a comma.
From the last sentence, you would think that GA will read up to five parameters in the query string and report them together somehow (perhaps concatenated in the search terms report). However, this is not the case! In query strings where more than one search term query parameter exists, GA reports only the last search term parameter and discards the rest. Here’s some screen shots of my test profile configuration, the top content report, and the resulting search terms GA reports.
Site Search Setup
Top Content Report
Search Terms Report
The same problem occurs if more than one category parameter exists.
Site Search Category Report
How are the multiple search parameters and categories supposed to be used you ask? Well, it’s usually for the following two cases:
- Your site has multiple search forms, each one using different query parameters.
- You are tracking multiple sites in the same profile, and each site uses a different site search engine.
The function concatTerms takes an array of search term query parameters, looks for those parameters within the query string, and returns a string with the search terms concatenated. We then create a virtual pageview using the concatTerms function to join the multiple search fields into one. Note that I've used the concatTerms function for both the search term fields (q1 and q2) and the category fields (c1 and c2).