@mparticle/web-rokt-kit 1.1.0 → 1.2.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.
@@ -28,6 +28,7 @@ var constructor = function () {
28
28
  self.name = name;
29
29
  self.moduleId = moduleId;
30
30
  self.isInitialized = false;
31
+
31
32
  self.launcher = null;
32
33
  self.filters = {};
33
34
  self.filteredUser = {};
@@ -35,17 +36,17 @@ var constructor = function () {
35
36
 
36
37
  function initForwarder(
37
38
  settings,
38
- service,
39
+ _service,
39
40
  testMode,
40
- trackerId,
41
+ _trackerId,
41
42
  filteredUserAttributes
42
43
  ) {
43
44
  var accountId = settings.accountId;
44
- var sandboxMode = window.mParticle.getEnvironment() === 'development';
45
45
  self.userAttributes = filteredUserAttributes;
46
+ self.onboardingExpProvider = settings.onboardingExpProvider;
46
47
 
47
48
  if (testMode) {
48
- attachLauncher(accountId, sandboxMode);
49
+ attachLauncher(accountId);
49
50
  return;
50
51
  }
51
52
 
@@ -66,7 +67,7 @@ var constructor = function () {
66
67
  typeof window.Rokt.createLauncher === 'function' &&
67
68
  window.Rokt.currentLauncher === undefined
68
69
  ) {
69
- attachLauncher(accountId, sandboxMode);
70
+ attachLauncher(accountId);
70
71
  } else {
71
72
  console.error(
72
73
  'Rokt object is not available after script load.'
@@ -120,9 +121,18 @@ var constructor = function () {
120
121
 
121
122
  self.userAttributes = filteredAttributes;
122
123
 
123
- var selectPlacementsAttributes = mergeObjects(filteredAttributes, {
124
- mpid: mpid,
125
- });
124
+ var optimizelyAttributes =
125
+ self.onboardingExpProvider === 'Optimizely'
126
+ ? fetchOptimizely()
127
+ : {};
128
+
129
+ var selectPlacementsAttributes = mergeObjects(
130
+ filteredAttributes,
131
+ optimizelyAttributes,
132
+ {
133
+ mpid: mpid,
134
+ }
135
+ );
126
136
 
127
137
  var selectPlacementsOptions = mergeObjects(options, {
128
138
  attributes: selectPlacementsAttributes,
@@ -144,16 +154,15 @@ var constructor = function () {
144
154
  delete self.userAttributes[key];
145
155
  }
146
156
 
147
- function attachLauncher(accountId, sandboxMode) {
157
+ function attachLauncher(accountId) {
148
158
  window.Rokt.createLauncher({
149
159
  accountId: accountId,
150
- sandbox: sandboxMode,
151
160
  integrationName:
152
161
  'mParticle_' +
153
162
  'wsdkv_' +
154
163
  window.mParticle.getVersion() +
155
164
  '_kitv_' +
156
- "1.1.0",
165
+ "1.2.1",
157
166
  })
158
167
  .then(function (launcher) {
159
168
  // Assign the launcher to a global variable for later access
@@ -191,6 +200,46 @@ var constructor = function () {
191
200
  this.selectPlacements = selectPlacements;
192
201
 
193
202
  // mParticle Kit Callback Methods
203
+ function fetchOptimizely() {
204
+ var forwarders = window.mParticle
205
+ ._getActiveForwarders()
206
+ .filter(function (forwarder) {
207
+ return forwarder.name === 'Optimizely';
208
+ });
209
+
210
+ try {
211
+ if (forwarders.length > 0 && window.optimizely) {
212
+ // Get the state object
213
+ var optimizelyState = window.optimizely.get('state');
214
+ if (
215
+ !optimizelyState ||
216
+ !optimizelyState.getActiveExperimentIds
217
+ ) {
218
+ return {};
219
+ }
220
+ // Get active experiment IDs
221
+ var activeExperimentIds =
222
+ optimizelyState.getActiveExperimentIds();
223
+ // Get variations for each active experiment
224
+ var activeExperiments = activeExperimentIds.reduce(function (
225
+ acc,
226
+ expId
227
+ ) {
228
+ acc[
229
+ 'rokt.custom.optimizely.experiment.' +
230
+ expId +
231
+ '.variationId'
232
+ ] = optimizelyState.getVariationMap()[expId].id;
233
+ return acc;
234
+ },
235
+ {});
236
+ return activeExperiments;
237
+ }
238
+ } catch (error) {
239
+ console.error('Error fetching Optimizely attributes:', error);
240
+ }
241
+ return {};
242
+ }
194
243
  this.init = initForwarder;
195
244
  this.setUserAttribute = setUserAttribute;
196
245
  this.onUserIdentified = onUserIdentified;
@@ -27,6 +27,7 @@ var RoktKit = (function (exports) {
27
27
  self.name = name;
28
28
  self.moduleId = moduleId;
29
29
  self.isInitialized = false;
30
+
30
31
  self.launcher = null;
31
32
  self.filters = {};
32
33
  self.filteredUser = {};
@@ -34,17 +35,17 @@ var RoktKit = (function (exports) {
34
35
 
35
36
  function initForwarder(
36
37
  settings,
37
- service,
38
+ _service,
38
39
  testMode,
39
- trackerId,
40
+ _trackerId,
40
41
  filteredUserAttributes
41
42
  ) {
42
43
  var accountId = settings.accountId;
43
- var sandboxMode = window.mParticle.getEnvironment() === 'development';
44
44
  self.userAttributes = filteredUserAttributes;
45
+ self.onboardingExpProvider = settings.onboardingExpProvider;
45
46
 
46
47
  if (testMode) {
47
- attachLauncher(accountId, sandboxMode);
48
+ attachLauncher(accountId);
48
49
  return;
49
50
  }
50
51
 
@@ -65,7 +66,7 @@ var RoktKit = (function (exports) {
65
66
  typeof window.Rokt.createLauncher === 'function' &&
66
67
  window.Rokt.currentLauncher === undefined
67
68
  ) {
68
- attachLauncher(accountId, sandboxMode);
69
+ attachLauncher(accountId);
69
70
  } else {
70
71
  console.error(
71
72
  'Rokt object is not available after script load.'
@@ -119,9 +120,18 @@ var RoktKit = (function (exports) {
119
120
 
120
121
  self.userAttributes = filteredAttributes;
121
122
 
122
- var selectPlacementsAttributes = mergeObjects(filteredAttributes, {
123
- mpid: mpid,
124
- });
123
+ var optimizelyAttributes =
124
+ self.onboardingExpProvider === 'Optimizely'
125
+ ? fetchOptimizely()
126
+ : {};
127
+
128
+ var selectPlacementsAttributes = mergeObjects(
129
+ filteredAttributes,
130
+ optimizelyAttributes,
131
+ {
132
+ mpid: mpid,
133
+ }
134
+ );
125
135
 
126
136
  var selectPlacementsOptions = mergeObjects(options, {
127
137
  attributes: selectPlacementsAttributes,
@@ -143,16 +153,15 @@ var RoktKit = (function (exports) {
143
153
  delete self.userAttributes[key];
144
154
  }
145
155
 
146
- function attachLauncher(accountId, sandboxMode) {
156
+ function attachLauncher(accountId) {
147
157
  window.Rokt.createLauncher({
148
158
  accountId: accountId,
149
- sandbox: sandboxMode,
150
159
  integrationName:
151
160
  'mParticle_' +
152
161
  'wsdkv_' +
153
162
  window.mParticle.getVersion() +
154
163
  '_kitv_' +
155
- "1.1.0",
164
+ "1.2.1",
156
165
  })
157
166
  .then(function (launcher) {
158
167
  // Assign the launcher to a global variable for later access
@@ -190,6 +199,46 @@ var RoktKit = (function (exports) {
190
199
  this.selectPlacements = selectPlacements;
191
200
 
192
201
  // mParticle Kit Callback Methods
202
+ function fetchOptimizely() {
203
+ var forwarders = window.mParticle
204
+ ._getActiveForwarders()
205
+ .filter(function (forwarder) {
206
+ return forwarder.name === 'Optimizely';
207
+ });
208
+
209
+ try {
210
+ if (forwarders.length > 0 && window.optimizely) {
211
+ // Get the state object
212
+ var optimizelyState = window.optimizely.get('state');
213
+ if (
214
+ !optimizelyState ||
215
+ !optimizelyState.getActiveExperimentIds
216
+ ) {
217
+ return {};
218
+ }
219
+ // Get active experiment IDs
220
+ var activeExperimentIds =
221
+ optimizelyState.getActiveExperimentIds();
222
+ // Get variations for each active experiment
223
+ var activeExperiments = activeExperimentIds.reduce(function (
224
+ acc,
225
+ expId
226
+ ) {
227
+ acc[
228
+ 'rokt.custom.optimizely.experiment.' +
229
+ expId +
230
+ '.variationId'
231
+ ] = optimizelyState.getVariationMap()[expId].id;
232
+ return acc;
233
+ },
234
+ {});
235
+ return activeExperiments;
236
+ }
237
+ } catch (error) {
238
+ console.error('Error fetching Optimizely attributes:', error);
239
+ }
240
+ return {};
241
+ }
193
242
  this.init = initForwarder;
194
243
  this.setUserAttribute = setUserAttribute;
195
244
  this.onUserIdentified = onUserIdentified;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-rokt-kit",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "mParticle integration kit for Rokt",
5
5
  "main": "dist/Rokt-Kit.common.js",
6
6
  "files": [