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: Set MPID before open session #41

5 changes: 5 additions & 0 deletions src/BrazeKit-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,11 @@ var constructor = function () {
function finishBrazeInitialization(forwarderSettings) {
braze.addSdkMetadata(['mp']);
primeBrazeWebPush();

if (forwarderSettings.userIdentificationType === 'MPID' && mParticle.Identity != null && mParticle.Identity.getCurrentUser().getMPID() != null) {
onUserIdentified(mParticle.Identity.getCurrentUser())
}

openSession(forwarderSettings);
}

Expand Down
27 changes: 26 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,22 @@ describe('Braze Forwarder', function() {
};
},
reportService = new ReportingService();

mParticle.Identity = {
getCurrentUser: function () {
return {
getMPID: function () {
return 'MPID123';
},
getUserIdentities: function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is getUserIdentities a necessary addition?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, it is necessary, yes. The getUserIdentities function is needed in the onUserIdentified call which sets the Braze identity. In retrospect, I'm calling the onUserIdentified function which in turn calls the Braze changeUser function. Seems like I could skip the secondary function and call the Braze function directly - would it make sense to make that change to eliminate the getUserIdentities and the extra processing?

return {
userIdentities: {
customerid: 'abc',
},
};
},
};
},
};
before(function() {
// expandCommerceEvent is tightly coupled to mParticle being loaded
// as well as having a few parameters on the Store.
Expand Down Expand Up @@ -1698,6 +1713,16 @@ USD,
purchaseEventProperties.should.eql(expectedPurchaseEvent);
});

it('should call changeUser and openSession on init with userIdentificationType MPID passed in forwarding settings', function() {
mParticle.forwarder.init({
apiKey: '123456',
userIdentificationType: 'MPID',
});

window.braze.userId.should.equal('MPID123');
window.braze.should.have.property('openSessionCalled', true);
});

describe('promotion events', function() {
const mpPromotionEvent = {
EventName: 'eCommerce - PromotionClick',
Expand Down
Loading