thankful-gpu-70135
08/01/2023, 9:29 PMirb(main):002:0> pp RudderAttributes::UserProperties.for_account(a)
{:user_id=>"50",
:traits=>
{:"Shop Name"=>"Rudderstack Test",
:"Shop Description"=> "My description",
:"Created At"=>"2023-03-21T20:28:42Z",
:Currency=>"USD",
:email=>"user@user.com",
:properties=>{:subscribe=>true}},
:context=>nil,
:integrations=>{:Intercom=>false}}
However in the live event view, it's showing the traits twice, once as a top level property, but then again as a nested prop of `context`:
{
"channel": "server",
"context": {
"library": {
"name": "rudderanalytics-ruby",
"version": "2.0.2"
},
"traits": {
"Created At": "2018-04-20T22:27:47Z",
"Currency": "USD",
"Shop Description": "My description",
"Shop Name": "Rudderstack Test",
"email": "user@user.com",
"properties": {
"subscribe": true
}
}
},
"integrations": {
"Intercom": false
},
"messageId": "f2d7f284-5f7c-41d5-bd82-402d74643251",
"rudderId": "f093e616-5855-4bbd-8621-4bffe9a663a8",
"sentAt": "2023-08-01T21:10:39.367Z",
"timestamp": "2023-08-01T21:10:39.367Z",
"traits": {
"Created At": "2018-04-20T22:27:47Z",
"Currency": "USD",
"Shop Description": "My description",
"Shop Name": "Rudderstack Test",
"email": "user@user.com",
"properties": {
"subscribe": true
}
},
"type": "identify",
"userId": "50"
}
This doesn't occur when do an identify call with the JS SDK -- I only see the traits under context.traits
I can't find any documentation around this either.
This impacts what I am writing for a transformation so trying to get to the bottom of this.millions-activity-52391
08/01/2023, 9:29 PMthankful-gpu-70135
08/01/2023, 9:41 PMtraits is just within context and not at the top level:
"anonymousId": "b7996d98-96cb-46da-8162-8dcb27f07d73",
"channel": "web",
"context": {
"app": {
"name": "RudderLabs JavaScript SDK",
"namespace": "com.rudderlabs.javascript",
"version": "2.38.1"
},
"campaign": {},
"library": {
"name": "RudderLabs JavaScript SDK",
"version": "2.38.1"
},
"locale": "en-US",
"os": {
"name": "",
"version": ""
},
"page": {
"path": "/dashboard",
"search": "",
"tab_url": "https://my.bigcartel.biz/dashboard",
"title": "Big Cartel - Dashboard",
"url": "https://my.bigcartel.biz/dashboard"
},
"screen": {
"density": 2,
"height": 1440,
"innerHeight": 1152,
"innerWidth": 829,
"width": 2560
},
"sessionId": 1690925648908,
"traits": {
"Created At": "2018-04-20T22:27:47Z",
"Currency": "USD",
"Shop Description": "My description",
"Shop Name": "Rudderstack Test",
"email": "user@user.com",
"properties": {
"subscribe": true
}
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
},
"integrations": {
"All": true
},
"messageId": "45e448b5-3a7a-4a4a-bdae-23f03ee20a0d",
"originalTimestamp": "2023-08-01T21:37:31.356Z",
"receivedAt": "2023-08-01T21:37:31.402Z",
"request_ip": "174.21.142.42",
"rudderId": "fdea86f3-24a7-47ac-b0f9-23ed221e28b1",
"sentAt": "2023-08-01T21:37:31.358Z",
"timestamp": "2023-08-01T21:37:31.400Z",
"type": "identify",
"userId": "50"
}thankful-gpu-70135
08/01/2023, 9:45 PMtraits is supposed to be a top level property within the event, it means the JS SDK is completely broken, and I find that hard to believe.
So my guess is that it's actually meant to be within context which means the Ruby SDK has a bug having it in both places (within context and at the top level)
In the Ruby SDK, this line 36 and 37 of this file shows that it's keeping it at both levels:
https://github.com/rudderlabs/rudder-sdk-ruby/blob/74e6a0281286cebaebfd9e16b6e5cbf3ea3a055a/lib/rudder/analytics/field_parser.rb#L36C1-L36C1
In the JS SDK, it clearly sets traits as a child of context but does not keep them top level:
https://github.com/rudderlabs/rudder-sdk-js/blob/7b5aea1eea91511e4b68ad6fe895b638f4c4413a/src/core/analytics.js#L920C16-L920C16
In the iOS SDK, traits is a top level property and nested under `context`:
https://github.com/rudderlabs/rudder-sdk-ios/blob/6de1425138a2dcdf36ea43c276a0b572eb836904/Sources/Classes/RSMessage.m#L25
vs
https://github.com/rudderlabs/rudder-sdk-ios/blob/6de1425138a2dcdf36ea43c276a0b572eb836904/Sources/Classes/RSMessage.m#L28
So Questions:
1. in the event payload for identify, where am I supposed to find "traits"? Within context as a nested property only or both within context and at the top level (peer with context )?
2. If it’s supposed to be both places, what’s the rationale for the duplication? It seems unnecessary and bloated to do this
3. Nit pick: If it's meant to be within context it is super weird that in the ruby docs, it shows traits as a peer of context. We just get into weird inception mind tricks on how to think about traits vs context when passed in as a params to identify: https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-ruby-sdk/#identifycalm-yak-10773
08/02/2023, 10:21 AMmillions-activity-52391
08/02/2023, 10:27 AMcalm-yak-10773
08/02/2023, 12:28 PMThis impacts what I am writing for a transformation so trying to get to the bottom of this.There are multiple ways you can deal with it: 1. Look for traits in both locations, following this order of priority: [
context.traits, traits].
2. Alternatively, you can drop the traits that are not required using transformation.thankful-gpu-70135
08/02/2023, 4:31 PMthankful-gpu-70135
08/02/2023, 4:31 PMthankful-gpu-70135
08/02/2023, 4:42 PMcontext.traits, the destinations got both sets of traits, one set transformed and one not. I'd expect a destination to only get one set of traits, not a merged set.
2.
Look for traits in both locations, following this order of priority: [This strikes me as odd guidance because it then means I can't rely on it being in one place if I'm using a recent SDK. Is it not safe to always look at,context.traits].traits
context.traits?
3. Can i really just delete traits every time and leave context.traits?calm-yak-10773
08/03/2023, 7:05 AMI’d expect a destination to only get one set of traits, not a merged set.Actually, some cloud mode destinations have been configured to fall back to the top-level traits in case
context.traits is absent. Due to this configuration, you might be receiving a merged set of traits.
3. Can i really just deleteI can think of two solution for this: 1. Since in your case, both the traits are exactly the same, you can safely delete the top-level traits. a. Suppose you’re making an identify call using the JS SDK and then performing some transformation. In this case, there wouldn’t be any top-level traits, correct? So, I wanted to synchronise the same behaviour for you, as we expect in any other client-side SDKs. 2. If there is still any doubt at your end, then transform both the traits. This way, you can guarantee that the traits will remain the same even after getting merged. Please take note that in the future, we are expecting to synchronise the behaviour between client-side and server-side SDKs.every time and leavetraits?context.traits
thankful-gpu-70135
08/03/2023, 10:47 PMActually, some cloud mode destinations have been configured to fall back to the top-level traits in caseI'm seeing this with klaviyo but there must be a bug.is absent. Due to this configuration, you might be receiving a merged set of traits.context.traits
context.traits is present, but I'm also getting a merged set. I think that it should never merge if context.traits is present, otherwise you're saying the legacy support (top level traits) always interferes.thankful-gpu-70135
08/03/2023, 10:49 PMSuppose you’re making an identify call using the JS SDK and then performing some transformation. In this case, there wouldn’t be any top-level traits, correct?I am only using the JS sdk right now for some easy testing and sending of events to rudderstack. our "real" implementation will be done using the Ruby SDK on our service. This is how I even stumbled upon this issue.
1. Since in your case, both the traits are exactly the same, you can safely delete the top-level traits.
Ok i'll do this then, it's better and cleaner if indeed you are saying that
context.traits is the correct most up to date place to look for traits, and will be so moving forward./calm-yak-10773
08/04/2023, 4:58 AMI’m seeing this with klaviyo but there must be a bug.Could you please share the code snippet that you’re currently using to make the call to Klaviyo destination using the JS SDK? Additionally, it would be helpful if you could provide more information about which traits are getting merged. This information will assist us in debugging the issue more effectively. Thank you!is present, but I’m also getting a merged set. I think that it should never merge ifcontext.traitsis present, otherwise you’re saying the legacy support (top level traits) always interferes.context.traits
thankful-gpu-70135
08/04/2023, 5:41 AM{
context: {
traits: {
foo: {
bar: 1
}
}
},
traits: {
foo: {
bar: 1
}
}
}
if my transformations flatters only what’s in context.traits, I have this:
{
context: {
traits: {
foo_bar: 1
}
},
traits: {
foo: {
bar: 1
}
}
}
That user proprieties is sent in an identify call to rudderstack which is connected to klayvio as a destination, klayvio will show in its user properties:
{
foo_bar: 1,
foo: { bar: 1 }
}
Which means RS is merging the traits into a single prop bag and sending it.
If the top level traits is indeed a legacy situation I’d expect context.traits to supersede it and not get merged.calm-yak-10773
08/04/2023, 5:52 AMthankful-gpu-70135
08/04/2023, 6:32 AMcalm-yak-10773
08/04/2023, 7:04 AMIf the top level traits is indeed a legacy situation I’d expect context.traits to supersede it and not get merged.I agree, but actually Klayvio and other destinations are not designed to handle the same set of traits present in both context.traits and top-level traits simultaneously in an identify call. The root cause of the problem lies in the Ruby SDK, as it is generating the payload in an incorrect format. I would suggest you to proceed with two approaches, I suggested earlier, until we fix this in Ruby SDK:
1. Since in your case, both the traits are exactly the same, you can safely delete the top-level traits.
a. Suppose you’re making an identify call using the JS SDK and then performing some transformation. In this case, there wouldn’t be any top-level traits, correct? So, I wanted to synchronise the same behaviour for you, as we expect in any other client-side SDKs.
2. If there is still any doubt at your end, then transform both the traits. This way, you can guarantee that the traits will remain the same even after getting merged.
Ok i’ll do this then, it’s better and cleaner if indeed you are saying thatFor an identify call,is the correct most up to date place to look for traits, and will be so moving forward./context.traits
context.traits is indeed the appropriate place to look for the traits. Please proceed with this.
I’m actually not sure about JS sdkJS SDK wouldn’t cause this issue, as there will be no top level traits in an identify call.
thankful-gpu-70135
08/04/2023, 8:03 AMthankful-gpu-70135
08/04/2023, 7:21 PMcalm-yak-10773
08/04/2023, 7:46 PMUnfortunately, due to backward compatibility concerns, we are currently unable to implement this change.
I really appreciate your effort to raise the PR. Thanks again.
thankful-gpu-70135
08/04/2023, 9:03 PM