How to use the trackSiteSearch event?

Hi,

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:

window.snowplow_name_here('trackSiteSearch',
    ['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?

Thanks,
Guillaume

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 atomic.events table. You can link the two tables by means of relation event_id = root_id.

–Ihor

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: https://github.com/snowplow/snowplow/wiki/2-Specific-event-tracking-with-the-Javascript-tracker#siteSearch

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:

window.snowplow_name_here('trackSiteSearch');

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

window.snowplow_name_here('trackSiteSearch',
    ['<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.