From 99603ec2a81955e7a26a646e3da75404d109bc83 Mon Sep 17 00:00:00 2001 From: Utsab Chowdhury Date: Mon, 29 Apr 2024 12:00:18 +0530 Subject: [PATCH] fix: braze dedup for non-billable attributes --- src/v0/destinations/braze/braze.util.test.js | 2 +- src/v0/destinations/braze/util.js | 20 +++---- .../destinations/braze/router/data.ts | 60 ++++++++++++++++++- 3 files changed, 69 insertions(+), 13 deletions(-) diff --git a/src/v0/destinations/braze/braze.util.test.js b/src/v0/destinations/braze/braze.util.test.js index 7b6a93d359..6b3a650e8d 100644 --- a/src/v0/destinations/braze/braze.util.test.js +++ b/src/v0/destinations/braze/braze.util.test.js @@ -757,7 +757,7 @@ describe('dedup utility tests', () => { }; store.set('123', storeData); const result = BrazeDedupUtility.deduplicate(userData, store); - expect(result).toBeNull(); + expect(result).toEqual({ country: 'US', external_id: '123', language: 'en' }); }); test('returns null if all keys have $add, $update, or $remove properties', () => { diff --git a/src/v0/destinations/braze/util.js b/src/v0/destinations/braze/util.js index 5f1f1e6205..060756ce8e 100644 --- a/src/v0/destinations/braze/util.js +++ b/src/v0/destinations/braze/util.js @@ -284,12 +284,17 @@ const BrazeDedupUtility = { return true; }); - if (keys.length === 0) { - return null; + if (keys.length > 0) { + keys.forEach((key) => { + if (!_.isEqual(userData[key], storedUserData[key])) { + deduplicatedUserData[key] = userData[key]; + } + }); } - keys.forEach((key) => { - if (!_.isEqual(userData[key], storedUserData[key])) { + // add non billable attributes back to the deduplicated user object + BRAZE_NON_BILLABLE_ATTRIBUTES.forEach((key) => { + if (isDefinedAndNotNull(userData[key])) { deduplicatedUserData[key] = userData[key]; } }); @@ -305,13 +310,6 @@ const BrazeDedupUtility = { const identifier = external_id || user_alias?.alias_name; store.set(identifier, { ...storedUserData, ...deduplicatedUserData }); - // add non billable attributes back to the deduplicated user object - BRAZE_NON_BILLABLE_ATTRIBUTES.forEach((key) => { - if (isDefinedAndNotNull(userData[key])) { - deduplicatedUserData[key] = userData[key]; - } - }); - return removeUndefinedValues(deduplicatedUserData); }, }; diff --git a/test/integrations/destinations/braze/router/data.ts b/test/integrations/destinations/braze/router/data.ts index 76201bda41..6803742e86 100644 --- a/test/integrations/destinations/braze/router/data.ts +++ b/test/integrations/destinations/braze/router/data.ts @@ -640,6 +640,59 @@ export const data = [ userId: 'user@50', }, }, + { + destination: { + ID: '2N9UakqKF0D35wfzSeofIxPdL8X', + Name: 'Braze-Test', + Config: { + appKey: '0e5440c3-226b-45d0-91b5-c64da56cde16', + blacklistedEvents: [], + dataCenter: 'US-03', + enableNestedArrayOperations: false, + enableSubscriptionGroupInGroupCall: false, + eventFilteringOption: 'disable', + oneTrustCookieCategories: [], + restApiKey: 'dummyApiKey', + supportDedup: true, + trackAnonymousUser: true, + whitelistedEvents: [], + }, + Enabled: true, + WorkspaceID: '27O0bhB6p5ehfOWeeZlOSsSDTLg', + Transformations: [], + IsProcessorEnabled: true, + RevisionID: '2N9Uaf2tWq2QRmatBWQm03Rz6qX', + }, + metadata: { jobId: 5, userId: 'u1' }, + message: { + anonymousId: 'e6ab2c5e-2cda-44a9-a962-e2f67df78bca', + channel: 'web', + context: { + app: { + build: '1.0.0', + name: 'RudderLabs JavaScript SDK', + namespace: 'com.rudderlabs.javascript', + version: '1.0.5', + }, + ip: '0.0.0.0', + library: { name: 'RudderLabs JavaScript SDK', version: '1.0.5' }, + locale: 'en-GB', + os: { name: '', version: '' }, + screen: { density: 2 }, + traits: { + city: 'Disney', + email: 'mickey@disney.com', + firstName: 'Mickey', + }, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36', + }, + integrations: { All: true }, + messageId: '2536eda4-d638-4c93-8014-8ffe3f083214', + type: 'identify', + userId: 'user@50', + }, + }, ], destType: 'braze', }, @@ -688,6 +741,10 @@ export const data = [ external_id: 'user@50', first_name: 'Mickey', }, + { + country: 'USA', + external_id: 'user@50', + }, ], events: [ { @@ -733,6 +790,7 @@ export const data = [ { jobId: 1, userId: 'u1' }, { jobId: 2, userId: 'u1' }, { jobId: 3, userId: 'u1' }, + { jobId: 4, userId: 'u1' }, ], batched: true, statusCode: 200, @@ -771,7 +829,7 @@ export const data = [ }, statusCode: 400, batched: false, - metadata: [{ jobId: 4, userId: 'u1' }], + metadata: [{ jobId: 5, userId: 'u1' }], destination: { ID: '2N9UakqKF0D35wfzSeofIxPdL8X', Name: 'Braze-Test',