Cardinal Path’s response to COVID-19 Cardinal Path is sharing all we know to help marketers during COVID-19.  Learn more.

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.

function concatTerms(qsParams) { qs = location.search.substring(1, location.search.length); var args = qs.split('&'); var params = {}; var concatVal = “”; var x, qsParam; // split out each name=value pair for (var i = 0; i < args.length; i++) { var pair = args[i].split('='); var name = decodeURIComponent(pair[0]); 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; } ]]>

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

Sharing is caring!

Popular

COVID-19 Crisis Navigator​

In partnership with Dentsu, Cardinal Path helps you distill the overwhelming news and information into a bi-weekly report highlighting emerging trends and insights during the pandemic.

EXPLORE THE REPORT

Thank you for your submission.

Message Sent

Thank you.

Click here to download access the tool.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Success!
Your message was received.

Thank you.

Message Sent

Thank you for registering.

Thank you for submitting the form.

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Thank you for your submission.

Message Sent

Thank you for registering.

Thank you for registering.​

Paid media spend by Government websites increased a whopping 139% YoY in 2020.

2020 Online Behavior Live Dashboard

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

2020 Online Behavior Live Dashboard

Message Sent

Thank you for registering.

Thank you for submitting the form.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Thank you for registering.

Cardinal Path is continuing with its series of free training. Next we are conducting training on Google Data Studio. Check it out here.
Cardinal Path hosted a live session to connect with you and answer all your questions on Google Analytics.
Get all the expertise and none of the consultancy fees in this not-to-be-missed, rapid-fire virtual event.

Message Sent

Success! Thank you
for reaching out.