Mixpanel Web (actions): add Source Name setting to tag events with segment_source_name - #3902
Mixpanel Web (actions): add Source Name setting to tag events with segment_source_name#3902core-e wants to merge 3 commits into
Conversation
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.
| 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) | ||
| } |
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
Good call on the defensive check, pushing an update now and adding a related test.
|
Hi @core-e thanks for raising this 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, |
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:
|
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.
|
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. |
|
Any update? |


Problem
The cloud-mode Mixpanel (actions) destination has a
sourceNamesetting whose value is sent assegment_source_nameon 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 Propertiesmapping is not sufficient, as Segment's mappings do not apply to autocaptured events generated by Mixpanel's SDK.Change
sourceNamesetting ("Source Name"), mirroring the cloud-mode destination's field.initializecallsmixpanel.register({ segment_source_name: sourceName })from within theloadedcallback. Registering it as a super property attaches it to every event the instance sends, including autocaptured events.sourceNameis destructured out ofsettingsso it is not spread into the object handed tomixpanel.init— the remaining settings are forwarded verbatim as Mixpanel config.registerto theMixpanelinterface intypes.ts.register: jest.fn()so their strictly-typedMixpanelmocks satisfy the updated interface.Compatibility
Opt-in and backwards compatible. When
sourceNameis blank or absent,registeris 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.src/__tests__/initialization.test.ts:segment_source_nameas a super property whensourceNameis set, and assertssourceNameis not forwarded into themixpanel.initconfig;registerwhensourceNameis unset.generated-types.tsregenerated via./bin/run generate:types.metadata.jsonregenerated via./bin/run generate:metadata-payload.eslintandtsc --noEmitclean on the changed package.segment_source_namecorrectly merged into the event (screenshot 2).Screenshots
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.