Skip to content

Commit 113f9b3

Browse files
committed
Simplify identity additions to selectplacement, remove duplicate filtered users
1 parent 203ffcc commit 113f9b3

2 files changed

Lines changed: 10 additions & 32 deletions

File tree

src/Rokt-Kit.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ var constructor = function () {
2525

2626
self.launcher = null;
2727
self.filters = {};
28-
self.filteredUser = {};
2928
self.userAttributes = {};
3029

3130
/**
@@ -115,31 +114,17 @@ var constructor = function () {
115114
console.warn('Unable to find Rokt on the page');
116115
}
117116
}
118-
119117
/**
120-
* Adds user identities to the attributes object
121-
* @param {Object} attributes - The attributes object to add identities to
118+
* Returns the user identities from the filtered user, if any
122119
* @param {Object} filteredUser - The filtered user object containing identities
123-
* @returns {Object} The attributes object with added identities
120+
* @returns {Object} The user identities from the filtered user
124121
*/
125-
function addIdentityAttributes(attributes, filteredUser) {
122+
function returnUserIdentities(filteredUser) {
126123
if (!filteredUser || !filteredUser.getUserIdentities) {
127-
return attributes;
128-
}
129-
130-
var userIdentities = filteredUser.getUserIdentities().userIdentities;
131-
if (!userIdentities) {
132-
return attributes;
133-
}
134-
135-
for (var identityKey in userIdentities) {
136-
if (userIdentities.hasOwnProperty(identityKey)) {
137-
var identityValue = userIdentities[identityKey];
138-
attributes[identityKey] = identityValue;
139-
}
124+
return {};
140125
}
141126

142-
return attributes;
127+
return filteredUser.getUserIdentities().userIdentities;
143128
}
144129

145130
/**
@@ -186,14 +171,11 @@ var constructor = function () {
186171
? fetchOptimizely()
187172
: {};
188173

189-
// Add user identities to the attributes
190-
filteredAttributes = addIdentityAttributes(
191-
filteredAttributes,
192-
filteredUser
193-
);
174+
var filteredUserIdentities = returnUserIdentities(filteredUser);
194175

195176
var selectPlacementsAttributes = mergeObjects(
196177
filteredAttributes,
178+
filteredUserIdentities,
197179
optimizelyAttributes,
198180
{
199181
mpid: mpid,
@@ -208,7 +190,6 @@ var constructor = function () {
208190
}
209191

210192
function onUserIdentified(filteredUser) {
211-
self.filteredUser = filteredUser;
212193
self.filters.filteredUser = filteredUser;
213194
self.userAttributes = filteredUser.getAllUserAttributes();
214195
}
@@ -246,8 +227,6 @@ var constructor = function () {
246227
console.warn(
247228
'Rokt Kit: No filtered user has been set.'
248229
);
249-
} else {
250-
self.filteredUser = roktFilters.filteredUser;
251230
}
252231
}
253232
// Attaches the kit to the Rokt manager

test/src/tests.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe('Rokt Forwarder', () => {
235235
},
236236
});
237237

238-
window.mParticle.Rokt.kit.filteredUser
238+
window.mParticle.Rokt.kit.filters.filteredUser
239239
.getMPID()
240240
.should.equal('123');
241241
});
@@ -971,9 +971,8 @@ describe('Rokt Forwarder', () => {
971971
'test-attribute': 'test-value',
972972
});
973973

974-
window.mParticle.forwarder.filteredUser
975-
.getMPID()
976-
.should.equal('123');
974+
window.mParticle.forwarder.filters.filteredUser
975+
.getMPID().should.equal('123');
977976
});
978977
});
979978

0 commit comments

Comments
 (0)