diff --git a/src/BrazeKit-dev.js b/src/BrazeKit-dev.js index 55305b3..3a3d23a 100644 --- a/src/BrazeKit-dev.js +++ b/src/BrazeKit-dev.js @@ -632,9 +632,11 @@ var constructor = function () { ]; } - kitLogger('braze.changeUser', brazeUserIDType); + if (brazeUserIDType) { + kitLogger('braze.changeUser', brazeUserIDType); - braze.changeUser(brazeUserIDType); + braze.changeUser(brazeUserIDType); + } if (userIdentities.email) { kitLogger('braze.getUser().setEmail', userIdentities.email); @@ -792,10 +794,16 @@ var constructor = function () { braze.addSdkMetadata(['mp']); primeBrazeWebPush(); - if (forwarderSettings.userIdentificationType === 'MPID' && mParticle.Identity != null && mParticle.Identity.getCurrentUser().getMPID() != null) { - onUserIdentified(mParticle.Identity.getCurrentUser()) + const currentUser = + mParticle.Identity !== null + ? mParticle.Identity.getCurrentUser() + : null; + const mpid = currentUser ? currentUser.getMPID() : null; + + if (currentUser && mpid) { + onUserIdentified(currentUser); } - + openSession(forwarderSettings); } diff --git a/test/tests.js b/test/tests.js index fcb69db..2098679 100644 --- a/test/tests.js +++ b/test/tests.js @@ -254,6 +254,7 @@ describe('Braze Forwarder', function() { return { userIdentities: { customerid: 'abc', + email: 'email@gmail.com' }, }; }, @@ -970,6 +971,25 @@ describe('Braze Forwarder', function() { delete mParticle.getVersion; }); + it('should set an identity on the user upon kit initialization when userIdentificationType is email', function() { + mParticle.forwarder.init({ + apiKey: '123456', + userIdentificationType: 'Email', + }); + + window.braze.userId.should.equal('email@gmail.com'); + window.braze.getUser().emailSet.should.equal('email@gmail.com'); + }); + + it('should not attempt to set an identity on braze if the userIdentificationType does not exist on the customer', function() { + mParticle.forwarder.init({ + apiKey: '123456', + userIdentificationType: 'other2', + }); + + Should(window.braze.userId).equal(null); + }); + it('should set main braze user identity from userIdentificationType ', function() { mParticle.forwarder.init({ apiKey: '123456',