How to use the trackSiteSearch event?


I want to implement trackSiteSearch to track terms entered by users on my website.
I added the basic script in my header page just to check if some data was tracked:

    ['unified', 'log'], // search terms
    ['books'],          // filters
    14,                 // results found
    8,                  // results displayed on first page

I couldn’t find any of the data in my events table, so I was thinking that maybe I need add some enrichment to be able to track search terms?

If yes, which one and how can I add it?


Hi @gtd,

The site_search event is implemented as unstructured (self-describing) event. As such the associated data would have to be loaded into the dedicated table, specifically com_snowplowanalytics_snowplow_site_search_1. The definition for the table could be found here in case you haven’t created the table yet.

This also means that this event would be labeled as unstruct in the event field of the table. You can link the two tables by means of relation event_id = root_id.


On a side note @gtd - where did you see the trackSiteSearch command in our documentation? I don’t believe it should exist…

@alex - here’s the reference:

Thanks @ihor!

Thanks a lot @ihor!

Hi, I want to use trackSiteSearch as well. From the docs, seems like we must specify the search terms? Can do track all site searches?

I am trying to do something like this:


Also can I clarify what do you mean by site search here?
Is it the search that triggers when:

  • user uses search functionality that our website provide
  • user searches term using CTRL+F or CMD+F ?

@aditya, you have to provide the search terms as a bare minimum when calling this method. The JSON schemas corresponding to this event is here. That is at the minimum, it should be called like this

    ['<search_term>'],      // search terms
    {},                     // filters
    0,                      // results found
    0                       // results displayed on first page

If you have search functionality implemented within your own web application then you could probably obtain all the data required to fire this event - meaning you are in control of either backend of your application (server-side programming) or frontend if all the data could be obtained from URI and DOM, for example.

Perhaps, you are looking for something entirely different - more of campaign attribution? There is the Campaign Attribution enrichment that could track your Google advertising campaign attribution automatically based on the mapping you provide, for example.

Thanks @ihor for the explanation!

I am trying to see if we can track a page-wide search initiated when user does ctrl+F in Windows or cmd+F in Mac?

You can capture certain key combinations that a user might press - but I don’t think that’s what you are after given that a user could map their find function to command + f, ctrl + f, option + f depending on their keyboard, locale, browser etc.

In general you shouldn’t really do this as most users (and browsers) assume that browser sandbox controls shouldn’t be accessible via Javascript. On site search is fine, but search within a browser is a different thing.