@constructor-io/constructorio-client-javascript 2.69.2 → 2.71.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/lib/constructorio.js +3 -0
- package/lib/modules/quizzes.js +6 -1
- package/lib/modules/search.js +5 -5
- package/lib/modules/tracker.js +57 -0
- package/lib/types/index.d.ts +5 -2
- package/lib/types/quizzes.d.ts +5 -1
- package/lib/types/tracker.d.ts +7 -0
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/lib/constructorio.js
CHANGED
|
@@ -43,6 +43,7 @@ var ConstructorIO = /*#__PURE__*/function () {
|
|
|
43
43
|
* @param {string} [parameters.serviceUrl='https://ac.cnstrc.com'] - API URL endpoint
|
|
44
44
|
* @param {string} [parameters.quizzesServiceUrl='https://quizzes.cnstrc.com'] - Quizzes API URL endpoint
|
|
45
45
|
* @param {string} [parameters.agentServiceUrl='https://agent.cnstrc.com'] - AI Shopping Agent API URL endpoint
|
|
46
|
+
* @param {string} [parameters.mediaServiceUrl='https://media-cnstrc.com'] - Media API URL endpoint
|
|
46
47
|
* @param {string} [parameters.assistantServiceUrl='https://assistant.cnstrc.com'] - AI Shopping Assistant API URL endpoint @deprecated This parameter is deprecated and will be removed in a future version. Use parameters.agentServiceUrl instead.
|
|
47
48
|
* @param {array} [parameters.segments] - User segments
|
|
48
49
|
* @param {object} [parameters.testCells] - User test cells
|
|
@@ -78,6 +79,7 @@ var ConstructorIO = /*#__PURE__*/function () {
|
|
|
78
79
|
quizzesServiceUrl = options.quizzesServiceUrl,
|
|
79
80
|
agentServiceUrl = options.agentServiceUrl,
|
|
80
81
|
assistantServiceUrl = options.assistantServiceUrl,
|
|
82
|
+
mediaServiceUrl = options.mediaServiceUrl,
|
|
81
83
|
segments = options.segments,
|
|
82
84
|
testCells = options.testCells,
|
|
83
85
|
clientId = options.clientId,
|
|
@@ -122,6 +124,7 @@ var ConstructorIO = /*#__PURE__*/function () {
|
|
|
122
124
|
quizzesServiceUrl: quizzesServiceUrl && quizzesServiceUrl.replace(/\/$/, '') || 'https://quizzes.cnstrc.com',
|
|
123
125
|
agentServiceUrl: agentServiceUrl && agentServiceUrl.replace(/\/$/, '') || 'https://agent.cnstrc.com',
|
|
124
126
|
assistantServiceUrl: assistantServiceUrl && assistantServiceUrl.replace(/\/$/, '') || 'https://assistant.cnstrc.com',
|
|
127
|
+
mediaServiceUrl: mediaServiceUrl && mediaServiceUrl.replace(/\/$/, '') || 'https://media-cnstrc.com',
|
|
125
128
|
sessionId: sessionId || session_id,
|
|
126
129
|
clientId: clientId || client_id,
|
|
127
130
|
userId: userId,
|
package/lib/modules/quizzes.js
CHANGED
|
@@ -54,7 +54,8 @@ function createQuizUrl(quizId, parameters, options, path) {
|
|
|
54
54
|
resultsPerPage = parameters.resultsPerPage,
|
|
55
55
|
filters = parameters.filters,
|
|
56
56
|
fmtOptions = parameters.fmtOptions,
|
|
57
|
-
hiddenFields = parameters.hiddenFields
|
|
57
|
+
hiddenFields = parameters.hiddenFields,
|
|
58
|
+
skipTracking = parameters.skipTracking;
|
|
58
59
|
|
|
59
60
|
// Pull section from parameters
|
|
60
61
|
if (section) {
|
|
@@ -104,6 +105,9 @@ function createQuizUrl(quizId, parameters, options, path) {
|
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
107
|
}
|
|
108
|
+
if (skipTracking) {
|
|
109
|
+
queryParams.skip_tracking = skipTracking;
|
|
110
|
+
}
|
|
107
111
|
}
|
|
108
112
|
queryParams._dt = Date.now();
|
|
109
113
|
queryParams = helpers.cleanParams(queryParams);
|
|
@@ -136,6 +140,7 @@ var Quizzes = /*#__PURE__*/function () {
|
|
|
136
140
|
* @param {array} [parameters.answers] - An array of answers in the format [[1,2], [1], ["true"], ["seen"], [""]]. Based on the question type, answers should either be an integer, "true"/"false", "seen" or an empty string ("") if skipped
|
|
137
141
|
* @param {string} [parameters.quizVersionId] - Version identifier for the quiz. Version ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.com/reference/configuration-quizzes
|
|
138
142
|
* @param {string} [parameters.quizSessionId] - Session identifier for the quiz. Session ID will be returned with the first request and it should be passed with subsequent requests. More information can be found: https://docs.constructor.com/reference/configuration-quizzes
|
|
143
|
+
* @param {boolean} [parameters.skipTracking] - If true, tracking for this question will be skipped. This is useful for preloading the first question of a quiz
|
|
139
144
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
140
145
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
141
146
|
* @returns {Promise}
|
package/lib/modules/search.js
CHANGED
|
@@ -179,13 +179,13 @@ var Search = /*#__PURE__*/function () {
|
|
|
179
179
|
* @param {string} [parameters.sortBy='relevance'] - The sort method for results
|
|
180
180
|
* @param {string} [parameters.sortOrder='descending'] - The sort order for results
|
|
181
181
|
* @param {string} [parameters.section='Products'] - The section name for results
|
|
182
|
-
* @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.com/reference/search-search-
|
|
182
|
+
* @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.com/reference/v1-search-get-search-results#query-params for details
|
|
183
183
|
* @param {object} [parameters.preFilterExpression] - Faceting expression to scope search results. Please refer to https://docs.constructor.com/reference/configuration-collections
|
|
184
184
|
* @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
|
|
185
185
|
* @param {string[]} [parameters.hiddenFacets] - Hidden facets to return
|
|
186
186
|
* @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.com/reference/shared-variations-mapping for details
|
|
187
|
-
* @param {object} [parameters.qsParam] - Parameters listed above can be serialized into a JSON object and parsed through this parameter. Please refer to https://docs.constructor.com/reference/v1-search-get-search-results
|
|
188
|
-
* @param {object} [parameters.filterMatchTypes] - An object specifying whether results must match `all`, `any` or `none` of a given filter. Please refer to https://docs.constructor.com/reference/v1-search-get-search-results
|
|
187
|
+
* @param {object} [parameters.qsParam] - Parameters listed above can be serialized into a JSON object and parsed through this parameter. Please refer to https://docs.constructor.com/reference/v1-search-get-search-results#query-params
|
|
188
|
+
* @param {object} [parameters.filterMatchTypes] - An object specifying whether results must match `all`, `any` or `none` of a given filter. Please refer to https://docs.constructor.com/reference/v1-search-get-search-results#query-params
|
|
189
189
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
190
190
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
191
191
|
* @returns {Promise}
|
|
@@ -257,12 +257,12 @@ var Search = /*#__PURE__*/function () {
|
|
|
257
257
|
* @param {number} [parameters.offset] - The number of results to skip from the beginning (Can't be used together with page)
|
|
258
258
|
* @param {number} [parameters.resultsPerPage] - The number of results per page to return
|
|
259
259
|
* @param {string} [parameters.section='Products'] - The section name for results
|
|
260
|
-
* @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.com/reference/search-search-
|
|
260
|
+
* @param {object} [parameters.fmtOptions] - The format options used to refine result groups. Please refer to https://docs.constructor.com/reference/v1-search-get-natural-language-search-results#query-params for details
|
|
261
261
|
* @param {object} [parameters.preFilterExpression] - Faceting expression to scope search results. Please refer to https://docs.constructor.com/reference/configuration-collections
|
|
262
262
|
* @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.com/reference/shared-variations-mapping for details
|
|
263
263
|
* @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
|
|
264
264
|
* @param {string[]} [parameters.hiddenFacets] - Hidden facets to return
|
|
265
|
-
* @param {object} [parameters.qsParam] - Parameters listed above can be serialized into a JSON object and parsed through this parameter. Please refer to https://docs.constructor.com/reference/v1-search-get-search-results
|
|
265
|
+
* @param {object} [parameters.qsParam] - Parameters listed above can be serialized into a JSON object and parsed through this parameter. Please refer to https://docs.constructor.com/reference/v1-search-get-natural-language-search-results#query-params
|
|
266
266
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
267
267
|
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
268
268
|
* @returns {Promise}
|
package/lib/modules/tracker.js
CHANGED
|
@@ -1281,6 +1281,63 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
1281
1281
|
return new Error('parameters are required of type object');
|
|
1282
1282
|
}
|
|
1283
1283
|
|
|
1284
|
+
/**
|
|
1285
|
+
* Send media impression view event to API
|
|
1286
|
+
*
|
|
1287
|
+
* @function trackMediaImpressionView
|
|
1288
|
+
* @param {object} parameters - Additional parameters to be sent with request
|
|
1289
|
+
* @param {string} parameters.bannerAdId - Banner ad identifier
|
|
1290
|
+
* @param {string} parameters.placementId - Placement identifier
|
|
1291
|
+
* @param {object} [parameters.analyticsTags] - Pass additional analytics data
|
|
1292
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
1293
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
1294
|
+
* @returns {(true|Error)}
|
|
1295
|
+
* @description User viewed a media banner
|
|
1296
|
+
* @example
|
|
1297
|
+
* constructorio.tracker.trackMediaImpressionView(
|
|
1298
|
+
* {
|
|
1299
|
+
* bannerAdId: 'banner_ad_id',
|
|
1300
|
+
* placementId: 'placement_id',
|
|
1301
|
+
* },
|
|
1302
|
+
* );
|
|
1303
|
+
*/
|
|
1304
|
+
}, {
|
|
1305
|
+
key: "trackMediaImpressionView",
|
|
1306
|
+
value: function trackMediaImpressionView(parameters) {
|
|
1307
|
+
var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1308
|
+
// Ensure parameters are provided (required)
|
|
1309
|
+
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
1310
|
+
var baseUrl = new URL(this.options.mediaServiceUrl);
|
|
1311
|
+
if (!baseUrl.hostname.startsWith('behavior')) {
|
|
1312
|
+
baseUrl.hostname = "behavior.".concat(baseUrl.hostname);
|
|
1313
|
+
}
|
|
1314
|
+
var requestPath = "".concat(baseUrl.toString(), "v2/ad_behavioral_action/display_ad_view?");
|
|
1315
|
+
var bodyParams = {};
|
|
1316
|
+
var bannerAdId = parameters.bannerAdId,
|
|
1317
|
+
placementId = parameters.placementId,
|
|
1318
|
+
analyticsTags = parameters.analyticsTags;
|
|
1319
|
+
if (!helpers.isNil(bannerAdId)) {
|
|
1320
|
+
bodyParams.banner_ad_id = bannerAdId;
|
|
1321
|
+
}
|
|
1322
|
+
if (!helpers.isNil(placementId)) {
|
|
1323
|
+
bodyParams.placement_id = placementId;
|
|
1324
|
+
}
|
|
1325
|
+
if (!helpers.isNil(analyticsTags)) {
|
|
1326
|
+
bodyParams.analytics_tags = analyticsTags;
|
|
1327
|
+
}
|
|
1328
|
+
var requestURL = "".concat(requestPath).concat(applyParamsAsString({}, this.options));
|
|
1329
|
+
var requestMethod = 'POST';
|
|
1330
|
+
var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
|
|
1331
|
+
requestMethod: requestMethod
|
|
1332
|
+
}));
|
|
1333
|
+
this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
|
|
1334
|
+
this.requests.send();
|
|
1335
|
+
return true;
|
|
1336
|
+
}
|
|
1337
|
+
this.requests.send();
|
|
1338
|
+
return new Error('parameters are required of type object');
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1284
1341
|
/**
|
|
1285
1342
|
* Send recommendation click event to API
|
|
1286
1343
|
*
|
package/lib/types/index.d.ts
CHANGED
|
@@ -32,8 +32,10 @@ export interface IdOptions extends Record<string, any> {
|
|
|
32
32
|
cookie_days_to_live?: number;
|
|
33
33
|
on_node?: boolean;
|
|
34
34
|
session_is_new?: boolean;
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
// defaults to 'cookie'
|
|
36
|
+
client_id_storage_location?: 'cookie' | 'local';
|
|
37
|
+
// defaults to 'local'
|
|
38
|
+
session_id_storage_location?: 'cookie' | 'local';
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
export interface EventDispatcherOptions {
|
|
@@ -47,6 +49,7 @@ export interface ConstructorClientOptions {
|
|
|
47
49
|
serviceUrl?: string;
|
|
48
50
|
quizzesServiceUrl?: string;
|
|
49
51
|
agentServiceUrl?: string;
|
|
52
|
+
mediaServiceUrl?: string;
|
|
50
53
|
assistantServiceUrl?: string;
|
|
51
54
|
sessionId?: number;
|
|
52
55
|
clientId?: string;
|
package/lib/types/quizzes.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ export interface QuizzesParameters {
|
|
|
21
21
|
quizSessionId?: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
export interface NextQuestionQuizzesParameters extends QuizzesParameters {
|
|
25
|
+
skipTracking?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
export interface QuizResultsFmtOptions {
|
|
25
29
|
hidden_fields?: string[];
|
|
26
30
|
fields?: string[];
|
|
@@ -42,7 +46,7 @@ declare class Quizzes {
|
|
|
42
46
|
|
|
43
47
|
getQuizNextQuestion(
|
|
44
48
|
quizId: string,
|
|
45
|
-
parameters?:
|
|
49
|
+
parameters?: NextQuestionQuizzesParameters,
|
|
46
50
|
networkParameters?: NetworkParameters
|
|
47
51
|
): Promise<NextQuestionResponse>;
|
|
48
52
|
|
package/lib/types/tracker.d.ts
CHANGED
|
@@ -437,5 +437,12 @@ declare class Tracker {
|
|
|
437
437
|
networkParameters?: NetworkParameters
|
|
438
438
|
): true | Error;
|
|
439
439
|
|
|
440
|
+
trackMediaImpressionView(parameters: {
|
|
441
|
+
bannerAdId: string;
|
|
442
|
+
placementId: string;
|
|
443
|
+
analyticsTags?: Record<string, string>;
|
|
444
|
+
}, networkParameters?: NetworkParameters
|
|
445
|
+
): true | Error;
|
|
446
|
+
|
|
440
447
|
on(messageType: string, callback: Function): true | Error;
|
|
441
448
|
}
|
package/lib/version.js
CHANGED