@mparticle/web-rokt-kit 1.14.0 → 1.16.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.
@@ -41,7 +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 = [];
46
+ self.integrationName = null;
47
+
48
+ function getEventAttributeValue(event, eventAttributeKey) {
49
+ var attributes = event && event.EventAttributes;
50
+ if (!attributes) {
51
+ return null;
52
+ }
53
+
54
+ if (typeof attributes[eventAttributeKey] === 'undefined') {
55
+ return null;
56
+ }
57
+
58
+ return attributes[eventAttributeKey];
59
+ }
60
+
61
+ function doesEventAttributeConditionMatch(condition, actualValue) {
62
+ if (!condition || !isString(condition.operator)) {
63
+ return false;
64
+ }
65
+
66
+ var operator = condition.operator.toLowerCase();
67
+ var expectedValue = condition.attributeValue;
68
+
69
+ if (operator === 'exists') {
70
+ return actualValue !== null;
71
+ }
72
+
73
+ if (actualValue == null) {
74
+ return false;
75
+ }
76
+
77
+ if (operator === 'equals') {
78
+ return String(actualValue) === String(expectedValue);
79
+ }
80
+
81
+ if (operator === 'contains') {
82
+ return String(actualValue).indexOf(String(expectedValue)) !== -1;
83
+ }
84
+
85
+ return false;
86
+ }
87
+
88
+ function doesEventMatchRule(event, rule) {
89
+ if (!rule || !isString(rule.eventAttributeKey)) {
90
+ return false;
91
+ }
92
+
93
+ var conditions = rule.conditions;
94
+ if (!Array.isArray(conditions)) {
95
+ return false;
96
+ }
97
+
98
+ var actualValue = getEventAttributeValue(event, rule.eventAttributeKey);
99
+
100
+ if (conditions.length === 0) {
101
+ return actualValue !== null;
102
+ }
103
+ for (var i = 0; i < conditions.length; i++) {
104
+ if (!doesEventAttributeConditionMatch(conditions[i], actualValue)) {
105
+ return false;
106
+ }
107
+ }
108
+
109
+ return true;
110
+ }
111
+
112
+ function generateMappedEventAttributeLookup(
113
+ placementEventAttributeMapping
114
+ ) {
115
+ var mappedAttributeKeys = {};
116
+ if (!Array.isArray(placementEventAttributeMapping)) {
117
+ return mappedAttributeKeys;
118
+ }
119
+ for (var i = 0; i < placementEventAttributeMapping.length; i++) {
120
+ var mapping = placementEventAttributeMapping[i];
121
+ if (
122
+ !mapping ||
123
+ !isString(mapping.value) ||
124
+ !isString(mapping.map)
125
+ ) {
126
+ continue;
127
+ }
128
+
129
+ var mappedAttributeKey = mapping.value;
130
+ var eventAttributeKey = mapping.map;
131
+
132
+ if (!mappedAttributeKeys[mappedAttributeKey]) {
133
+ mappedAttributeKeys[mappedAttributeKey] = [];
134
+ }
135
+
136
+ mappedAttributeKeys[mappedAttributeKey].push({
137
+ eventAttributeKey: eventAttributeKey,
138
+ conditions: Array.isArray(mapping.conditions)
139
+ ? mapping.conditions
140
+ : [],
141
+ });
142
+ }
143
+ return mappedAttributeKeys;
144
+ }
145
+
146
+ function applyPlacementEventAttributeMapping(event) {
147
+ var mappedAttributeKeys = Object.keys(
148
+ self.placementEventAttributeMappingLookup
149
+ );
150
+ for (var i = 0; i < mappedAttributeKeys.length; i++) {
151
+ var mappedAttributeKey = mappedAttributeKeys[i];
152
+ var rulesForMappedAttributeKey =
153
+ self.placementEventAttributeMappingLookup[mappedAttributeKey];
154
+ if (isEmpty(rulesForMappedAttributeKey)) {
155
+ continue;
156
+ }
157
+
158
+ // Require ALL rules for the same key to match (AND).
159
+ var allMatch = true;
160
+ for (var j = 0; j < rulesForMappedAttributeKey.length; j++) {
161
+ if (!doesEventMatchRule(event, rulesForMappedAttributeKey[j])) {
162
+ allMatch = false;
163
+ break;
164
+ }
165
+ }
166
+ if (!allMatch) {
167
+ continue;
168
+ }
169
+
170
+ window.mParticle.Rokt.setLocalSessionAttribute(
171
+ mappedAttributeKey,
172
+ true
173
+ );
174
+ }
175
+ }
45
176
 
