Skip to content

Commit

Permalink
fix: braze dedup for non-billable attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc committed Apr 29, 2024
1 parent 7b1d11b commit 99603ec
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/v0/destinations/braze/braze.util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
20 changes: 9 additions & 11 deletions src/v0/destinations/braze/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
});
Expand All @@ -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);
},
};
Expand Down
60 changes: 59 additions & 1 deletion test/integrations/destinations/braze/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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',
},
Expand Down Expand Up @@ -688,6 +741,10 @@ export const data = [
external_id: 'user@50',
first_name: 'Mickey',
},
{
country: 'USA',
external_id: 'user@50',
},
],
events: [
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 99603ec

Please sign in to comment.