Skip to content

How to write an enrichment plugin that fires after a remote integration? #1120

Closed
@kwalker3690

Description

@kwalker3690

I'm writing an 'enrichment' plugin that should add a property to any event that comes through track. However, the value of this property relies on a value added to events via an integration (the Amplitude Actions integration to be specific). Here is the code I'm using to register my plugin:

const testPlugin: Plugin = {
  name: "Session Replay Events",
  type: "enrichment",
  version: "1.0.0",

  isLoaded: () => true,
  load: loadMethod,
  track: trackMethod,
};

SegmentAnalytics.load({
  writeKey: <api key>,
  plugins: [testPlugin],
});

When debugging this, I've inspected the code and observed that testPlugin (red arrow in below screenshot) is always added before the Actions enrichment plugin (blue arrow in below screenshot)

Screenshot 2024-07-22 at 2 20 39 PM

I believe the ordering is occurring due to the ordering of plugins vs remotePlugins in this code snippet.

I'd like to have my plugin be registered in load() so that we can enrich all events, including those emitted immediately on page load (as opposed to registering my plugin after load(), which means it will not capture those initial events).

Because of the ordering, when I console log via my track method, the ctx.event.integrations object is empty, as the Amplitude Actions integration has not yet been processed:
image

Is there any way I can have my testPlugin be registered in load(), but have its track calls execute after those from remotely loaded plugins?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions