Integrate Google Analytics
On this page
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:
- Set up the Google Analytics library in your page
- Add and configure the
analyticswidget
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.addWidget(
instantsearch.widgets.analytics({
pushFunction(formattedParameters, state, results) {
window.ga('set', 'page', window.location.pathname + window.location.search);
window.ga('send', 'pageView');
},
})
);