Skip to content

Mixpanel Web (actions): add Source Name setting to tag events with segment_source_name - #3902

Open
core-e wants to merge 3 commits into
segmentio:mainfrom
core-e:mixpanel-web-source-name
Open

Mixpanel Web (actions): add Source Name setting to tag events with segment_source_name#3902
core-e wants to merge 3 commits into
segmentio:mainfrom
core-e:mixpanel-web-source-name

Conversation

@core-e

@core-e core-e commented Jul 24, 2026

Copy link
Copy Markdown

Problem

The cloud-mode Mixpanel (actions) destination has a sourceName setting whose value is sent as segment_source_name on every event. Mixpanel Web (actions) has no equivalent. Customers sending data from more than one source into a single Mixpanel project cannot determine which source device-mode traffic originated from.

Adding the value through the Event Properties mapping is not sufficient, as Segment's mappings do not apply to autocaptured events generated by Mixpanel's SDK.

Change

  • New optional sourceName setting ("Source Name"), mirroring the cloud-mode destination's field.
  • When set, initialize calls mixpanel.register({ segment_source_name: sourceName }) from within the loaded callback. Registering it as a super property attaches it to every event the instance sends, including autocaptured events.
  • sourceName is destructured out of settings so it is not spread into the object handed to mixpanel.init — the remaining settings are forwarded verbatim as Mixpanel config.
  • Added register to the Mixpanel interface in types.ts.
  • The five action test files each gain register: jest.fn() so their strictly-typed Mixpanel mocks satisfy the updated interface.

Compatibility

Opt-in and backwards compatible. When sourceName is blank or absent, register is never called and behavior is identical to today. No existing field changed type or became required.

Testing

  • yarn browser jest destinations/mixpanel-web — 6 suites, 10 tests, all passing.
  • New tests in src/__tests__/initialization.test.ts:
    • registers segment_source_name as a super property when sourceName is set, and asserts sourceName is not forwarded into the mixpanel.init config;
    • does not call register when sourceName is unset.
  • generated-types.ts regenerated via ./bin/run generate:types.
  • metadata.json regenerated via ./bin/run generate:metadata-payload.
  • eslint and tsc --noEmit clean on the changed package.
  • Source Name setting renders with its description in Segment's Action Tester (screenshot 1). Note: the Tester does not perform the device-mode send, so it is verified separately (screenshot 2).
  • Test event sent to a live (dev) Mixpanel project through Mixpanel's SDK, orchestrated locally with Playwright, segment_source_name correctly merged into the event (screenshot 2).

Screenshots

  1. segment-action-center-01
  2. mixpanel_screenshot_01

Follow-up

If the destination settings are not updated automatically from this configuration, guidance on the process for requesting the necessary Segment UI changes would be appreciated.

Adds an optional `sourceName` setting that, when set, is registered as a Mixpanel super property named `segment_source_name`.

This ports the Source Name setting from the cloud-mode Mixpanel (actions) destination. Without it, there is no straightforward way to identify in Mixpanel which Segment source initialized the SDK.

`sourceName` is destructured out of settings so it is not spread into the config object passed to mixpanel.init.

Opt-in and backwards compatible: when `sourceName` is blank, register is never called and behavior is unchanged.
Comment on lines +92 to +98
config.loaded = (mp) => {
if (sourceName) {
// Registered as a super property so it is attached to every event
mp.register({ segment_source_name: sourceName })
}
resolve(mp)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be more defensive?
Something like the following:

config.loaded = (mp) => {
  const trimmed = sourceName?.trim?.()
  if (typeof mp?.register === 'function' && trimmed) {
    mp.register({ segment_source_name: trimmed })
  }
  
  resolve(mp)
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call on the defensive check, pushing an update now and adding a related test.

@joe-ayoub-segment

Copy link
Copy Markdown
Contributor

Hi @core-e thanks for raising this PR.
Can you send me an email to jayoub@twilio.com so that I can verify your identity please? If you don't work for Mixpanel I'll need to contact Mixpanel to have them review the PR.

Also, please attach proof of testing to the PR description. Screenshot(s) or video is fine. Should show events being sent from the local testing tool to Mixpanel.

If you could also link to the API docs which outline the use of the register(properties: { [k: string]: unknown }): void function, that would be super helpful.

Kind regards,
Joe

@core-e

core-e commented Jul 24, 2026

Copy link
Copy Markdown
Author

Hi @core-e thanks for raising this PR. Can you send me an email to jayoub@twilio.com so that I can verify your identity please? If you don't work for Mixpanel I'll need to contact Mixpanel to have them review the PR.

Also, please attach proof of testing to the PR description. Screenshot(s) or video is fine. Should show events being sent from the local testing tool to Mixpanel.

If you could also link to the API docs which outline the use of the register(properties: { [k: string]: unknown }): void function, that would be super helpful.

Kind regards, Joe

Thanks for the quick review!

I'm actually just an interested customer. I'll shoot you an email shortly with my Mixpanel contact.

Super Property API references:

Two screenshots as testing proof:

  1. Action Tester — shows the new Source Name setting correctly rendering in Segment's Action Tester with the description. Note: I couldn't get the Tester itself to route the event through Mixpanel's device-mode SDK.
segment-action-center-01
  1. Mixpanel event — a test event in a live (dev) Mixpanel project, sent through Mixpanel's SDK orchestrated locally with Playwright, showing that the segment_source_name was correctly merged into the event.
mixpanel_screenshot_01

core-e and others added 2 commits July 24, 2026 09:01
Addresses review feedback on the Source Name change:

- Trim `sourceName` before use so a whitespace-only value does not register an empty super property.
- Guard `typeof mp.register === 'function'` before calling it, so an unexpected Mixpanel SDK build degrades gracefully rather than throwing a TypeError.
- Add a test covering the whitespace-only case.

@jakewski jakewski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

@mp-emmett

Copy link
Copy Markdown

While I can't speak to our SDK team, I do represent Mixpanels GTM team and this fix would essentially add the Source.

Register would store this on whatever persistance configuration, so as long as we call this more often than less (i.e. when segments lib loads, versus some single operation) works for us. Register is safe to call multiple times and only appends the property to future outgoing track calls.

@core-e

core-e commented Aug 4, 2026

Copy link
Copy Markdown
Author

Any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants