Skip to content

Commit

Permalink
feat: adding awin property pattern check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Apr 29, 2024
1 parent 53b6cf0 commit 2602715
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/v0/destinations/awin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ const trackProduct = (properties, advertiserId, commissionParts) => {
// ref: https://wiki.awin.com/index.php/Advertiser_Tracking_Guide/Product_Level_Tracking#PLT_Via_Conversion_Pixel
const populateCustomTransactionProperties = (properties, customFieldMap) => {
const customObject = {};
const customPropertyPattern = '^\\s*p\\d+\\s*$';
const regex = new RegExp(customPropertyPattern, 'i');
const propertyMap = getHashFromArray(customFieldMap, 'from', 'to', false);
Object.entries(propertyMap).forEach(([rudderProperty, awinProperty]) => {
const fieldValue = properties[rudderProperty];
if (fieldValue) {
customObject[awinProperty] = fieldValue;
if (regex.test(awinProperty)) {
const fieldValue = properties[rudderProperty];
if (fieldValue) {
customObject[awinProperty] = fieldValue;
}
}
});
return customObject;
Expand Down
10 changes: 6 additions & 4 deletions src/v0/destinations/awin/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,16 @@ describe('populateCustomTransactionProperties', () => {
rudderProperty1: 'value1',
rudderProperty2: 123,
rudderProperty3: 'value3',
rudderProperty4: 234,
};
const customFieldMap = [
{ from: 'rudderProperty1', to: 'awinProperty1' },
{ from: 'rudderProperty2', to: 'awinProperty2' },
{ from: 'rudderProperty1', to: 'p1' },
{ from: 'rudderProperty2', to: 'p2' },
{ from: 'rudderProperty4', to: 'anotherp2' },
];
const expectedOutput = {
awinProperty1: 'value1',
awinProperty2: 123,
p1: 'value1',
p2: 123,
};

const result = populateCustomTransactionProperties(properties, customFieldMap);
Expand Down

0 comments on commit 2602715

Please sign in to comment.