Skip to content

Commit

Permalink
fix: allowing traffic type dynamically for split.io (#3425)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 authored Jun 10, 2024
1 parent e124470 commit 3bea186
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/v0/destinations/splitio/data/EventConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@
"type": "toFloat"
},
"required": false
},
{
"destKey": "trafficTypeName",
"sourceKeys": [
"traits.trafficTypeName",
"context.traits.trafficTypeName",
"properties.trafficTypeName"
],
"metadata": {
"type": "toString"
},
"required": false
}
]
8 changes: 7 additions & 1 deletion src/v0/destinations/splitio/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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),
);
Expand Down
9 changes: 6 additions & 3 deletions test/integrations/destinations/splitio/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const data = [
Config: {
apiKey: 'abcde',
environment: 'staging',
trafficType: 'user',
trafficType: 'anonymous',
},
},
},
Expand Down Expand Up @@ -246,7 +246,7 @@ export const data = [
Config: {
apiKey: 'abcde',
environment: 'production',
trafficType: 'user',
trafficType: 'anonymous',
},
},
},
Expand Down Expand Up @@ -847,6 +847,9 @@ export const data = [
library: {
name: 'http',
},
traits: {
trafficTypeName: 'user',
},
},
type: 'identify',
timestamp: '2020-01-21T00:21:34.208Z',
Expand All @@ -858,7 +861,7 @@ export const data = [
Config: {
apiKey: 'abcde',
environment: 'staging',
trafficType: 'user',
trafficType: 'anonymous',
},
},
},
Expand Down

0 comments on commit 3bea186

Please sign in to comment.