DavidWells / DavidWells/analytics
Adjust event name in enrichment plugin
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 2.7k
- Forks
- 267
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the enricher plugin's track:google-analytics hook and compare how the returned payload.event and properties are handled. Reproduce the Product Clicked example; done means the renamed item_clicked event is delivered while the property transformation still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- analytics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100