@mparticle/web-rokt-kit 1.2.0 → 1.3.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 +46 -16
- package/dist/Rokt-Kit.iife.js +46 -16
- package/package.json +2 -2
package/dist/Rokt-Kit.common.js
CHANGED
|
@@ -34,20 +34,34 @@ 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
57
|
filteredUserAttributes
|
|
43
58
|
) {
|
|
44
59
|
var accountId = settings.accountId;
|
|
45
|
-
var sandboxMode = window.mParticle.getEnvironment() === 'development';
|
|
46
60
|
self.userAttributes = filteredUserAttributes;
|
|
47
61
|
self.onboardingExpProvider = settings.onboardingExpProvider;
|
|
48
62
|
|
|
49
63
|
if (testMode) {
|
|
50
|
-
attachLauncher(accountId
|
|
64
|
+
attachLauncher(accountId);
|
|
51
65
|
return;
|
|
52
66
|
}
|
|
53
67
|
|
|
@@ -68,7 +82,7 @@ var constructor = function () {
|
|
|
68
82
|
typeof window.Rokt.createLauncher === 'function' &&
|
|
69
83
|
window.Rokt.currentLauncher === undefined
|
|
70
84
|
) {
|
|
71
|
-
attachLauncher(accountId
|
|
85
|
+
attachLauncher(accountId);
|
|
72
86
|
} else {
|
|
73
87
|
console.error(
|
|
74
88
|
'Rokt object is not available after script load.'
|
|
@@ -86,12 +100,15 @@ var constructor = function () {
|
|
|
86
100
|
}
|
|
87
101
|
}
|
|
88
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options
|
|
105
|
+
* @see https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
|
|
106
|
+
* @param {Object} options - The options object for selecting placements containing:
|
|
107
|
+
* - identifier {string}: The placement identifier
|
|
108
|
+
* - attributes {Object}: Optional attributes to merge with existing attributes
|
|
109
|
+
* @returns {Promise<void>} A Promise resolving to the Rokt launcher's selectPlacements method with processed attributes
|
|
110
|
+
*/
|
|
89
111
|
function selectPlacements(options) {
|
|
90
|
-
// https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
|
|
91
|
-
// options should contain:
|
|
92
|
-
// - identifier
|
|
93
|
-
// - attributes
|
|
94
|
-
|
|
95
112
|
var attributes = (options && options.attributes) || {};
|
|
96
113
|
var placementAttributes = mergeObjects(self.userAttributes, attributes);
|
|
97
114
|
|
|
@@ -155,16 +172,15 @@ var constructor = function () {
|
|
|
155
172
|
delete self.userAttributes[key];
|
|
156
173
|
}
|
|
157
174
|
|
|
158
|
-
function attachLauncher(accountId
|
|
175
|
+
function attachLauncher(accountId) {
|
|
159
176
|
window.Rokt.createLauncher({
|
|
160
177
|
accountId: accountId,
|
|
161
|
-
sandbox: sandboxMode,
|
|
162
178
|
integrationName:
|
|
163
179
|
'mParticle_' +
|
|
164
180
|
'wsdkv_' +
|
|
165
181
|
window.mParticle.getVersion() +
|
|
166
182
|
'_kitv_' +
|
|
167
|
-
"1.
|
|
183
|
+
"1.3.0",
|
|
168
184
|
})
|
|
169
185
|
.then(function (launcher) {
|
|
170
186
|
// Assign the launcher to a global variable for later access
|
|
@@ -198,9 +214,6 @@ var constructor = function () {
|
|
|
198
214
|
});
|
|
199
215
|
}
|
|
200
216
|
|
|
201
|
-
// Called by the mParticle Rokt Manager
|
|
202
|
-
this.selectPlacements = selectPlacements;
|
|
203
|
-
|
|
204
217
|
// mParticle Kit Callback Methods
|
|
205
218
|
function fetchOptimizely() {
|
|
206
219
|
var forwarders = window.mParticle
|
|
@@ -242,10 +255,27 @@ var constructor = function () {
|
|
|
242
255
|
}
|
|
243
256
|
return {};
|
|
244
257
|
}
|
|
258
|
+
|
|
259
|
+
// Called by the mParticle Rokt Manager
|
|
260
|
+
this.selectPlacements = selectPlacements;
|
|
261
|
+
this.hashAttributes = hashAttributes;
|
|
262
|
+
|
|
263
|
+
// Kit Callback Methods
|
|
245
264
|
this.init = initForwarder;
|
|
246
265
|
this.setUserAttribute = setUserAttribute;
|
|
247
266
|
this.onUserIdentified = onUserIdentified;
|
|
248
267
|
this.removeUserAttribute = removeUserAttribute;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Checks if the kit is properly initialized and ready for use.
|
|
271
|
+
* Both conditions must be true:
|
|
272
|
+
* 1. self.isInitialized - Set after successful initialization of the kit
|
|
273
|
+
* 2. self.launcher - The Rokt launcher instance must be available
|
|
274
|
+
* @returns {boolean} Whether the kit is fully initialized
|
|
275
|
+
*/
|
|
276
|
+
function isInitialized() {
|
|
277
|
+
return !!(self.isInitialized && self.launcher);
|
|
278
|
+
}
|
|
249
279
|
};
|
|
250
280
|
|
|
251
281
|
function getId() {
|
package/dist/Rokt-Kit.iife.js
CHANGED
|
@@ -33,20 +33,34 @@ 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
56
|
filteredUserAttributes
|
|
42
57
|
) {
|
|
43
58
|
var accountId = settings.accountId;
|
|
44
|
-
var sandboxMode = window.mParticle.getEnvironment() === 'development';
|
|
45
59
|
self.userAttributes = filteredUserAttributes;
|
|
46
60
|
self.onboardingExpProvider = settings.onboardingExpProvider;
|
|
47
61
|
|
|
48
62
|
if (testMode) {
|
|
49
|
-
attachLauncher(accountId
|
|
63
|
+
attachLauncher(accountId);
|
|
50
64
|
return;
|
|
51
65
|
}
|
|
52
66
|
|
|
@@ -67,7 +81,7 @@ var RoktKit = (function (exports) {
|
|
|
67
81
|
typeof window.Rokt.createLauncher === 'function' &&
|
|
68
82
|
window.Rokt.currentLauncher === undefined
|
|
69
83
|
) {
|
|
70
|
-
attachLauncher(accountId
|
|
84
|
+
attachLauncher(accountId);
|
|
71
85
|
} else {
|
|
72
86
|
console.error(
|
|
73
87
|
'Rokt object is not available after script load.'
|
|
@@ -85,12 +99,15 @@ var RoktKit = (function (exports) {
|
|
|
85
99
|
}
|
|
86
100
|
}
|
|
87
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Selects placements for Rokt Web SDK with merged attributes, filters, and experimentation options
|
|
104
|
+
* @see https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options/
|
|
105
|
+
* @param {Object} options - The options object for selecting placements containing:
|
|
106
|
+
* - identifier {string}: The placement identifier
|
|
107
|
+
* - attributes {Object}: Optional attributes to merge with existing attributes
|
|
108
|
+
* @returns {Promise<void>} A Promise resolving to the Rokt launcher's selectPlacements method with processed attributes
|
|
109
|
+
*/
|
|
88
110
|
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
111
|
var attributes = (options && options.attributes) || {};
|
|
95
112
|
var placementAttributes = mergeObjects(self.userAttributes, attributes);
|
|
96
113
|
|
|
@@ -154,16 +171,15 @@ var RoktKit = (function (exports) {
|
|
|
154
171
|
delete self.userAttributes[key];
|
|
155
172
|
}
|
|
156
173
|
|
|
157
|
-
function attachLauncher(accountId
|
|
174
|
+
function attachLauncher(accountId) {
|
|
158
175
|
window.Rokt.createLauncher({
|
|
159
176
|
accountId: accountId,
|
|
160
|
-
sandbox: sandboxMode,
|
|
161
177
|
integrationName:
|
|
162
178
|
'mParticle_' +
|
|
163
179
|
'wsdkv_' +
|
|
164
180
|
window.mParticle.getVersion() +
|
|
165
181
|
'_kitv_' +
|
|
166
|
-
"1.
|
|
182
|
+
"1.3.0",
|
|
167
183
|
})
|
|
168
184
|
.then(function (launcher) {
|
|
169
185
|
// Assign the launcher to a global variable for later access
|
|
@@ -197,9 +213,6 @@ var RoktKit = (function (exports) {
|
|
|
197
213
|
});
|
|
198
214
|
}
|
|
199
215
|
|
|
200
|
-
// Called by the mParticle Rokt Manager
|
|
201
|
-
this.selectPlacements = selectPlacements;
|
|
202
|
-
|
|
203
216
|
// mParticle Kit Callback Methods
|
|
204
217
|
function fetchOptimizely() {
|
|
205
218
|
var forwarders = window.mParticle
|
|
@@ -241,10 +254,27 @@ var RoktKit = (function (exports) {
|
|
|
241
254
|
}
|
|
242
255
|
return {};
|
|
243
256
|
}
|
|
257
|
+
|
|
258
|
+
// Called by the mParticle Rokt Manager
|
|
259
|
+
this.selectPlacements = selectPlacements;
|
|
260
|
+
this.hashAttributes = hashAttributes;
|
|
261
|
+
|
|
262
|
+
// Kit Callback Methods
|
|
244
263
|
this.init = initForwarder;
|
|
245
264
|
this.setUserAttribute = setUserAttribute;
|
|
246
265
|
this.onUserIdentified = onUserIdentified;
|
|
247
266
|
this.removeUserAttribute = removeUserAttribute;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Checks if the kit is properly initialized and ready for use.
|
|
270
|
+
* Both conditions must be true:
|
|
271
|
+
* 1. self.isInitialized - Set after successful initialization of the kit
|
|
272
|
+
* 2. self.launcher - The Rokt launcher instance must be available
|
|
273
|
+
* @returns {boolean} Whether the kit is fully initialized
|
|
274
|
+
*/
|
|
275
|
+
function isInitialized() {
|
|
276
|
+
return !!(self.isInitialized && self.launcher);
|
|
277
|
+
}
|
|
248
278
|
};
|
|
249
279
|
|
|
250
280
|
function getId() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-rokt-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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:
|
|
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
|
},
|