Skip to content

Commit

Permalink
feat: improved page/track calls braze (#669)
Browse files Browse the repository at this point in the history
fix: improved page/track calls braze
  • Loading branch information
aashishmalik authored Oct 11, 2022
1 parent e29d2af commit b348fb9
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions integrations/Braze/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Braze {
constructor(config, analytics) {
this.analytics = analytics;
this.appKey = config.appKey;
this.trackAnonymousUser = config.trackAnonymousUser;
this.enableHtmlInAppMessages = config.enableHtmlInAppMessages || false;
this.allowUserSuppliedJavascript =
config.allowUserSuppliedJavascript || false;
Expand Down Expand Up @@ -225,23 +226,39 @@ class Braze {
const { userId } = rudderElement.message;
const eventName = rudderElement.message.event;
let { properties } = rudderElement.message;

window.braze.changeUser(userId);
if (eventName && eventName.toLowerCase() === "order completed") {
this.handlePurchase(properties, userId);
} else {
properties = this.handleReservedProperties(properties);
window.braze.logCustomEvent(eventName, properties);
let canSendCustomEvent = false;
if (userId) {
window.braze.changeUser(userId);
canSendCustomEvent = true;
} else if (this.trackAnonymousUser) {
window.braze.changeUser(rudderElement.message.anonymousId);
canSendCustomEvent = true;
}
if (eventName && canSendCustomEvent) {
if (eventName.toLowerCase() === "order completed") {
this.handlePurchase(properties, userId);
} else {
properties = this.handleReservedProperties(properties);
window.braze.logCustomEvent(eventName, properties);
}
}
}

page(rudderElement) {
const { userId } = rudderElement.message;
const eventName = rudderElement.message.name;
let { properties } = rudderElement.message;
if (userId) {
window.braze.changeUser(userId);
} else if (this.trackAnonymousUser) {
window.braze.changeUser(rudderElement.message.anonymousId);
}
properties = this.handleReservedProperties(properties);
window.braze.changeUser(userId);
window.braze.logCustomEvent(eventName, properties);
if (eventName) {
window.braze.logCustomEvent(eventName, properties);
} else {
window.braze.logCustomEvent("Page View", properties);
}
}

isLoaded() {
Expand Down

0 comments on commit b348fb9

Please sign in to comment.