46
177
  /**
47
178
  * Generates the Rokt launcher script URL with optional domain override and extensions
@@ -105,6 +236,12 @@ var constructor = function () {
105
236
  placementEventMapping
106
237
  );
107
238
 
239
+ var placementEventAttributeMapping = parseSettingsString(
240
+ settings.placementEventAttributeMapping
241
+ );
242
+ self.placementEventAttributeMappingLookup =
243
+ generateMappedEventAttributeLookup(placementEventAttributeMapping);
244
+
108
245
  // Set dynamic OTHER_IDENTITY based on server settings
109
246
  // Convert to lowercase since server sends TitleCase (e.g., 'Other' -> 'other')
110
247
  if (settings.hashedEmailUserIdentityType) {
@@ -117,9 +254,10 @@ var constructor = function () {
117
254
  {},
118
255
  window.mParticle.Rokt.launcherOptions || {}
119
256
  );
120
- launcherOptions.integrationName = generateIntegrationName(
257
+ self.integrationName = generateIntegrationName(
121
258
  launcherOptions.integrationName
122
259
  );
260
+ launcherOptions.integrationName = self.integrationName;
123
261
 
124
262
  if (testMode) {
125
263
  self.testHelpers = {
@@ -128,6 +266,8 @@ var constructor = function () {
128
266
  hashEventMessage: hashEventMessage,
129
267
  parseSettingsString: parseSettingsString,
130
268
  generateMappedEventLookup: generateMappedEventLookup,
269
+ generateMappedEventAttributeLookup:
270
+ generateMappedEventAttributeLookup,
131
271
  };
132
272
  attachLauncher(accountId, launcherOptions);
133
273
  return;
@@ -180,13 +320,18 @@ var constructor = function () {
180
320
 
181
321
  function returnLocalSessionAttributes() {
182
322
  if (
183
- isEmpty(self.placementEventMappingLookup) ||
184
323
  !window.mParticle.Rokt ||
185
324
  typeof window.mParticle.Rokt.getLocalSessionAttributes !==
186
325
  'function'
187
326
  ) {
188
327
  return {};
189
328
  }
329
+ if (
330
+ isEmpty(self.placementEventMappingLookup) &&
331
+ isEmpty(self.placementEventAttributeMappingLookup)
332
+ ) {
333
+ return {};
334
+ }
190
335
  return window.mParticle.Rokt.getLocalSessionAttributes();
191
336
  }
192
337
 
@@ -305,7 +450,7 @@ var constructor = function () {
305
450
  console.error('Rokt Kit: Not initialized');
306
451
  return Promise.reject(new Error('Rokt Kit: Not initialized'));
307
452
  }
308
- if (!extensionName || typeof extensionName !== 'string') {
453
+ if (!extensionName || !isString(extensionName)) {
309
454
  return Promise.reject(
310
455
  new Error('Rokt Kit: Invalid extension name')
311
456
  );
@@ -343,12 +488,19 @@ var constructor = function () {
343
488
  }
344
489
 
345
490
  if (
346
- isEmpty(self.placementEventMappingLookup) ||
347
491
  typeof window.mParticle.Rokt.setLocalSessionAttribute !== 'function'
348
492
  ) {
349
493
  return;
350
494
  }
351
495
 
496
+ if (!isEmpty(self.placementEventAttributeMappingLookup)) {
497
+ applyPlacementEventAttributeMapping(event);
498
+ }
499
+
500
+ if (isEmpty(self.placementEventMappingLookup)) {
501
+ return;
502
+ }
503
+
352
504
  var hashedEvent = hashEventMessage(
353
505
  event.EventDataType,
354
506
  event.EventCategory,
@@ -511,7 +663,7 @@ var constructor = function () {
511
663
 
512
664
  function generateIntegrationName(customIntegrationName) {
513
665
  var coreSdkVersion = window.mParticle.getVersion();
514
- var kitVersion = "1.14.0";
666
+ var kitVersion = "1.16.0";
515
667
  var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
516
668
 
517
669
  if (customIntegrationName) {
@@ -617,6 +769,10 @@ function isEmpty(value) {
617
769
  return value == null || !(Object.keys(value) || value).length;
618
770
  }
619
771
 
772
+ function isString(value) {
773
+ return typeof value === 'string';
774
+ }
775
+
620
776
  if (window && window.mParticle && window.mParticle.addForwarder) {
621
777
  window.mParticle.addForwarder({
622
778
  name: name,
@@ -40,7 +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 = [];
45
+ self.integrationName = null;
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
+ }
44
175
 
45
176
  /**
46
177
  * Generates the Rokt launcher script URL with optional domain override and extensions
@@ -104,6 +235,12 @@ var RoktKit = (function (exports) {
104
235
  placementEventMapping
105
236
  );
106
237
 
238
+ var placementEventAttributeMapping = parseSettingsString(
239
+ settings.placementEventAttributeMapping
240
+ );
241
+ self.placementEventAttributeMappingLookup =
242
+ generateMappedEventAttributeLookup(placementEventAttributeMapping);
243
+
107
244
  // Set dynamic OTHER_IDENTITY based on server settings
108
245
  // Convert to lowercase since server sends TitleCase (e.g., 'Other' -> 'other')
109
246
  if (settings.hashedEmailUserIdentityType) {
@@ -116,9 +253,10 @@ var RoktKit = (function (exports) {
116
253
  {},
117
254
  window.mParticle.Rokt.launcherOptions || {}
118
255
  );
119
- launcherOptions.integrationName = generateIntegrationName(
256
+ self.integrationName = generateIntegrationName(
120
257
  launcherOptions.integrationName
121
258
  );
259
+ launcherOptions.integrationName = self.integrationName;
122
260
 
123
261
  if (testMode) {
124
262
  self.testHelpers = {
@@ -127,6 +265,8 @@ var RoktKit = (function (exports) {
127
265
  hashEventMessage: hashEventMessage,
128
266
  parseSettingsString: parseSettingsString,
129
267
  generateMappedEventLookup: generateMappedEventLookup,
268
+ generateMappedEventAttributeLookup:
269
+ generateMappedEventAttributeLookup,
130
270
  };
131
271
  attachLauncher(accountId, launcherOptions);
132
272
  return;
@@ -179,13 +319,18 @@ var RoktKit = (function (exports) {
179
319
 
180
320
  function returnLocalSessionAttributes() {
181
321
  if (
182
- isEmpty(self.placementEventMappingLookup) ||
183
322
  !window.mParticle.Rokt ||
184
323
  typeof window.mParticle.Rokt.getLocalSessionAttributes !==
185
324
  'function'
186
325
  ) {
187
326
  return {};
188
327
  }
328
+ if (
329
+ isEmpty(self.placementEventMappingLookup) &&
330
+ isEmpty(self.placementEventAttributeMappingLookup)
331
+ ) {
332
+ return {};
333
+ }
189
334
  return window.mParticle.Rokt.getLocalSessionAttributes();
190
335
  }
191
336
 
@@ -304,7 +449,7 @@ var RoktKit = (function (exports) {
304
449
  console.error('Rokt Kit: Not initialized');
305
450
  return Promise.reject(new Error('Rokt Kit: Not initialized'));
306
451
  }
307
- if (!extensionName || typeof extensionName !== 'string') {
452
+ if (!extensionName || !isString(extensionName)) {
308
453
  return Promise.reject(
309
454
  new Error('Rokt Kit: Invalid extension name')
310
455
  );
@@ -342,12 +487,19 @@ var RoktKit = (function (exports) {
342
487
  }
343
488
 
344
489
  if (
345
- isEmpty(self.placementEventMappingLookup) ||
346
490
  typeof window.mParticle.Rokt.setLocalSessionAttribute !== 'function'
347
491
  ) {
348
492
  return;
349
493
  }
350
494
 
495
+ if (!isEmpty(self.placementEventAttributeMappingLookup)) {
496
+ applyPlacementEventAttributeMapping(event);
497
+ }
498
+
499
+ if (isEmpty(self.placementEventMappingLookup)) {
500
+ return;
501
+ }
502
+
351
503
  var hashedEvent = hashEventMessage(
352
504
  event.EventDataType,
353
505
  event.EventCategory,
@@ -510,7 +662,7 @@ var RoktKit = (function (exports) {
510
662
 
511
663
  function generateIntegrationName(customIntegrationName) {
512
664
  var coreSdkVersion = window.mParticle.getVersion();
513
- var kitVersion = "1.14.0";
665
+ var kitVersion = "1.16.0";
514
666
  var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
515
667
 
516
668
  if (customIntegrationName) {
@@ -616,6 +768,10 @@ var RoktKit = (function (exports) {
616
768
  return value == null || !(Object.keys(value) || value).length;
617
769
  }
618
770
 
771
+ function isString(value) {
772
+ return typeof value === 'string';
773
+ }
774
+
619
775
  if (window && window.mParticle && window.mParticle.addForwarder) {
620
776
  window.mParticle.addForwarder({
621
777
  name: name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-rokt-kit",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "mParticle integration kit for Rokt",
5
5
  "main": "dist/Rokt-Kit.common.js",
6
6
  "files": [