@mparticle/web-rokt-kit 1.2.1 → 1.3.1

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.
@@ -34,19 +34,49 @@ var constructor = function () {
34
34
  self.filteredUser = {};
35
35
  self.userAttributes = {};
36
36
 
37
+ /**
38
+ * Passes attributes to the Rokt Web SDK for client-side hashing
39
+ * @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes
40
+ * @param {Object} attributes - The attributes to be hashed
41
+ * @returns {Promise<Object|null>} A Promise resolving to the
42
+ * hashed attributes from the launcher, or `null` if the kit is not initialized
43
+ */
44
+ function hashAttributes(attributes) {
45
+ if (!isInitialized()) {
46
+ console.error('Rokt Kit: Not initialized');
47
+ return null;
48
+ }
49
+ return self.launcher.hashAttributes(attributes);
50
+ }
51
+
37
52
  function initForwarder(
38
53
  settings,
39
54
  _service,
40
55
  testMode,
41
56
  _trackerId,
42
- filteredUserAttributes
57
+ filteredUserAttributes,
58
+ filteredUserIdentities,
59
+ appVersion,
60
+ appName,
61
+ customFlags
43
62
  ) {
44
63
  var accountId = settings.accountId;
45
64
  self.userAttributes = filteredUserAttributes;
46
65
  self.onboardingExpProvider = settings.onboardingExpProvider;
47
66
 
67
+ var integrationName =
68
+ customFlags && customFlags['Rokt.integrationName'];
69
+ var noFunctional = customFlags && customFlags['Rokt.noFunctional'];
70
+ var noTargeting = customFlags && customFlags['Rokt.noTargeting'];
71
+
72
+ var launcherOptions = {
73
+ integrationName: generateIntegrationName(integrationName),
74
+ noFunctional: noFunctional,
75
+ noTargeting: noTargeting,
76
+ };
77
+
48
78
  if (testMode) {
49
- attachLauncher(accountId);
79
+ attachLauncher(accountId, launcherOptions);
50
80
  return;
51
81
  }
52
82
 
@@ -67,7 +97,7 @@ var constructor = function () {
67
97
  typeof window.Rokt.createLauncher === 'function' &&
68
98
  window.Rokt.currentLauncher === undefined
69
99
  ) {
70
- attachLauncher(accountId);
100
+ attachLauncher(accountId, launcherOptions);
71
101
  } else {
72
102
  console.error(
73
103
  'Rokt object is not available after script load.'
@@ -85,12 +115,15 @@ var constructor = function () {
85
115
  }
86
116
  }
87
117
 
118
+ /**
119
+ * Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options
120
+ * @see https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
121
+ * @param {Object} options - The options object for selecting placements containing:
122
+ * - identifier {string}: The placement identifier
123
+ * - attributes {Object}: Optional attributes to merge with existing attributes
124
+ * @returns {Promise<void>} A Promise resolving to the Rokt launcher's selectPlacements method with processed attributes
125
+ */
88
126
  function selectPlacements(options) {
89
- // https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
90
- // options should contain:
91
- // - identifier
92
- // - attributes
93
-
94
127
  var attributes = (options && options.attributes) || {};
95
128
  var placementAttributes = mergeObjects(self.userAttributes, attributes);
96
129
 
@@ -154,16 +187,13 @@ var constructor = function () {
154
187
  delete self.userAttributes[key];
155
188
  }
156
189
 
157
- function attachLauncher(accountId) {
158
- window.Rokt.createLauncher({
159
- accountId: accountId,
160
- integrationName:
161
- 'mParticle_' +
162
- 'wsdkv_' +
163
- window.mParticle.getVersion() +
164
- '_kitv_' +
165
- "1.2.1",
166
- })
190
+ function attachLauncher(accountId, launcherOptions) {
191
+ var options = mergeObjects(
192
+ { accountId: accountId },
193
+ launcherOptions || {}
194
+ );
195
+
196
+ window.Rokt.createLauncher(options)
167
197
  .then(function (launcher) {
168
198
  // Assign the launcher to a global variable for later access
169
199
  window.Rokt.currentLauncher = launcher;
@@ -196,9 +226,6 @@ var constructor = function () {
196
226
  });
197
227
  }
198
228
 
199
- // Called by the mParticle Rokt Manager
200
- this.selectPlacements = selectPlacements;
201
-
202
229
  // mParticle Kit Callback Methods
203
230
  function fetchOptimizely() {
204
231
  var forwarders = window.mParticle
@@ -240,12 +267,40 @@ var constructor = function () {
240
267
  }
241
268
  return {};
242
269
  }
270
+
271
+ // Called by the mParticle Rokt Manager
272
+ this.selectPlacements = selectPlacements;
273
+ this.hashAttributes = hashAttributes;
274
+
275
+ // Kit Callback Methods
243
276
  this.init = initForwarder;
244
277
  this.setUserAttribute = setUserAttribute;
245
278
  this.onUserIdentified = onUserIdentified;
246
279
  this.removeUserAttribute = removeUserAttribute;
280
+
281
+ /**
282
+ * Checks if the kit is properly initialized and ready for use.
283
+ * Both conditions must be true:
284
+ * 1. self.isInitialized - Set after successful initialization of the kit
285
+ * 2. self.launcher - The Rokt launcher instance must be available
286
+ * @returns {boolean} Whether the kit is fully initialized
287
+ */
288
+ function isInitialized() {
289
+ return !!(self.isInitialized && self.launcher);
290
+ }
247
291
  };
248
292
 
293
+ function generateIntegrationName(customIntegrationName) {
294
+ var coreSdkVersion = window.mParticle.getVersion();
295
+ var kitVersion = "1.3.1";
296
+ var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
297
+
298
+ if (customIntegrationName) {
299
+ name += '_' + customIntegrationName;
300
+ }
301
+ return name;
302
+ }
303
+
249
304
  function getId() {
250
305
  return moduleId;
251
306
  }
@@ -33,19 +33,49 @@ var RoktKit = (function (exports) {
33
33
  self.filteredUser = {};
34
34
  self.userAttributes = {};
35
35
 
36
+ /**
37
+ * Passes attributes to the Rokt Web SDK for client-side hashing
38
+ * @see https://docs.rokt.com/developers/integration-guides/web/library/integration-launcher#hash-attributes
39
+ * @param {Object} attributes - The attributes to be hashed
40
+ * @returns {Promise<Object|null>} A Promise resolving to the
41
+ * hashed attributes from the launcher, or `null` if the kit is not initialized
42
+ */
43
+ function hashAttributes(attributes) {
44
+ if (!isInitialized()) {
45
+ console.error('Rokt Kit: Not initialized');
46
+ return null;
47
+ }
48
+ return self.launcher.hashAttributes(attributes);
49
+ }
50
+
36
51
  function initForwarder(
37
52
  settings,
38
53
  _service,
39
54
  testMode,
40
55
  _trackerId,
41
- filteredUserAttributes
56
+ filteredUserAttributes,
57
+ filteredUserIdentities,
58
+ appVersion,
59
+ appName,
60
+ customFlags
42
61
  ) {
43
62
  var accountId = settings.accountId;
44
63
  self.userAttributes = filteredUserAttributes;
45
64
  self.onboardingExpProvider = settings.onboardingExpProvider;
46
65
 
66
+ var integrationName =
67
+ customFlags && customFlags['Rokt.integrationName'];
68
+ var noFunctional = customFlags && customFlags['Rokt.noFunctional'];
69
+ var noTargeting = customFlags && customFlags['Rokt.noTargeting'];
70
+
71
+ var launcherOptions = {
72
+ integrationName: generateIntegrationName(integrationName),
73
+ noFunctional: noFunctional,
74
+ noTargeting: noTargeting,
75
+ };
76
+
47
77
  if (testMode) {
48
- attachLauncher(accountId);
78
+ attachLauncher(accountId, launcherOptions);
49
79
  return;
50
80
  }
51
81
 
@@ -66,7 +96,7 @@ var RoktKit = (function (exports) {
66
96
  typeof window.Rokt.createLauncher === 'function' &&
67
97
  window.Rokt.currentLauncher === undefined
68
98
  ) {
69
- attachLauncher(accountId);
99
+ attachLauncher(accountId, launcherOptions);
70
100
  } else {
71
101
  console.error(
72
102
  'Rokt object is not available after script load.'
@@ -84,12 +114,15 @@ var RoktKit = (function (exports) {
84
114
  }
85
115
  }
86
116
 
117
+ /**
118
+ * Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options
119
+ * @see https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
120
+ * @param {Object} options - The options object for selecting placements containing:
121
+ * - identifier {string}: The placement identifier
122
+ * - attributes {Object}: Optional attributes to merge with existing attributes
123
+ * @returns {Promise<void>} A Promise resolving to the Rokt launcher's selectPlacements method with processed attributes
124
+ */
87
125
  function selectPlacements(options) {
88
- // https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
89
- // options should contain:
90
- // - identifier
91
- // - attributes
92
-
93
126
  var attributes = (options && options.attributes) || {};
94
127
  var placementAttributes = mergeObjects(self.userAttributes, attributes);
95
128
 
@@ -153,16 +186,13 @@ var RoktKit = (function (exports) {
153
186
  delete self.userAttributes[key];
154
187
  }
155
188
 
156
- function attachLauncher(accountId) {
157
- window.Rokt.createLauncher({
158
- accountId: accountId,
159
- integrationName:
160
- 'mParticle_' +
161
- 'wsdkv_' +
162
- window.mParticle.getVersion() +
163
- '_kitv_' +
164
- "1.2.1",
165
- })
189
+ function attachLauncher(accountId, launcherOptions) {
190
+ var options = mergeObjects(
191
+ { accountId: accountId },
192
+ launcherOptions || {}
193
+ );
194
+
195
+ window.Rokt.createLauncher(options)
166
196
  .then(function (launcher) {
167
197
  // Assign the launcher to a global variable for later access
168
198
  window.Rokt.currentLauncher = launcher;
@@ -195,9 +225,6 @@ var RoktKit = (function (exports) {
195
225
  });
196
226
  }
197
227
 
198
- // Called by the mParticle Rokt Manager
199
- this.selectPlacements = selectPlacements;
200
-
201
228
  // mParticle Kit Callback Methods
202
229
  function fetchOptimizely() {
203
230
  var forwarders = window.mParticle
@@ -239,12 +266,40 @@ var RoktKit = (function (exports) {
239
266
  }
240
267
  return {};
241
268
  }
269
+
270
+ // Called by the mParticle Rokt Manager
271
+ this.selectPlacements = selectPlacements;
272
+ this.hashAttributes = hashAttributes;
273
+
274
+ // Kit Callback Methods
242
275
  this.init = initForwarder;
243
276
  this.setUserAttribute = setUserAttribute;
244
277
  this.onUserIdentified = onUserIdentified;
245
278
  this.removeUserAttribute = removeUserAttribute;
279
+
280
+ /**
281
+ * Checks if the kit is properly initialized and ready for use.
282
+ * Both conditions must be true:
283
+ * 1. self.isInitialized - Set after successful initialization of the kit
284
+ * 2. self.launcher - The Rokt launcher instance must be available
285
+ * @returns {boolean} Whether the kit is fully initialized
286
+ */
287
+ function isInitialized() {
288
+ return !!(self.isInitialized && self.launcher);
289
+ }
246
290
  };
247
291
 
292
+ function generateIntegrationName(customIntegrationName) {
293
+ var coreSdkVersion = window.mParticle.getVersion();
294
+ var kitVersion = "1.3.1";
295
+ var name = 'mParticle_' + 'wsdkv_' + coreSdkVersion + '_kitv_' + kitVersion;
296
+
297
+ if (customIntegrationName) {
298
+ name += '_' + customIntegrationName;
299
+ }
300
+ return name;
301
+ }
302
+
248
303
  function getId() {
249
304
  return moduleId;
250
305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-rokt-kit",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "mParticle integration kit for Rokt",
5
5
  "main": "dist/Rokt-Kit.common.js",
6
6
  "files": [
@@ -14,7 +14,7 @@
14
14
  "lint": "eslint src/ test/src/",
15
15
  "lint:fix": "eslint src/ test/src/ --fix",
16
16
  "watch": "rollup --config rollup.config.js -w",
17
- "watch:test": "rollup --config rollup.test.config.js -w",
17
+ "watch:tests": "rollup --config rollup.test.config.js -w",
18
18
  "test": "npm run build && npm run build:test && karma start test/karma.config.js",
19
19
  "test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js"
20
20
  },