diff --git a/src/v0/destinations/splitio/data/EventConfig.json b/src/v0/destinations/splitio/data/EventConfig.json index d41398a5e2..6435458368 100644 --- a/src/v0/destinations/splitio/data/EventConfig.json +++ b/src/v0/destinations/splitio/data/EventConfig.json @@ -29,5 +29,17 @@ "type": "toFloat" }, "required": false + }, + { + "destKey": "trafficTypeName", + "sourceKeys": [ + "traits.trafficTypeName", + "context.traits.trafficTypeName", + "properties.trafficTypeName" + ], + "metadata": { + "type": "toString" + }, + "required": false } ] diff --git a/src/v0/destinations/splitio/transform.js b/src/v0/destinations/splitio/transform.js index 6641a62fe8..3dd5bea4f2 100644 --- a/src/v0/destinations/splitio/transform.js +++ b/src/v0/destinations/splitio/transform.js @@ -56,6 +56,7 @@ function prepareResponse(message, destination, category) { let outputPayload = {}; + // ref: https://docs.split.io/reference/events-overview outputPayload = constructPayload(message, MAPPING_CONFIG[category.name]); outputPayload.eventTypeId = outputPayload.eventTypeId.replace(/ /g, '_'); if (EVENT_TYPE_ID_REGEX.test(outputPayload.eventTypeId)) { @@ -93,7 +94,12 @@ function prepareResponse(message, destination, category) { if (isDefinedAndNotNullAndNotEmpty(environment)) { outputPayload.environmentName = environment; } - outputPayload.trafficTypeName = trafficType; + + // in case traffic type could not be mapped from the input payloads, falls back to the UI configured default traffic type. + if (!isDefinedAndNotNullAndNotEmpty(outputPayload.trafficTypeName)) { + outputPayload.trafficTypeName = trafficType; + } + outputPayload.properties = removeUndefinedNullValuesAndEmptyObjectArray( flattenJson(bufferProperty), ); diff --git a/test/integrations/destinations/splitio/processor/data.ts b/test/integrations/destinations/splitio/processor/data.ts index 3fda93cc30..d4c3e39794 100644 --- a/test/integrations/destinations/splitio/processor/data.ts +++ b/test/integrations/destinations/splitio/processor/data.ts @@ -43,7 +43,7 @@ export const data = [ Config: { apiKey: 'abcde', environment: 'staging', - trafficType: 'user', + trafficType: 'anonymous', }, }, }, @@ -246,7 +246,7 @@ export const data = [ Config: { apiKey: 'abcde', environment: 'production', - trafficType: 'user', + trafficType: 'anonymous', }, }, }, @@ -847,6 +847,9 @@ export const data = [ library: { name: 'http', }, + traits: { + trafficTypeName: 'user', + }, }, type: 'identify', timestamp: '2020-01-21T00:21:34.208Z', @@ -858,7 +861,7 @@ export const data = [ Config: { apiKey: 'abcde', environment: 'staging', - trafficType: 'user', + trafficType: 'anonymous', }, }, },