Skip to content

Commit

Permalink
logpurchase event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajashekar Varkala authored and Rajashekar Varkala committed Feb 11, 2020
1 parent 019d745 commit 993dcce
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions integrations/Braze/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class Braze {
return props;
}

identify(rudderElement) {
console.log(rudderElement);
identify(rudderElement) {

var userId = rudderElement.message.userId;
var address = rudderElement.message.context.traits.address;
Expand Down Expand Up @@ -129,15 +128,44 @@ class Braze {
});
}


handlePurchase(properties,userId){
var products = properties.products ;
var currencyCode = properties.currency;

window.appboy.changeUser(userId);

// del used properties
del(properties, 'products');
del(properties, 'currency');

// we have to make a separate call to appboy for each product
products .forEach(product => {
var productId = product.product_id;
var price = product.price;
var quantity = product.quantity;
if(quantity && price && productId)
window.appboy.logPurchase(productId, price, currencyCode, quantity, properties);
});

}

track(rudderElement) {
var userId = rudderElement.message.userId;
var eventName = rudderElement.message.event;
var properties = rudderElement.message.properties;

properties = this.handleReservedProperties(properties);

window.appboy.changeUser(userId);
window.appboy.logCustomEvent(eventName, properties);

if(eventName.toLowerCase() === 'order completed')
{
this.handlePurchase(properties,userId);
}
else
{
properties = this.handleReservedProperties(properties);
window.appboy.logCustomEvent(eventName, properties);
}
}


Expand Down

0 comments on commit 993dcce

Please sign in to comment.