Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust event name in enrichment plugin #353

Open
oddnavy opened this issue Jan 19, 2023 · 2 comments
Open

Adjust event name in enrichment plugin #353

oddnavy opened this issue Jan 19, 2023 · 2 comments

Comments

@oddnavy
Copy link
Contributor

oddnavy commented Jan 19, 2023

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.

@ccook10-chwy
Copy link

I am seeing similar behavior in the google-tag-manager plugin. #363

@DavidWells
Copy link
Owner

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
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants