DavidWells / DavidWells/analytics

Adjust event name in enrichment plugin

Open
#353 2 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.