0

I've got two kinds of searches in my website:

  • /blog/search?q=some-blogpost
  • /products/search?q=some-product

I want to be able to analyze the searches my users are making on both of those channels separately.

Which option should I go for:

OPTION #1

  • Fire all as a search event and add a custom prop to identify the type of search.
gtat("event","search", {
  search_type: "BLOG" | "PRODUCT"  // <<< THIS IS A CUSTOM PROP
  search_term: string
});

OPTION #2

  • Fire the searches as 2 separate custom events:
gtat("event","blog_search", {
  search_term: string
});

gtat("event","product_search", {
  search_term: string
});
1

I'd like to propose Option #3: GA's dedicated search tracking with Search Category set. This will give you the four reports under Behavior > Site Search and allow you to analyze search behavior as a whole or divided by type.

All of the setup for this is in Google Analytics, not your JavaScript; it is based on the query string being present.

Note: this setup uses an Advanced Filter, which can't be verified via preview, so apply it to a testing View before making the changes to your main View.

First, in your View settings, enable Site Search Tracking and set q as the query parameter.

Site Search Settings area of GA View settings page

In the screenshot I haven't checked "strip query parameters out of URL" but I personally would select that. Also, this step should be fine to do in your main View right off.

For categories, you'll need a View Filter set up as follows:

Filter using portion of URL for search category value

You'll create a new Custom filter of type Advanced, find Request URIs that match your two search URLs, capture the category identifier with (blog|products), and output it to the field Site Search Category.

Once you have the filter defined and it is working the way you need it to, you can apply it to your main View with the Apply Existing Filter option also shown in the screenshot.

3
  • Thanks. You've said: All of the setup for this is in Google Analytics, not your JavaScript; it is based on the query string being present.. So i don't even need to send a search event? Those reports will be built from the page_view URL's? Is that it? – cbdeveloper Jan 15 at 15:31
  • Also, I'm implementing Google Analytics 4. And they've "deprecated" the View. There are no Views in GA 4. Only Properties. – cbdeveloper Jan 15 at 15:32
  • I expect there is an analogous way to do it in GA4 - but your question is tagged Universal Analytics, which is what my answer applies to. – Reve Jan 15 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.