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: Allow any userIdentificationType to be used when initializing kit #48

Merged
merged 6 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/BrazeKit-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -792,10 +794,16 @@ var constructor = function () {
braze.addSdkMetadata(['mp']);
primeBrazeWebPush();

if (forwarderSettings.userIdentificationType === 'MPID' && mParticle.Identity != null && mParticle.Identity.getCurrentUser().getMPID() != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're no longer referencing forwarderSettings, we should remove it from the function parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is still being passed to openSession at the bottom of this function

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ooof. Missed that.

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);
}

Expand Down
20 changes: 20 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ describe('Braze Forwarder', function() {
return {
userIdentities: {
customerid: 'abc',
email: '[email protected]'
},
};
},
Expand Down Expand Up @@ -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 protected]');
window.braze.getUser().emailSet.should.equal('[email protected]');
});

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',
Expand Down
Loading