analytics
analytics copied to clipboard
Adjust event name in enrichment plugin
Is it possible to change/format an event name within a plugin for a specific namespace?
For example, for Google Analytics 4, I need to use specific event names and properties for the e-commerce data but don't necessarily want to use the Google Analytics event names everywhere.
I was hoping something like this would work, but the event gets swallowed:
// enricher plugin
const googleAnalyticsEnricherPlugin = {
name: 'enrich-google-analytics',
'track:google-analytics': ({ payload }) => {
switch (payload.event) {
case 'Product Clicked':
return {
...payload,
event: 'item_clicked',
properties: {
items: [
{
item_id: payload.properties.id,
item_name: payload.properties.name,
},
],
},
};
default:
return { ...payload };
}
},
};
// track call
analytics.track('Product Clicked', {
id: product.id,
name: product.name,
});
Adjusting the properties works fine but not the event name.
I am seeing similar behavior in the google-tag-manager plugin. #363
This is interesting one. Changing event
isn't setup right now. Would be a good future improvement tho
Right now you can send provider specific events like this:
/* Send track call to one 1 place */
analytics.track('item_clicked', {
price: 11,
sku: '1234'
}, {
plugins: {
// disable this specific track call for all plugins except google-analytics
all: false,
['google-analytics']: true
}
})