@mparticle/web-rokt-kit 1.13.1 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Rokt-Kit.common.js +200 -13
- package/dist/Rokt-Kit.iife.js +200 -13
- package/package.json +10 -6
package/dist/Rokt-Kit.common.js
CHANGED
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
19
19
|
|
|
20
20
|
var name = 'Rokt';
|
|
21
21
|
var moduleId = 181;
|
|
22
|
+
var EVENT_NAME_SELECT_PLACEMENTS = 'selectPlacements';
|
|
22
23
|
|
|
23
24
|
var constructor = function () {
|
|
24
25
|
var self = this;
|
|
@@ -40,8 +41,138 @@ var constructor = function () {
|
|
|
40
41
|
self.userAttributes = {};
|
|
41
42
|
self.testHelpers = null;
|
|
42
43
|
self.placementEventMappingLookup = {};
|
|
44
|
+
self.placementEventAttributeMappingLookup = {};
|
|
43
45
|
self.eventQueue = [];
|
|
44
46
|
|
|
47
|
+
function getEventAttributeValue(event, eventAttributeKey) {
|
|
48
|
+
var attributes = event && event.EventAttributes;
|
|
49
|
+
if (!attributes) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (typeof attributes[eventAttributeKey] === 'undefined') {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return attributes[eventAttributeKey];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function doesEventAttributeConditionMatch(condition, actualValue) {
|
|
61
|
+
if (!condition || !isString(condition.operator)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var operator = condition.operator.toLowerCase();
|
|
66
|
+
var expectedValue = condition.attributeValue;
|
|
67
|
+
|
|
68
|
+
if (operator === 'exists') {
|
|
69
|
+
return actualValue !== null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (actualValue == null) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (operator === 'equals') {
|
|
77
|
+
return String(actualValue) === String(expectedValue);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (operator === 'contains') {
|
|
81
|
+
return String(actualValue).indexOf(String(expectedValue)) !== -1;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function doesEventMatchRule(event, rule) {
|
|
88
|
+
if (!rule || !isString(rule.eventAttributeKey)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var conditions = rule.conditions;
|
|
93
|
+
if (!Array.isArray(conditions)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var actualValue = getEventAttributeValue(event, rule.eventAttributeKey);
|
|
98
|
+
|
|
99
|
+
if (conditions.length === 0) {
|
|
100
|
+
return actualValue !== null;
|
|
101
|
+
}
|
|
102
|
+
for (var i = 0; i < conditions.length; i++) {
|
|
103
|
+
if (!doesEventAttributeConditionMatch(conditions[i], actualValue)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function generateMappedEventAttributeLookup(
|
|
112
|
+
placementEventAttributeMapping
|
|
113
|
+
) {
|
|
114
|
+
var mappedAttributeKeys = {};
|
|
115
|
+
if (!Array.isArray(placementEventAttributeMapping)) {
|
|
116
|
+
return mappedAttributeKeys;
|
|
117
|
+
}
|
|
118
|
+
for (var i = 0; i < placementEventAttributeMapping.length; i++) {
|
|
119
|
+
var mapping = placementEventAttributeMapping[i];
|
|
120
|
+
if (
|
|
121
|
+
!mapping ||
|
|
122
|
+
!isString(mapping.value) ||
|
|
123
|
+
!isString(mapping.map)
|
|
124
|
+
) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var mappedAttributeKey = mapping.value;
|
|
129
|
+
var eventAttributeKey = mapping.map;
|
|
130
|
+
|
|
131
|
+
if (!mappedAttributeKeys[mappedAttributeKey]) {
|
|
132
|
+
mappedAttributeKeys[mappedAttributeKey] = [];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
mappedAttributeKeys[mappedAttributeKey].push({
|
|
136
|
+
eventAttributeKey: eventAttributeKey,
|
|
137
|
+
conditions: Array.isArray(mapping.conditions)
|
|
138
|
+
? mapping.conditions
|
|
139
|
+
: [],
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return mappedAttributeKeys;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function applyPlacementEventAttributeMapping(event) {
|
|
146
|
+
var mappedAttributeKeys = Object.keys(
|
|
147
|
+
self.placementEventAttributeMappingLookup
|
|
148
|
+
);
|
|
149
|
+
for (var i = 0; i < mappedAttributeKeys.length; i++) {
|
|
150
|
+
var mappedAttributeKey = mappedAttributeKeys[i];
|
|
151
|
+
var rulesForMappedAttributeKey =
|
|
152
|
+
self.placementEventAttributeMappingLookup[mappedAttributeKey];
|
|
153
|
+
if (isEmpty(rulesForMappedAttributeKey)) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Require ALL rules for the same key to match (AND).
|
|
158
|
+
var allMatch = true;
|
|
159
|
+
for (var j = 0; j < rulesForMappedAttributeKey.length; j++) {
|
|
160
|
+
if (!doesEventMatchRule(event, rulesForMappedAttributeKey[j])) {
|
|
161
|
+
allMatch = false;
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (!allMatch) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
window.mParticle.Rokt.setLocalSessionAttribute(
|
|
170
|
+
mappedAttributeKey,
|
|
171
|
+
true
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
45
176
|
/**
|
|
46
177
|
* Generates the Rokt launcher script URL with optional domain override and extensions
|
|
47
178
|
* @param {string} domain - The CNAME domain to use for overriding the launcher url
|
|
@@ -62,6 +193,14 @@ var constructor = function () {
|
|
|
62
193
|
return baseUrl + '?extensions=' + extensions.join(',');
|
|
63
194
|
}
|
|
64
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Checks if Rokt launcher is available and ready to attach
|
|
198
|
+
* @returns {boolean} True if launcher can be attached
|
|
199
|
+
*/
|
|
200
|
+
function isLauncherReadyToAttach() {
|
|
201
|
+
return window.Rokt && typeof window.Rokt.createLauncher === 'function';
|
|
202
|
+
}
|
|
203
|
+
|
|
65
204
|
/**
|
|
66
205
|
* Passes attributes to the Rokt Web SDK for client-side hashing
|
|
67
206
|
* @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes
|
|
@@ -96,6 +235,12 @@ var constructor = function () {
|
|
|
96
235
|
placementEventMapping
|
|
97
236
|
);
|
|
98
237
|
|
|
238
|
+
var placementEventAttributeMapping = parseSettingsString(
|
|
239
|
+
settings.placementEventAttributeMapping
|
|
240
|
+
);
|
|
241
|
+
self.placementEventAttributeMappingLookup =
|
|
242
|
+
generateMappedEventAttributeLookup(placementEventAttributeMapping);
|
|
243
|
+
|
|
99
244
|
// Set dynamic OTHER_IDENTITY based on server settings
|
|
100
245
|
// Convert to lowercase since server sends TitleCase (e.g., 'Other' -> 'other')
|
|
101
246
|
if (settings.hashedEmailUserIdentityType) {
|
|
@@ -119,12 +264,16 @@ var constructor = function () {
|
|
|
119
264
|
hashEventMessage: hashEventMessage,
|
|
120
265
|
parseSettingsString: parseSettingsString,
|
|
121
266
|
generateMappedEventLookup: generateMappedEventLookup,
|
|
267
|
+
generateMappedEventAttributeLookup:
|
|
268
|
+
generateMappedEventAttributeLookup,
|
|
122
269
|
};
|
|
123
270
|
attachLauncher(accountId, launcherOptions);
|
|
124
271
|
return;
|
|
125
272
|
}
|
|
126
273
|
|
|
127
|
-
if (
|
|
274
|
+
if (isLauncherReadyToAttach()) {
|
|
275
|
+
attachLauncher(accountId, launcherOptions);
|
|
276
|
+
} else {
|
|
128
277
|
var target = document.head || document.body;
|
|
129
278
|
var script = document.createElement('script');
|
|
130
279
|
script.type = 'text/javascript';
|
|
@@ -135,12 +284,7 @@ var constructor = function () {
|
|
|
135
284
|
script.id = 'rokt-launcher';
|
|
136
285
|
|
|
137
286
|
script.onload = function () {
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
window.Rokt &&
|
|
141
|
-
typeof window.Rokt.createLauncher === 'function' &&
|
|
142
|
-
window.Rokt.currentLauncher === undefined
|
|
143
|
-
) {
|
|
287
|
+
if (isLauncherReadyToAttach()) {
|
|
144
288
|
attachLauncher(accountId, launcherOptions);
|
|
145
289
|
} else {
|
|
146
290
|
console.error(
|
|
@@ -155,8 +299,6 @@ var constructor = function () {
|
|
|
155
299
|
|
|
156
300
|
target.appendChild(script);
|
|
157
301
|
captureTiming(PerformanceMarks.RoktScriptAppended);
|
|
158
|
-
} else {
|
|
159
|
-
console.warn('Unable to find Rokt on the page');
|
|
160
302
|
}
|
|
161
303
|
}
|
|
162
304
|
/**
|
|
@@ -176,13 +318,18 @@ var constructor = function () {
|
|
|
176
318
|
|
|
177
319
|
function returnLocalSessionAttributes() {
|
|
178
320
|
if (
|
|
179
|
-
isEmpty(self.placementEventMappingLookup) ||
|
|
180
321
|
!window.mParticle.Rokt ||
|
|
181
322
|
typeof window.mParticle.Rokt.getLocalSessionAttributes !==
|
|
182
323
|
'function'
|
|
183
324
|
) {
|
|
184
325
|
return {};
|
|
185
326
|
}
|
|
327
|
+
if (
|
|
328
|
+
isEmpty(self.placementEventMappingLookup) &&
|
|
329
|
+
isEmpty(self.placementEventAttributeMappingLookup)
|
|
330
|
+
) {
|
|
331
|
+
return {};
|
|
332
|
+
}
|
|
186
333
|
return window.mParticle.Rokt.getLocalSessionAttributes();
|
|
187
334
|
}
|
|
188
335
|
|
|
@@ -259,9 +406,38 @@ var constructor = function () {
|
|
|
259
406
|
attributes: selectPlacementsAttributes,
|
|
260
407
|
});
|
|
261
408
|
|
|
409
|
+
// Log custom event for selectPlacements call
|
|
410
|
+
logSelectPlacementsEvent(selectPlacementsAttributes);
|
|
411
|
+
|
|
262
412
|
return self.launcher.selectPlacements(selectPlacementsOptions);
|
|
263
413
|
}
|
|
264
414
|
|
|
415
|
+
/**
|
|
416
|
+
* Logs a custom event when selectPlacements is called
|
|
417
|
+
* This enables visibility and troubleshooting
|
|
418
|
+
* @param {Object} attributes - The attributes sent to Rokt
|
|
419
|
+
*/
|
|
420
|
+
function logSelectPlacementsEvent(attributes) {
|
|
421
|
+
if (
|
|
422
|
+
!window.mParticle ||
|
|
423
|
+
typeof window.mParticle.logEvent !== 'function'
|
|
424
|
+
) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (!isObject(attributes)) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
var EVENT_TYPE_OTHER = window.mParticle.EventType.Other;
|
|
433
|
+
|
|
434
|
+
window.mParticle.logEvent(
|
|
435
|
+
EVENT_NAME_SELECT_PLACEMENTS,
|
|
436
|
+
EVENT_TYPE_OTHER,
|
|
437
|
+
attributes
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
|
|
265
441
|
/**
|
|
266
442
|
* Enables optional Integration Launcher extensions before selecting placements
|
|
267
443
|
* @param {string} extensionName - Name of the extension to enable
|
|
@@ -272,7 +448,7 @@ var constructor = function () {
|
|
|
272
448
|
console.error('Rokt Kit: Not initialized');
|
|
273
449
|
return Promise.reject(new Error('Rokt Kit: Not initialized'));
|
|
274
450
|
}
|
|
275
|
-
if (!extensionName ||
|
|
451
|
+
if (!extensionName || !isString(extensionName)) {
|
|
276
452
|
return Promise.reject(
|
|
277
453
|
new Error('Rokt Kit: Invalid extension name')
|
|
278
454
|
);
|
|
@@ -310,12 +486,19 @@ var constructor = function () {
|
|
|
310
486
|
}
|
|
311
487
|
|
|
312
488
|
if (
|
|
313
|
-
isEmpty(self.placementEventMappingLookup) ||
|
|
314
489
|
typeof window.mParticle.Rokt.setLocalSessionAttribute !== 'function'
|
|
315
490
|
) {
|
|
316
491
|
return;
|
|
317
492
|
}
|
|
318
493
|
|
|
494
|
+
if (!isEmpty(self.placementEventAttributeMappingLookup)) {
|
|
495
|
+
applyPlacementEventAttributeMapping(event);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (isEmpty(self.placementEventMappingLookup)) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
319
502
|
var hashedEvent = hashEventMessage(
|
|
320
503
|
event.EventDataType,
|
|
321
504
|
event.EventCategory,
|
|
@@ -478,7 +661,7 @@ var constructor = function () {
|
|
|
478
661
|
|
|
479
662
|
function generateIntegrationName(customIntegrationName) {
|
|
480
663
|
var coreSdkVersion = window.mParticle.getVersion();
|
|
481
|
-
var kitVersion = "1.
|
|
664
|
+
var kitVersion = "1.15.0";
|
|
482
665
|
var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
|
|
483
666
|
|
|
484
667
|
if (customIntegrationName) {
|
|
@@ -584,6 +767,10 @@ function isEmpty(value) {
|
|
|
584
767
|
return value == null || !(Object.keys(value) || value).length;
|
|
585
768
|
}
|
|
586
769
|
|
|
770
|
+
function isString(value) {
|
|
771
|
+
return typeof value === 'string';
|
|
772
|
+
}
|
|
773
|
+
|
|
587
774
|
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
588
775
|
window.mParticle.addForwarder({
|
|
589
776
|
name: name,
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -18,6 +18,7 @@ var RoktKit = (function (exports) {
|
|
|
18
18
|
|
|
19
19
|
var name = 'Rokt';
|
|
20
20
|
var moduleId = 181;
|
|
21
|
+
var EVENT_NAME_SELECT_PLACEMENTS = 'selectPlacements';
|
|
21
22
|
|
|
22
23
|
var constructor = function () {
|
|
23
24
|
var self = this;
|
|
@@ -39,8 +40,138 @@ var RoktKit = (function (exports) {
|
|
|
39
40
|
self.userAttributes = {};
|
|
40
41
|
self.testHelpers = null;
|
|
41
42
|
self.placementEventMappingLookup = {};
|
|
43
|
+
self.placementEventAttributeMappingLookup = {};
|
|
42
44
|
self.eventQueue = [];
|
|
43
45
|
|
|
46
|
+
function getEventAttributeValue(event, eventAttributeKey) {
|
|
47
|
+
var attributes = event && event.EventAttributes;
|
|
48
|
+
if (!attributes) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (typeof attributes[eventAttributeKey] === 'undefined') {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return attributes[eventAttributeKey];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function doesEventAttributeConditionMatch(condition, actualValue) {
|
|
60
|
+
if (!condition || !isString(condition.operator)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var operator = condition.operator.toLowerCase();
|
|
65
|
+
var expectedValue = condition.attributeValue;
|
|
66
|
+
|
|
67
|
+
if (operator === 'exists') {
|
|
68
|
+
return actualValue !== null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (actualValue == null) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (operator === 'equals') {
|
|
76
|
+
return String(actualValue) === String(expectedValue);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (operator === 'contains') {
|
|
80
|
+
return String(actualValue).indexOf(String(expectedValue)) !== -1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function doesEventMatchRule(event, rule) {
|
|
87
|
+
if (!rule || !isString(rule.eventAttributeKey)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
var conditions = rule.conditions;
|
|
92
|
+
if (!Array.isArray(conditions)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var actualValue = getEventAttributeValue(event, rule.eventAttributeKey);
|
|
97
|
+
|
|
98
|
+
if (conditions.length === 0) {
|
|
99
|
+
return actualValue !== null;
|
|
100
|
+
}
|
|
101
|
+
for (var i = 0; i < conditions.length; i++) {
|
|
102
|
+
if (!doesEventAttributeConditionMatch(conditions[i], actualValue)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function generateMappedEventAttributeLookup(
|
|
111
|
+
placementEventAttributeMapping
|
|
112
|
+
) {
|
|
113
|
+
var mappedAttributeKeys = {};
|
|
114
|
+
if (!Array.isArray(placementEventAttributeMapping)) {
|
|
115
|
+
return mappedAttributeKeys;
|
|
116
|
+
}
|
|
117
|
+
for (var i = 0; i < placementEventAttributeMapping.length; i++) {
|
|
118
|
+
var mapping = placementEventAttributeMapping[i];
|
|
119
|
+
if (
|
|
120
|
+
!mapping ||
|
|
121
|
+
!isString(mapping.value) ||
|
|
122
|
+
!isString(mapping.map)
|
|
123
|
+
) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
var mappedAttributeKey = mapping.value;
|
|
128
|
+
var eventAttributeKey = mapping.map;
|
|
129
|
+
|
|
130
|
+
if (!mappedAttributeKeys[mappedAttributeKey]) {
|
|
131
|
+
mappedAttributeKeys[mappedAttributeKey] = [];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
mappedAttributeKeys[mappedAttributeKey].push({
|
|
135
|
+
eventAttributeKey: eventAttributeKey,
|
|
136
|
+
conditions: Array.isArray(mapping.conditions)
|
|
137
|
+
? mapping.conditions
|
|
138
|
+
: [],
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return mappedAttributeKeys;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function applyPlacementEventAttributeMapping(event) {
|
|
145
|
+
var mappedAttributeKeys = Object.keys(
|
|
146
|
+
self.placementEventAttributeMappingLookup
|
|
147
|
+
);
|
|
148
|
+
for (var i = 0; i < mappedAttributeKeys.length; i++) {
|
|
149
|
+
var mappedAttributeKey = mappedAttributeKeys[i];
|
|
150
|
+
var rulesForMappedAttributeKey =
|
|
151
|
+
self.placementEventAttributeMappingLookup[mappedAttributeKey];
|
|
152
|
+
if (isEmpty(rulesForMappedAttributeKey)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Require ALL rules for the same key to match (AND).
|
|
157
|
+
var allMatch = true;
|
|
158
|
+
for (var j = 0; j < rulesForMappedAttributeKey.length; j++) {
|
|
159
|
+
if (!doesEventMatchRule(event, rulesForMappedAttributeKey[j])) {
|
|
160
|
+
allMatch = false;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!allMatch) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
window.mParticle.Rokt.setLocalSessionAttribute(
|
|
169
|
+
mappedAttributeKey,
|
|
170
|
+
true
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
44
175
|
/**
|
|
45
176
|
* Generates the Rokt launcher script URL with optional domain override and extensions
|
|
46
177
|
* @param {string} domain - The CNAME domain to use for overriding the launcher url
|
|
@@ -61,6 +192,14 @@ var RoktKit = (function (exports) {
|
|
|
61
192
|
return baseUrl + '?extensions=' + extensions.join(',');
|
|
62
193
|
}
|
|
63
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Checks if Rokt launcher is available and ready to attach
|
|
197
|
+
* @returns {boolean} True if launcher can be attached
|
|
198
|
+
*/
|
|
199
|
+
function isLauncherReadyToAttach() {
|
|
200
|
+
return window.Rokt && typeof window.Rokt.createLauncher === 'function';
|
|
201
|
+
}
|
|
202
|
+
|
|
64
203
|
/**
|
|
65
204
|
* Passes attributes to the Rokt Web SDK for client-side hashing
|
|
66
205
|
* @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes
|
|
@@ -95,6 +234,12 @@ var RoktKit = (function (exports) {
|
|
|
95
234
|
placementEventMapping
|
|
96
235
|
);
|
|
97
236
|
|
|
237
|
+
var placementEventAttributeMapping = parseSettingsString(
|
|
238
|
+
settings.placementEventAttributeMapping
|
|
239
|
+
);
|
|
240
|
+
self.placementEventAttributeMappingLookup =
|
|
241
|
+
generateMappedEventAttributeLookup(placementEventAttributeMapping);
|
|
242
|
+
|
|
98
243
|
// Set dynamic OTHER_IDENTITY based on server settings
|
|
99
244
|
// Convert to lowercase since server sends TitleCase (e.g., 'Other' -> 'other')
|
|
100
245
|
if (settings.hashedEmailUserIdentityType) {
|
|
@@ -118,12 +263,16 @@ var RoktKit = (function (exports) {
|
|
|
118
263
|
hashEventMessage: hashEventMessage,
|
|
119
264
|
parseSettingsString: parseSettingsString,
|
|
120
265
|
generateMappedEventLookup: generateMappedEventLookup,
|
|
266
|
+
generateMappedEventAttributeLookup:
|
|
267
|
+
generateMappedEventAttributeLookup,
|
|
121
268
|
};
|
|
122
269
|
attachLauncher(accountId, launcherOptions);
|
|
123
270
|
return;
|
|
124
271
|
}
|
|
125
272
|
|
|
126
|
-
if (
|
|
273
|
+
if (isLauncherReadyToAttach()) {
|
|
274
|
+
attachLauncher(accountId, launcherOptions);
|
|
275
|
+
} else {
|
|
127
276
|
var target = document.head || document.body;
|
|
128
277
|
var script = document.createElement('script');
|
|
129
278
|
script.type = 'text/javascript';
|
|
@@ -134,12 +283,7 @@ var RoktKit = (function (exports) {
|
|
|
134
283
|
script.id = 'rokt-launcher';
|
|
135
284
|
|
|
136
285
|
script.onload = function () {
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
window.Rokt &&
|
|
140
|
-
typeof window.Rokt.createLauncher === 'function' &&
|
|
141
|
-
window.Rokt.currentLauncher === undefined
|
|
142
|
-
) {
|
|
286
|
+
if (isLauncherReadyToAttach()) {
|
|
143
287
|
attachLauncher(accountId, launcherOptions);
|
|
144
288
|
} else {
|
|
145
289
|
console.error(
|
|
@@ -154,8 +298,6 @@ var RoktKit = (function (exports) {
|
|
|
154
298
|
|
|
155
299
|
target.appendChild(script);
|
|
156
300
|
captureTiming(PerformanceMarks.RoktScriptAppended);
|
|
157
|
-
} else {
|
|
158
|
-
console.warn('Unable to find Rokt on the page');
|
|
159
301
|
}
|
|
160
302
|
}
|
|
161
303
|
/**
|
|
@@ -175,13 +317,18 @@ var RoktKit = (function (exports) {
|
|
|
175
317
|
|
|
176
318
|
function returnLocalSessionAttributes() {
|
|
177
319
|
if (
|
|
178
|
-
isEmpty(self.placementEventMappingLookup) ||
|
|
179
320
|
!window.mParticle.Rokt ||
|
|
180
321
|
typeof window.mParticle.Rokt.getLocalSessionAttributes !==
|
|
181
322
|
'function'
|
|
182
323
|
) {
|
|
183
324
|
return {};
|
|
184
325
|
}
|
|
326
|
+
if (
|
|
327
|
+
isEmpty(self.placementEventMappingLookup) &&
|
|
328
|
+
isEmpty(self.placementEventAttributeMappingLookup)
|
|
329
|
+
) {
|
|
330
|
+
return {};
|
|
331
|
+
}
|
|
185
332
|
return window.mParticle.Rokt.getLocalSessionAttributes();
|
|
186
333
|
}
|
|
187
334
|
|
|
@@ -258,9 +405,38 @@ var RoktKit = (function (exports) {
|
|
|
258
405
|
attributes: selectPlacementsAttributes,
|
|
259
406
|
});
|
|
260
407
|
|
|
408
|
+
// Log custom event for selectPlacements call
|
|
409
|
+
logSelectPlacementsEvent(selectPlacementsAttributes);
|
|
410
|
+
|
|
261
411
|
return self.launcher.selectPlacements(selectPlacementsOptions);
|
|
262
412
|
}
|
|
263
413
|
|
|
414
|
+
/**
|
|
415
|
+
* Logs a custom event when selectPlacements is called
|
|
416
|
+
* This enables visibility and troubleshooting
|
|
417
|
+
* @param {Object} attributes - The attributes sent to Rokt
|
|
418
|
+
*/
|
|
419
|
+
function logSelectPlacementsEvent(attributes) {
|
|
420
|
+
if (
|
|
421
|
+
!window.mParticle ||
|
|
422
|
+
typeof window.mParticle.logEvent !== 'function'
|
|
423
|
+
) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (!isObject(attributes)) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
var EVENT_TYPE_OTHER = window.mParticle.EventType.Other;
|
|
432
|
+
|
|
433
|
+
window.mParticle.logEvent(
|
|
434
|
+
EVENT_NAME_SELECT_PLACEMENTS,
|
|
435
|
+
EVENT_TYPE_OTHER,
|
|
436
|
+
attributes
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
264
440
|
/**
|
|
265
441
|
* Enables optional Integration Launcher extensions before selecting placements
|
|
266
442
|
* @param {string} extensionName - Name of the extension to enable
|
|
@@ -271,7 +447,7 @@ var RoktKit = (function (exports) {
|
|
|
271
447
|
console.error('Rokt Kit: Not initialized');
|
|
272
448
|
return Promise.reject(new Error('Rokt Kit: Not initialized'));
|
|
273
449
|
}
|
|
274
|
-
if (!extensionName ||
|
|
450
|
+
if (!extensionName || !isString(extensionName)) {
|
|
275
451
|
return Promise.reject(
|
|
276
452
|
new Error('Rokt Kit: Invalid extension name')
|
|
277
453
|
);
|
|
@@ -309,12 +485,19 @@ var RoktKit = (function (exports) {
|
|
|
309
485
|
}
|
|
310
486
|
|
|
311
487
|
if (
|
|
312
|
-
isEmpty(self.placementEventMappingLookup) ||
|
|
313
488
|
typeof window.mParticle.Rokt.setLocalSessionAttribute !== 'function'
|
|
314
489
|
) {
|
|
315
490
|
return;
|
|
316
491
|
}
|
|
317
492
|
|
|
493
|
+
if (!isEmpty(self.placementEventAttributeMappingLookup)) {
|
|
494
|
+
applyPlacementEventAttributeMapping(event);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (isEmpty(self.placementEventMappingLookup)) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
|
|
318
501
|
var hashedEvent = hashEventMessage(
|
|
319
502
|
event.EventDataType,
|
|
320
503
|
event.EventCategory,
|
|
@@ -477,7 +660,7 @@ var RoktKit = (function (exports) {
|
|
|
477
660
|
|
|
478
661
|
function generateIntegrationName(customIntegrationName) {
|
|
479
662
|
var coreSdkVersion = window.mParticle.getVersion();
|
|
480
|
-
var kitVersion = "1.
|
|
663
|
+
var kitVersion = "1.15.0";
|
|
481
664
|
var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
|
|
482
665
|
|
|
483
666
|
if (customIntegrationName) {
|
|
@@ -583,6 +766,10 @@ var RoktKit = (function (exports) {
|
|
|
583
766
|
return value == null || !(Object.keys(value) || value).length;
|
|
584
767
|
}
|
|
585
768
|
|
|
769
|
+
function isString(value) {
|
|
770
|
+
return typeof value === 'string';
|
|
771
|
+
}
|
|
772
|
+
|
|
586
773
|
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
587
774
|
window.mParticle.addForwarder({
|
|
588
775
|
name: name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-rokt-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "mParticle integration kit for Rokt",
|
|
5
5
|
"main": "dist/Rokt-Kit.common.js",
|
|
6
6
|
"files": [
|
|
@@ -19,13 +19,17 @@
|
|
|
19
19
|
"test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
|
-
"access": "public"
|
|
22
|
+
"access": "public",
|
|
23
|
+
"provenance": true,
|
|
24
|
+
"registry": "https://registry.npmjs.org"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
25
27
|
"@rollup/plugin-json": "^6.1.0",
|
|
26
|
-
"@semantic-release/changelog": "^
|
|
27
|
-
"@semantic-release/exec": "^
|
|
28
|
-
"@semantic-release/git": "^
|
|
28
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
29
|
+
"@semantic-release/exec": "^6.0.3",
|
|
30
|
+
"@semantic-release/git": "^10.0.1",
|
|
31
|
+
"@semantic-release/npm": "^13.1.2",
|
|
32
|
+
"semantic-release": "^24.2.0",
|
|
29
33
|
"mocha": "^5.2.0",
|
|
30
34
|
"chai": "^4.2.0",
|
|
31
35
|
"eslint": "^7.25.0",
|
|
@@ -46,7 +50,7 @@
|
|
|
46
50
|
"watchify": "^3.11.0"
|
|
47
51
|
},
|
|
48
52
|
"dependencies": {
|
|
49
|
-
"@mparticle/web-sdk": "^2.
|
|
53
|
+
"@mparticle/web-sdk": "^2.56.0"
|
|
50
54
|
},
|
|
51
55
|
"license": "Apache-2.0"
|
|
52
56
|
}
|