Hey all, is it possible to send custom context wit...
# support
d
Hey all, is it possible to send custom context with the React Native SDK? With the JS web SDK we can pass custom context via the third "options" parameter on page/screen/identify:
rudder.track("event", parameters, context)
. The key/value pairs in
context
will be added to the final
event.context
for us. This does not work with the RN SDK. We dug into the iOS source code and Android source code and discovered that the options object is being scrubbed so that only the
integrations
key and keys related to external ids are respected. Is there a way to set custom context via RN/iOS/Android? If not, what's the recommended way to pass things like our custom/internal client id, tenant id, app version, etc.? Thanks!
Here's what I think is allowing our custom context through when passed via the JS SDK's options parameter: https://github.com/rudderlabs/rudder-sdk-js/blob/c6d775f143c3f082c124503500b532032838b4ba/src/core/analytics.js#L1032-L1044
c
Hey @damp-napkin-69254, Unfortunately, our React Native SDK does not currently support the ability to pass custom context. I’ll raise this feature request to our team. From the mobile perspective, currently this feature is only available at our native Android and iOS SDKs. If you’re using cloud mode connections, then there is a workaround possible to set the customContext by using our transformation feature i.e., 1. Send the required customContext as a part of the properties. 2. Then use the transformation feature to create a new field in the context object and assign the customContext. 3. Then remove the customContext from the properties field. For reference, here is the sample code snippet: • Suppose you make track event in the React-Native as follows:
Copy code
const properties = { 
    customContext: {
      customContext1: {
        customKey1: "customValue1",
      }
    },
    key1: "value1",
  };
  rudderClient.track("Custom track Event - 1", properties);
where customContext is the field which you want to set in the context object. • So now, as a next step, you can use the following transformation code snippet to achieve the end result of moving the customContext object from properties to the context object:
Copy code
export function transformEvent(event, metadata) {
    const customContext = event.properties?.customContext;
    delete event.properties?.customContext;
    
    event.context.customContext = customContext; 
    return event;
}
Refer here to know more about the transformation feature: https://www.rudderstack.com/docs/features/transformations/ (Please note: Transformation will not work with device mode connections)
Is there a way to set custom context via RN/iOS/Android?
For Android and iOS, there do exist a way. • Refer the following Android code (in Kotlin):
Copy code
val option = RudderOption()
        option.putCustomContext("Context1", mapOf("customContextKey" to "customContextValue"))
        rudderClient.identify("RudderStack Android userId 2",
            RudderTraits()
                .put("displayName","RandomName_2")
                .putName("RudderStack_2")
                .putAge("123")
                .putEmail("support@rudderstack.com24"),
            option
        )
• You need to use the same putCustomContext API in iOS. Hope this will unblock you for now! CC: <!subteam^S04QT1G74Q3|@sdk-team>
d
Consider this a +1 for that feature request, but for now that transformer solution will work great thank you!
Is this a feature that could be implemented as an open source contribution?
c
Yes! It could be implemented as an open-source contribution. I’ll request you to please refer to this guideline: https://github.com/rudderlabs/rudder-sdk-react-native/blob/develop/CONTRIBUTING.md.
a
Hi @calm-yak-10773 or @damp-napkin-69254 - Was a solution reached for this? Im working with the RN SDK and am looking to customize the context before it leaves the client for PPI/ HIPAA compliance. We aren’t able to self host a control panel to use transformations, so looking for a way to mask some context properties before it either leaves the client, or leaves Rudderstack to our data warehouse. Thanks!
c
Hey @alert-shampoo-49789, Transformations are the only way to customise or modify event context or any other properties. (The previous discussion centered on the future support for sending custom context in our React-Native SDK.)
a
Thanks Abhishek Is there any plan to support this in the RN SDK, or implemented as an opensource contribution as mentioned above?
c
As you mentioned:
We aren’t able to self host a control panel
Does it mean you are using our hosted control plane? If that’s the case, you can utilise the transformation feature, right? Or is there any blocker?
a
We are not using Rudderstacks hosted control plane no, and the Lite version is deprecated (and does not support Transformations either)
c
So, you’re considering using the Control Plane Lite in the future, or are there any other plans? As of now, there is no plan to support this feature. However, I can pass this feature request to the team for consideration.
a
Isnt Control Panel Lite deprecated, and I understand doesnt support Transformations? If you can pass that feature request on that would be great, thank you.
c
I’ll definitely pass this as a feature request, but before that, could you please help me understand how you are planning to initialise the Rudder React Native SDK, as the SDK requires some configuration to be fetched from the control plane during the initialisation process.
a
We have an open source instance of Rudderstack configured and running for our website, which we are also using for the SDK.
👍 1
c
Thanks for the info, I've passed this as a feature request to our team.