Web Analytics

Google Analytics Site Search Instructions Lead You To Track Multiple Search Parameters Incorrectly

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:

  1. Your site has multiple search forms, each one using different query parameters.
  2. You are tracking multiple sites in the same profile, and each site uses a different site search engine.

To achieve our goal of concatenating search terms, we need some custom JavaScript that reads the individual search parameters, and concatenates them into one parameter. Then, using virtual pageviews, we would pass the concatenated parameter to GA. Here’s some sample code that achieves exactly this.

<!–[CDATA[

var value = (pair.length==2)
? decodeURIComponent(pair[1])
: name;

params[name] = value;
}

for (var x in qsParams) {

qsParam = qsParams[x];

if (typeof(params[qsParam]) != 'undefined') {
if (concatVal != "")
concatVal += "+";

concatVal += params[qsParam];
}
}

return concatVal;
}


} catch (e) {}

]]>

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).

Cardinal Path

Share
Published by
Cardinal Path

Recent Posts

Optimizing user experiences with Digital Experience Analytics (DXA) platforms

As consumers become increasingly digitally savvy, and more and more brand touchpoints take place online,…

2 months ago

Enabling Value-Based Bidding with Google Tightlock

Marketers are on a constant journey to optimize the efficiency of paid search advertising. In…

3 months ago

Resolving “Unassigned” Traffic in GA4

Unassigned traffic in Google Analytics 4 (GA4) can be frustrating for data analysts to deal…

3 months ago

This website uses cookies.