mixpanel / mixpanel-js

Official Mixpanel JavaScript Client Library
https://mixpanel.com/help/reference/javascript
Other
862 stars 308 forks source link

Bug: 'token' property added to objects sent to track() on Safari / Firefox #386

Closed ogy6 closed 6 months ago

ogy6 commented 9 months ago

Hi when tracking events with mixpanel, I noticed a weird bug happening in safari and firefox (doesn't happen in chrome).

when I'm calling mixpanel's track method and pass an object to be logged with the message (as the second argument), this object is being mutated and added a property token (with the value of my mixpanel token).

screenshot from safari console after printing the object: image

this is unexpected and unwanted behaviour as I sometimes pass an object to track that is also used in other places in the code, and for users using safari / firefox the object is being mutated and sometimes saved / sent to 3rd parties (i.e. local storage, api calls) with this property, which is obviously a risk.

relevant code: track('obj will be mutated on safari', obj);

versions: mixpanel-browser: 2.46.0 safari: 16.5 (18615.2.9.11.4) firefox: 116.0.3 (64-bit)

expected behaviour: objects passed to track shouldn't be mutated by mixpanel

possible workaround: using the deconstructing syntax track('obj will not be mutated', { ...obj });

tdumitrescu commented 9 months ago

Duplicate of https://github.com/mixpanel/mixpanel-js/issues/183. Haven't heard about Chrome behaving differently before, though.

ogy6 commented 9 months ago

Ohh, I didn't see the previous issues. I see the first issue is from 2016, is it going to be fixed at any point? just so I know for next times I use mixpanel.

about Chrome, I found it weird too, but it didn't reproduce there.

tdumitrescu commented 6 months ago

This should be fixed as of https://github.com/mixpanel/mixpanel-js/releases/tag/v2.48.0