With Algolia's Magento extension, you can implement analyticsTags by following these steps:
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 the information that you want to tag (ie: "fromCategoryPage" or "mobileDevice"). For example, you can identify if the current page is a category page by checking the binary value of the "alogliaConfig.isCategoryPage" variable provided by the extension and adding the appropriate tag based on the value.
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
const getPageType=()=>{
return algoliaConfig.isCategoryPage ? 'categoryPage' : 'searchPage';
};
//get page tag for the current page
constpageTag=getPageType();
//set page tag as analyticsTags for InstantSearch.js widgets
if (typeof allWidgetConfiguration['configure'].analyticsTags==='undefined') {
allWidgetConfiguration['configure'].analyticsTags= [pageTag];
} else {
allWidgetConfiguration['configure'].analyticsTags.push(pageTag);
}
return allWidgetConfiguration;
});
In this way, search requests sent from this configuration will get analyticsTags, and you can segment your analytics data with these tags in the dashboard.
This supplemental documentation may be helpful for learning about best practices when customizing the extension's behavior.