Concepts / Building Search UI / Integrate Google Analytics
Oct. 11, 2019

Integrate Google Analytics

Google Analytics with InstantSearch.js

Even though Algolia provides analytics that are tailored to your search implementation, you might want to integrate your search into your existing analytics tools. InstantSearch.js provides a widget called analytics to do that.

This widget is platform agnostic and can be used either with Google Analytics or any solution that provides a REST endpoint. The example below uses Google Analytics.

Integrating with Google Analytics requires 2 steps:

Once the Google Analytics library is installed on your website, you can use the analytics widget. The logic is defined in the pushFunction option.

1
2
3
4
5
6
7
8
search.addWidgets([
  instantsearch.widgets.analytics({
    pushFunction(formattedParameters, state, results) {
      window.ga('set', 'page', window.location.pathname + window.location.search);
      window.ga('send', 'pageView');
    },
  })
]);

Did you find this page helpful?