With Algolia Magento 2 extension, you can implement analyticsTags with the following steps.
This document may help with customizing the extension's behavior.
1. Register a custom hook in the Magento 2 extension. You can use the "beforeWidgetInitialization" hook to set the analyticsTags.
2. Write logic to identify information to tag, such as if it's on a category page or if the device is mobile. For example, you can identify if the current page is category page by checking "alogliaConfig.isCategoryPage" variable provided by the extension and add a tag based on the variable
3. Add analyticsTags information to the request configuration.
You can add search parameters as a part of the allWidgetConfiguration['configure'] object.
//register hook
algolia.registerHook('beforeWidgetInitialization', function (allWidgetConfiguration) {
allWidgetConfiguration['configure'] = allWidgetConfiguration['configure'] || {}
//function to return tag name according to the algoliaConfig information
constgetPageType=()=>{
return algoliaConfig.isCategoryPage ? 'categoryPage' : 'searchPage';
};
//get page tag for the current page
constpageTag=getPageType();
//set page tag as analyticsTags for InstantSearch.js widgets
if (typeofallWidgetConfiguration['configure'].analyticsTags==='undefined') {
allWidgetConfiguration['configure'].analyticsTags= [pageTag];
} else {
allWidgetConfiguration['configure'].analyticsTags.push(pageTag);
}
returnallWidgetConfiguration;
});
In this way, search requests sent from this configuration will get analyticsTags, and you can analyze data with them from the dashboard.
Comments
0 comments
Article is closed for comments.