How do I integrate Google Analytics with my site search?

If you've created a search interface from the Sajari Console, you can trigger your own analytics on searches by subscribing to events from the search interface in javascript.


Interfaces are created using setup which is included when generating the interface from the Console.

var myUI = sajari.init({ /* config object */ });

You can subscribe to events by calling your interface with the "sub" value followed by the pipeline (either pipeline or instantPipeline) and event name, then a callback. It takes the form.

myUI("sub", ".", callback);

For example, if you are using the default inline interface and want to listen to the search-sent event, you would write:

myUI("sub", "", function(event, values) {
   console.log("Search sent with values: ", values);

For information on the events please refer to the documentation on our Github

How to hide a field in a search interface?


When you generate an interface via console for a Site Search collection, we return title, description, URL, and image(optional) in the search results. In some instances, you might want to hide title, description, or URL.


Our default interface uses URL field for click-tracking, and it must be returned in response, otherwise, the click-tracking won’t function. Hence, if you try to remove URL field, it will return an error:

tracking field 'url' missing from result.


To hide ‘title’ or the ‘description’ field from the search interface:

  1. Generate an interface from the Integrate section in the console.
  2. After choosing the relevant options, and generating an interface, click on “View code“
  3. Add the “fields” parameter in the values object. See example below which will only return and render ‘title’ and ‘URL’:

values: {"q.override": true, "resultsPerPage": "10","q": getUrlParam("q"), "fields":'title,url'}