You can find a general guide for how to implement this here.
You may also learn more about our analyticsTags parameter here.
As an example, to set analytics tags for different devices, after writing your function to detect the device:
const getPlatform = () => { const isMobile = ... // your logic to determine whether a user is on mobile or desktop return isMobile ? 'mobile' : 'desktop'; };
You would then use it with the configure widget to set the tag:
const platformTag = getPlatform(); instantsearch.widgets.configure({ analyticsTags: [platformTag], });
To do this with Magento you will need to make modifications to your front end to add this functionality.
The best option for this would be through the use of a frontend hook. The hook would look something like this:
algolia.registerHook('beforeWidgetInitialization', function(allWidgetConfiguration, algoliaBundle) { const getPlatform = () => { const isMobile = ... // your logic to determine whether a user is on mobile or desktop return isMobile ? 'mobile' : 'desktop'; }; const widgetConfig = { analyticsTags: [platformTag], }; if (typeof allWidgetConfiguration['configure'] === 'undefined') { allWidgetConfiguration['configure'] = [widgetConfig]; } else { allWidgetConfiguration['configure'].push(widgetConfig); } return allWidgetConfiguration; });
Here is our guide for modifying the front end in Magento 2 which you may also find useful.
Comments
0 comments
Please sign in to leave a comment.