rudderlabs / rudder-sdk-js

JavaScript SDK for RudderStack - the Customer Data Platform for Developers.
https://www.rudderstack.com
Other
144 stars 83 forks source link

BUG : Traits passed to `identify` are not correctly sent in the network call #1875

Closed happypoulp closed 1 month ago

happypoulp commented 1 month ago

Describe the bug When calling the identify method with:

const traits = {
  foo: 1
}
rudderanalytics.identify("someuserid", traits)

I expect to see the same traits object being transmitted in the payload of the identify network call made to Rudderstack.

However, the traits sent in the HTTP payload do not match the one I passed to identify method. Instead, it seems like the traits I pass to the identify method are being merged or added to the existing traits.

To Reproduce Steps to reproduce the behavior:

  1. Run rudderanalytics.identify("e36b8bc6-0c1e-44fd-907c-f63e94315b30", {foo: 1})
  2. Check the identify HTTP call and see that the traits contains more than {foo: 1} (if you already have existing traits)
  3. Run rudderanalytics.identify("e36b8bc6-0c1e-44fd-907c-f63e94315b30", {bar: 1})
  4. Check the identify HTTP call and see that the traits still contains foo even though we only passed bar
  5. Run rudderanalytics.identify("e36b8bc6-0c1e-44fd-907c-f63e94315b30", {baz:[1,2]})
  6. Check the identify HTTP call and see that the traits contains baz: [1,2] (and also foo and bar)
  7. Run rudderanalytics.identify("e36b8bc6-0c1e-44fd-907c-f63e94315b30", {baz:[2]})
  8. Check the identify HTTP call and see that the traits contains baz: [2,2] instead of {baz:[2]}

Expected behavior I expect the traits object passed to identify method to be the one sent in the payload of the identify HTTP request made to Rudderstack.

Screenshots

Capture d’écran 2024-10-04 à 11 52 56

Additional Information (please complete the following information):

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

contributor-support[bot] commented 1 month ago

Thanks for opening this issue! We'll get back to you shortly. If it is a bug, please make sure to add steps to reproduce the issue.

MoumitaM commented 1 month ago

Hi @happypoulp ,

This is the expected behavior of the SDK. Ref

If you want to reset traits, use reset API then make an identify call. Ref

happypoulp commented 1 month ago

Oh thanks, I did not understood it this way while reading the doc.

I am surprised about the behavior regarding arrays updating because it produces unexpected results where we could have duplicated entries in the array because of this merge behavior.

I guess it should then be safer to always call reset before calling identify ?

Also maybe that is could be worth emphasizing about what "append or modify" means in the documentation because it may not be obvious that it means that you cannot remove any information once it's in the traits (especially tricky when dealing with arrays).

saikumarrs commented 1 month ago

Hello @happypoulp, thanks for your feedback.

We've planned to improve the above doc page. So, it'll reflect very soon.