@mparticle/web-rokt-kit 1.14.0 → 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 +158 -4
- package/dist/Rokt-Kit.iife.js +158 -4
- package/package.json +1 -1
package/dist/Rokt-Kit.common.js
CHANGED
|
@@ -41,8 +41,138 @@ var constructor = function () {
|
|
|
41
41
|
self.userAttributes = {};
|
|
42
42
|
self.testHelpers = null;
|
|
43
43
|
self.placementEventMappingLookup = {};
|
|
44
|
+
self.placementEventAttributeMappingLookup = {};
|
|
44
45
|
self.eventQueue = [];
|
|
45
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
|
+
|
|
46
176
|
/**
|
|
47
177
|
* Generates the Rokt launcher script URL with optional domain override and extensions
|
|
48
178
|
* @param {string} domain - The CNAME domain to use for overriding the launcher url
|
|
@@ -105,6 +235,12 @@ var constructor = function () {
|
|
|
105
235
|
placementEventMapping
|
|
106
236
|
);
|
|
107
237
|
|
|
238
|
+
var placementEventAttributeMapping = parseSettingsString(
|
|
239
|
+
settings.placementEventAttributeMapping
|
|
240
|
+
);
|
|
241
|
+
self.placementEventAttributeMappingLookup =
|
|
242
|
+
generateMappedEventAttributeLookup(placementEventAttributeMapping);
|
|
243
|
+
|
|
108
244
|
// Set dynamic OTHER_IDENTITY based on server settings
|
|
109
245
|
// Convert to lowercase since server sends TitleCase (e.g., 'Other' -> 'other')
|
|
110
246
|
if (settings.hashedEmailUserIdentityType) {
|
|
@@ -128,6 +264,8 @@ var constructor = function () {
|
|
|
128
264
|
hashEventMessage: hashEventMessage,
|
|
129
265
|
parseSettingsString: parseSettingsString,
|
|
130
266
|
generateMappedEventLookup: generateMappedEventLookup,
|
|
267
|
+
generateMappedEventAttributeLookup:
|
|
268
|
+
generateMappedEventAttributeLookup,
|
|
131
269
|
};
|
|
132
270
|
attachLauncher(accountId, launcherOptions);
|
|
133
271
|
return;
|
|
@@ -180,13 +318,18 @@ var constructor = function () {
|
|
|
180
318
|
|
|
181
319
|
function returnLocalSessionAttributes() {
|
|
182
320
|
if (
|
|
183
|
-
isEmpty(self.placementEventMappingLookup) ||
|
|
184
321
|
!window.mParticle.Rokt ||
|
|
185
322
|
typeof window.mParticle.Rokt.getLocalSessionAttributes !==
|
|
186
323
|
'function'
|
|
187
324
|
) {
|
|
188
325
|
return {};
|
|
189
326
|
}
|
|
327
|
+
if (
|
|
328
|
+
isEmpty(self.placementEventMappingLookup) &&
|
|
329
|
+
isEmpty(self.placementEventAttributeMappingLookup)
|
|
330
|
+
) {
|
|
331
|
+
return {};
|
|
332
|
+
}
|
|
190
333
|
return window.mParticle.Rokt.getLocalSessionAttributes();
|
|
191
334
|
}
|
|
192
335
|
|
|
@@ -305,7 +448,7 @@ var constructor = function () {
|
|
|
305
448
|
console.error('Rokt Kit: Not initialized');
|
|
306
449
|
return Promise.reject(new Error('Rokt Kit: Not initialized'));
|
|
307
450
|
}
|
|
308
|
-
if (!extensionName ||
|
|
451
|
+
if (!extensionName || !isString(extensionName)) {
|
|
309
452
|
return Promise.reject(
|
|
310
453
|
new Error('Rokt Kit: Invalid extension name')
|
|
311
454
|
);
|
|
@@ -343,12 +486,19 @@ var constructor = function () {
|
|
|
343
486
|
}
|
|
344
487
|
|
|
345
488
|
if (
|
|
346
|
-
isEmpty(self.placementEventMappingLookup) ||
|
|
347
489
|
typeof window.mParticle.Rokt.setLocalSessionAttribute !== 'function'
|
|
348
490
|
) {
|
|
349
491
|
return;
|
|
350
492
|
}
|
|
351
493
|
|
|
494
|
+
if (!isEmpty(self.placementEventAttributeMappingLookup)) {
|
|
495
|
+
applyPlacementEventAttributeMapping(event);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (isEmpty(self.placementEventMappingLookup)) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
352
502
|
var hashedEvent = hashEventMessage(
|
|
353
503
|
event.EventDataType,
|
|
354
504
|
event.EventCategory,
|
|
@@ -511,7 +661,7 @@ var constructor = function () {
|
|
|
511
661
|
|
|
512
662
|
function generateIntegrationName(customIntegrationName) {
|
|
513
663
|
var coreSdkVersion = window.mParticle.getVersion();
|
|
514
|
-
var kitVersion = "1.
|
|
664
|
+
var kitVersion = "1.15.0";
|
|
515
665
|
var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
|
|
516
666
|
|
|
517
667
|
if (customIntegrationName) {
|
|
@@ -617,6 +767,10 @@ function isEmpty(value) {
|
|
|
617
767
|
return value == null || !(Object.keys(value) || value).length;
|
|
618
768
|
}
|
|
619
769
|
|
|
770
|
+
function isString(value) {
|
|
771
|
+
return typeof value === 'string';
|
|
772
|
+
}
|
|
773
|
+
|
|
620
774
|
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
621
775
|
window.mParticle.addForwarder({
|
|
622
776
|
name: name,
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -40,8 +40,138 @@ var RoktKit = (function (exports) {
|
|
|
40
40
|
self.userAttributes = {};
|
|
41
41
|
self.testHelpers = null;
|
|
42
42
|
self.placementEventMappingLookup = {};
|
|
43
|
+
self.placementEventAttributeMappingLookup = {};
|
|
43
44
|
self.eventQueue = [];
|
|
44
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
|
+
|
|
45
175
|
/**
|
|
46
176
|
* Generates the Rokt launcher script URL with optional domain override and extensions
|
|
47
177
|
* @param {string} domain - The CNAME domain to use for overriding the launcher url
|
|
@@ -104,6 +234,12 @@ var RoktKit = (function (exports) {
|
|
|
104
234
|
placementEventMapping
|
|
105
235
|
);
|
|
106
236
|
|
|
237
|
+
var placementEventAttributeMapping = parseSettingsString(
|
|
238
|
+
settings.placementEventAttributeMapping
|
|
239
|
+
);
|
|
240
|
+
self.placementEventAttributeMappingLookup =
|
|
241
|
+
generateMappedEventAttributeLookup(placementEventAttributeMapping);
|
|
242
|
+
|
|
107
243
|
// Set dynamic OTHER_IDENTITY based on server settings
|
|
108
244
|
// Convert to lowercase since server sends TitleCase (e.g., 'Other' -> 'other')
|
|
109
245
|
if (settings.hashedEmailUserIdentityType) {
|
|
@@ -127,6 +263,8 @@ var RoktKit = (function (exports) {
|
|
|
127
263
|
hashEventMessage: hashEventMessage,
|
|
128
264
|
parseSettingsString: parseSettingsString,
|
|
129
265
|
generateMappedEventLookup: generateMappedEventLookup,
|
|
266
|
+
generateMappedEventAttributeLookup:
|
|
267
|
+
generateMappedEventAttributeLookup,
|
|
130
268
|
};
|
|
131
269
|
attachLauncher(accountId, launcherOptions);
|
|
132
270
|
return;
|
|
@@ -179,13 +317,18 @@ var RoktKit = (function (exports) {
|
|
|
179
317
|
|
|
180
318
|
function returnLocalSessionAttributes() {
|
|
181
319
|
if (
|
|
182
|
-
isEmpty(self.placementEventMappingLookup) ||
|
|
183
320
|
!window.mParticle.Rokt ||
|
|
184
321
|
typeof window.mParticle.Rokt.getLocalSessionAttributes !==
|
|
185
322
|
'function'
|
|
186
323
|
) {
|
|
187
324
|
return {};
|
|
188
325
|
}
|
|
326
|
+
if (
|
|
327
|
+
isEmpty(self.placementEventMappingLookup) &&
|
|
328
|
+
isEmpty(self.placementEventAttributeMappingLookup)
|
|
329
|
+
) {
|
|
330
|
+
return {};
|
|
331
|
+
}
|
|
189
332
|
return window.mParticle.Rokt.getLocalSessionAttributes();
|
|
190
333
|
}
|
|
191
334
|
|
|
@@ -304,7 +447,7 @@ var RoktKit = (function (exports) {
|
|
|
304
447
|
console.error('Rokt Kit: Not initialized');
|
|
305
448
|
return Promise.reject(new Error('Rokt Kit: Not initialized'));
|
|
306
449
|
}
|
|
307
|
-
if (!extensionName ||
|
|
450
|
+
if (!extensionName || !isString(extensionName)) {
|
|
308
451
|
return Promise.reject(
|
|
309
452
|
new Error('Rokt Kit: Invalid extension name')
|
|
310
453
|
);
|
|
@@ -342,12 +485,19 @@ var RoktKit = (function (exports) {
|
|
|
342
485
|
}
|
|
343
486
|
|
|
344
487
|
if (
|
|
345
|
-
isEmpty(self.placementEventMappingLookup) ||
|
|
346
488
|
typeof window.mParticle.Rokt.setLocalSessionAttribute !== 'function'
|
|
347
489
|
) {
|
|
348
490
|
return;
|
|
349
491
|
}
|
|
350
492
|
|
|
493
|
+
if (!isEmpty(self.placementEventAttributeMappingLookup)) {
|
|
494
|
+
applyPlacementEventAttributeMapping(event);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (isEmpty(self.placementEventMappingLookup)) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
|
|
351
501
|
var hashedEvent = hashEventMessage(
|
|
352
502
|
event.EventDataType,
|
|
353
503
|
event.EventCategory,
|
|
@@ -510,7 +660,7 @@ var RoktKit = (function (exports) {
|
|
|
510
660
|
|
|
511
661
|
function generateIntegrationName(customIntegrationName) {
|
|
512
662
|
var coreSdkVersion = window.mParticle.getVersion();
|
|
513
|
-
var kitVersion = "1.
|
|
663
|
+
var kitVersion = "1.15.0";
|
|
514
664
|
var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
|
|
515
665
|
|
|
516
666
|
if (customIntegrationName) {
|
|
@@ -616,6 +766,10 @@ var RoktKit = (function (exports) {
|
|
|
616
766
|
return value == null || !(Object.keys(value) || value).length;
|
|
617
767
|
}
|
|
618
768
|
|
|
769
|
+
function isString(value) {
|
|
770
|
+
return typeof value === 'string';
|
|
771
|
+
}
|
|
772
|
+
|
|
619
773
|
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
620
774
|
window.mParticle.addForwarder({
|
|
621
775
|
name: name,
|