Skip to content

Commit 7e114d1

Browse files
authored
feat: Support adding identities to select placement attributes (#35)
1 parent 58efaaa commit 7e114d1

2 files changed

Lines changed: 450 additions & 129 deletions

File tree

src/Rokt-Kit.js

Lines changed: 16 additions & 6 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,6 +114,18 @@ var constructor = function () {
115114
console.warn('Unable to find Rokt on the page');
116115
}
117116
}
117+
/**
118+
* Returns the user identities from the filtered user, if any
119+
* @param {Object} filteredUser - The filtered user object containing identities
120+
* @returns {Object} The user identities from the filtered user
121+
*/
122+
function returnUserIdentities(filteredUser) {
123+
if (!filteredUser || !filteredUser.getUserIdentities) {
124+
return {};
125+
}
126+
127+
return filteredUser.getUserIdentities().userIdentities;
128+
}
118129

119130
/**
120131
* Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options
@@ -160,8 +171,11 @@ var constructor = function () {
160171
? fetchOptimizely()
161172
: {};
162173

174+
var filteredUserIdentities = returnUserIdentities(filteredUser);
175+
163176
var selectPlacementsAttributes = mergeObjects(
164177
filteredAttributes,
178+
filteredUserIdentities,
165179
optimizelyAttributes,
166180
{
167181
mpid: mpid,
@@ -176,7 +190,7 @@ var constructor = function () {
176190
}
177191

178192
function onUserIdentified(filteredUser) {
179-
self.filteredUser = filteredUser;
193+
self.filters.filteredUser = filteredUser;
180194
self.userAttributes = filteredUser.getAllUserAttributes();
181195
}
182196

@@ -200,7 +214,6 @@ var constructor = function () {
200214
.then(function (launcher) {
201215
// Assign the launcher to a global variable for later access
202216
window.Rokt.currentLauncher = launcher;
203-
204217
// Locally cache the launcher and filters
205218
self.launcher = launcher;
206219

@@ -214,11 +227,8 @@ var constructor = function () {
214227
console.warn(
215228
'Rokt Kit: No filtered user has been set.'
216229
);
217-
} else {
218-
self.filteredUser = roktFilters.filteredUser;
219230
}
220231
}
221-
222232
// Attaches the kit to the Rokt manager
223233
window.mParticle.Rokt.attachKit(self);
224234

0 commit comments

Comments
 (0)