Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for custom properties for braze purchase events #2856

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/v0/destinations/braze/braze.util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,4 +1219,75 @@ describe('getPurchaseObjs', () => {
);
}
});

test('products having extra properties', () => {
const output = getPurchaseObjs({
properties: {
products: [
{ product_id: '123', price: 10.99, quantity: 2, random_extra_property_a: 'abc' },
{ product_id: '456', price: 5.49, quantity: 1, random_extra_property_b: 'efg' },
{
product_id: '789',
price: 15.49,
quantity: 1,
random_extra_property_a: 'abc',
random_extra_property_b: 'efg',
random_extra_property_c: 'hij',
},
],
currency: 'USD',
},
timestamp: '2023-08-04T12:34:56Z',
anonymousId: 'abc',
});
expect(output).toEqual([
{
product_id: '123',
price: 10.99,
currency: 'USD',
quantity: 2,
time: '2023-08-04T12:34:56Z',
properties: {
random_extra_property_a: 'abc',
},
_update_existing_only: false,
user_alias: {
alias_name: 'abc',
alias_label: 'rudder_id',
},
},
{
product_id: '456',
price: 5.49,
currency: 'USD',
quantity: 1,
time: '2023-08-04T12:34:56Z',
properties: {
random_extra_property_b: 'efg',
},
_update_existing_only: false,
user_alias: {
alias_name: 'abc',
alias_label: 'rudder_id',
},
},
{
product_id: '789',
price: 15.49,
currency: 'USD',
quantity: 1,
time: '2023-08-04T12:34:56Z',
properties: {
random_extra_property_a: 'abc',
random_extra_property_b: 'efg',
random_extra_property_c: 'hij',
},
_update_existing_only: false,
user_alias: {
alias_name: 'abc',
alias_label: 'rudder_id',
},
},
]);
});
});
4 changes: 4 additions & 0 deletions src/v0/destinations/braze/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ function getPurchaseObjs(message) {
parseInt(quantity, 10),
timestamp,
);
const extraProperties = _.omit(product, ['product_id', 'sku', 'price', 'quantity', 'currency']);
utsabc marked this conversation as resolved.
Show resolved Hide resolved
utsabc marked this conversation as resolved.
Show resolved Hide resolved
utsabc marked this conversation as resolved.
Show resolved Hide resolved
if (Object.keys(extraProperties).length > 0) {
purchaseObj = { ...purchaseObj, properties: extraProperties };
}
purchaseObj = setExternalIdOrAliasObject(purchaseObj, message);
purchaseObjs.push(purchaseObj);
});
Expand Down
26 changes: 26 additions & 0 deletions test/__tests__/data/braze_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@
"currency": "USD",
"price": 0,
"product_id": "507f1f77bcf86cd799439011",
"properties": {
"category": "Games",
"image_url": "https:///www.example.com/product/path.jpg",
"name": "Monopoly: 3rd Edition",
"url": "https://www.example.com/product/path"
},
"quantity": 1,
"time": "2020-01-24T11:59:02.402+05:30",
"user_alias": {
Expand All @@ -408,6 +414,10 @@
"currency": "USD",
"price": 0,
"product_id": "505bd76785ebb509fc183733",
"properties": {
"category": "Games",
"name": "Uno Card Game"
},
"quantity": 2,
"time": "2020-01-24T11:59:02.402+05:30",
"user_alias": {
Expand Down Expand Up @@ -457,6 +467,12 @@
"currency": "USD",
"price": 0,
"product_id": "507f1f77bcf86cd799439011",
"properties": {
"category": "Games",
"image_url": "https:///www.example.com/product/path.jpg",
"name": "Monopoly: 3rd Edition",
"url": "https://www.example.com/product/path"
},
"quantity": 1,
"time": "2020-01-24T11:59:02.402+05:30",
"user_alias": {
Expand All @@ -469,6 +485,10 @@
"currency": "USD",
"price": 10,
"product_id": "505bd76785ebb509fc183733",
"properties": {
"category": "Games",
"name": "Uno Card Game"
},
"quantity": 2,
"time": "2020-01-24T11:59:02.402+05:30",
"user_alias": {
Expand Down Expand Up @@ -855,6 +875,12 @@
"purchases": [
{
"product_id": "507f1f77bcf86cd799439011",
"properties": {
"category": "Games",
"image_url": "https:///www.example.com/product/path.jpg",
"name": "Monopoly: 3rd Edition",
"url": "https://www.example.com/product/path"
},
"price": 0,
"currency": "USD",
"quantity": 1,
Expand Down
Loading