From 0e9c1913cc1e578395f4b59f6122186e3a114f56 Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 1 May 2024 11:32:59 -0400 Subject: [PATCH 1/6] fix: Allow any userIdentificationType to be used when initializing kit --- src/BrazeKit-dev.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/BrazeKit-dev.js b/src/BrazeKit-dev.js index 55305b3..3bd7828 100644 --- a/src/BrazeKit-dev.js +++ b/src/BrazeKit-dev.js @@ -792,10 +792,13 @@ var constructor = function () { braze.addSdkMetadata(['mp']); primeBrazeWebPush(); - if (forwarderSettings.userIdentificationType === 'MPID' && mParticle.Identity != null && mParticle.Identity.getCurrentUser().getMPID() != null) { - onUserIdentified(mParticle.Identity.getCurrentUser()) + if ( + mParticle.Identity != null && + mParticle.Identity.getCurrentUser().getMPID() != null + ) { + onUserIdentified(mParticle.Identity.getCurrentUser()); } - + openSession(forwarderSettings); } From 90e0d9f2e9489393db312937637f41273b5b534b Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 1 May 2024 11:44:16 -0400 Subject: [PATCH 2/6] Add test --- test/tests.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/tests.js b/test/tests.js index fcb69db..a4db635 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,16 @@ describe('Braze Forwarder', function() { delete mParticle.getVersion; }); + it('should set an identity on the user upon kit initialization', 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 set main braze user identity from userIdentificationType ', function() { mParticle.forwarder.init({ apiKey: '123456', From edc706773182056df62552a88fd4abeeb6dca70f Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 1 May 2024 11:44:58 -0400 Subject: [PATCH 3/6] Rephrase test --- test/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.js b/test/tests.js index a4db635..b572c6d 100644 --- a/test/tests.js +++ b/test/tests.js @@ -971,7 +971,7 @@ describe('Braze Forwarder', function() { delete mParticle.getVersion; }); - it('should set an identity on the user upon kit initialization', function() { + it('should set an identity on the user upon kit initialization when userIdentificationType is email', function() { mParticle.forwarder.init({ apiKey: '123456', userIdentificationType: 'Email', From dd4c425facb5250e7b379e8740fda6da5f91c304 Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Thu, 2 May 2024 16:43:39 -0400 Subject: [PATCH 4/6] Add case for when brazeUserIDType is null/undefined --- src/BrazeKit-dev.js | 6 ++++-- test/tests.js | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/BrazeKit-dev.js b/src/BrazeKit-dev.js index 3bd7828..5bd2358 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); diff --git a/test/tests.js b/test/tests.js index b572c6d..2098679 100644 --- a/test/tests.js +++ b/test/tests.js @@ -981,6 +981,15 @@ describe('Braze Forwarder', function() { 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', From 34dbadb2e2d94e6ea3879a49008c6f637bd02bfb Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Fri, 3 May 2024 11:58:21 -0400 Subject: [PATCH 5/6] Update src/BrazeKit-dev.js Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com> --- src/BrazeKit-dev.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BrazeKit-dev.js b/src/BrazeKit-dev.js index 5bd2358..82a307a 100644 --- a/src/BrazeKit-dev.js +++ b/src/BrazeKit-dev.js @@ -794,11 +794,11 @@ var constructor = function () { braze.addSdkMetadata(['mp']); primeBrazeWebPush(); - if ( - mParticle.Identity != null && - mParticle.Identity.getCurrentUser().getMPID() != null - ) { - onUserIdentified(mParticle.Identity.getCurrentUser()); + const currentUser = mParticle.Identity != null ? mParticle.Identity.getCurrentUser() : null; + const mpid = currentUser.getMPID(); + + if (currentUser && mpid) { + onUserIdentified(currentUser); } openSession(forwarderSettings); From 7883f304f7aff05a221af6a8b2b44d0ec0162f1e Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Fri, 3 May 2024 11:59:58 -0400 Subject: [PATCH 6/6] Check for null currentuser --- src/BrazeKit-dev.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/BrazeKit-dev.js b/src/BrazeKit-dev.js index 82a307a..3a3d23a 100644 --- a/src/BrazeKit-dev.js +++ b/src/BrazeKit-dev.js @@ -794,9 +794,12 @@ var constructor = function () { braze.addSdkMetadata(['mp']); primeBrazeWebPush(); - const currentUser = mParticle.Identity != null ? mParticle.Identity.getCurrentUser() : null; - const mpid = currentUser.getMPID(); - + const currentUser = + mParticle.Identity !== null + ? mParticle.Identity.getCurrentUser() + : null; + const mpid = currentUser ? currentUser.getMPID() : null; + if (currentUser && mpid) { onUserIdentified(currentUser); }