Skip to content

A plugin method to detect when an event was flushed #1062

@mattlennon3

Description

@mattlennon3

Summary

I'm trying to make a plugin which will update my store with the number events which are actually sent to Segment, ideally the count of successful uploads.

This plugin will be ran in our pre-release environment as part of an automation test suite, so we can ensure Segment events are being uploaded successfully before we release to production.

Here's the best I have come up with for now:

export class EventCounter extends Plugin {
  type = PluginType.after;

  execute(e: SegmentEvent) {

    // if (production), return e; else:

    useStore.setState(state => {
      return {
        ...state,
        e2eSegmentEventCount: state.e2eSegmentEventCount + 1,
      };
    });
    return e;
  }
}

This does work at the moment, but it's just counting processed events, not ones that have actually been sent.

Proposed Solution

Perhaps some kind of onFlushed event:

export class EventCounter extends Plugin {
  type = PluginType.after;

  // New event here:
  onFlushSuccess(e: SegmentEvent) {

    // if (production), return e; else:

    useStore.setState(state => {
      return {
        ...state,
        e2eSegmentEventCount: state.e2eSegmentEventCount + 1,
      };
    });
    return e;
  }
}

// Could even have:
// onFlushFailed

Once the event has passed through this plugin, it can be cleared from memory.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions