@constructor-io/constructorio-client-javascript 2.49.4 → 2.51.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/modules/autocomplete.js +8 -1
- package/lib/modules/tracker.js +335 -7
- package/lib/types/autocomplete.d.ts +4 -0
- package/lib/types/browse.d.ts +2 -0
- package/lib/types/search.d.ts +2 -0
- package/lib/types/tracker.d.ts +65 -0
- package/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -57,7 +57,8 @@ function createAutocompleteUrl(query, parameters, options) {
|
|
|
57
57
|
filters = parameters.filters,
|
|
58
58
|
filtersPerSection = parameters.filtersPerSection,
|
|
59
59
|
hiddenFields = parameters.hiddenFields,
|
|
60
|
-
variationsMap = parameters.variationsMap
|
|
60
|
+
variationsMap = parameters.variationsMap,
|
|
61
|
+
preFilterExpression = parameters.preFilterExpression;
|
|
61
62
|
|
|
62
63
|
// Pull results number from parameters
|
|
63
64
|
if (numResults) {
|
|
@@ -83,6 +84,11 @@ function createAutocompleteUrl(query, parameters, options) {
|
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
// Pull filter expression from parameters
|
|
88
|
+
if (preFilterExpression) {
|
|
89
|
+
queryParams.pre_filter_expression = JSON.stringify(preFilterExpression);
|
|
90
|
+
}
|
|
91
|
+
|
|
86
92
|
// Pull hidden fields from parameters
|
|
87
93
|
if (hiddenFields) {
|
|
88
94
|
if (queryParams.fmt_options) {
|
|
@@ -132,6 +138,7 @@ var Autocomplete = /*#__PURE__*/function () {
|
|
|
132
138
|
* @param {object} [parameters.filters] - Key / value mapping (dictionary) of filters used to refine results
|
|
133
139
|
* @param {object} [parameters.filtersPerSection] - Filters used to refine results per section
|
|
134
140
|
* @param {object} [parameters.resultsPerSection] - Number of results to return (value) per section (key)
|
|
141
|
+
* @param {object} [parameters.preFilterExpression] - Faceting expression to scope autocomplete results. Please refer to https://docs.constructor.io/rest_api/collections/#add-items-dynamically for details
|
|
135
142
|
* @param {string[]} [parameters.hiddenFields] - Hidden metadata fields to return
|
|
136
143
|
* @param {object} [parameters.variationsMap] - The variations map object to aggregate variations. Please refer to https://docs.constructor.io/rest_api/variations_mapping for details
|
|
137
144
|
* @param {object} [networkParameters] - Parameters relevant to the network request
|
package/lib/modules/tracker.js
CHANGED
|
@@ -81,7 +81,6 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
81
81
|
this.options = options || {};
|
|
82
82
|
this.eventemitter = new EventEmitter();
|
|
83
83
|
this.requests = new RequestQueue(options, this.eventemitter);
|
|
84
|
-
this.behavioralV2Url = 'https://ac.cnstrc.com/v2/behavioral_action/';
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
/**
|
|
@@ -98,7 +97,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
98
97
|
key: "trackSessionStartV2",
|
|
99
98
|
value: function trackSessionStartV2() {
|
|
100
99
|
var networkParameters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
101
|
-
var url = "".concat(this.
|
|
100
|
+
var url = "".concat(this.options.serviceUrl, "/v2/behavioral_action/session_start?");
|
|
102
101
|
this.requests.queue("".concat(url).concat(applyParamsAsString({}, this.options)), 'POST', undefined, networkParameters);
|
|
103
102
|
this.requests.send();
|
|
104
103
|
return true;
|
|
@@ -147,7 +146,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
147
146
|
var userInput = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
148
147
|
var parameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
149
148
|
var networkParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
150
|
-
var baseUrl = "".concat(this.
|
|
149
|
+
var baseUrl = "".concat(this.options.serviceUrl, "/v2/behavioral_action/focus?");
|
|
151
150
|
var bodyParams = {};
|
|
152
151
|
var _parameters$analytics = parameters.analyticsTags,
|
|
153
152
|
analyticsTags = _parameters$analytics === void 0 ? null : _parameters$analytics;
|
|
@@ -304,7 +303,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
304
303
|
if (itemName && typeof itemName === 'string') {
|
|
305
304
|
// Ensure parameters are provided (required)
|
|
306
305
|
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
307
|
-
var baseUrl = "".concat(this.
|
|
306
|
+
var baseUrl = "".concat(this.options.serviceUrl, "/v2/behavioral_action/autocomplete_select?");
|
|
308
307
|
var original_query = parameters.original_query,
|
|
309
308
|
_parameters$originalQ = parameters.originalQuery,
|
|
310
309
|
originalQuery = _parameters$originalQ === void 0 ? original_query : _parameters$originalQ,
|
|
@@ -460,7 +459,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
460
459
|
if (searchTerm && typeof searchTerm === 'string') {
|
|
461
460
|
// Ensure parameters are provided (required)
|
|
462
461
|
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
463
|
-
var baseUrl = "".concat(this.
|
|
462
|
+
var baseUrl = "".concat(this.options.serviceUrl, "/v2/behavioral_action/search_submit?");
|
|
464
463
|
var original_query = parameters.original_query,
|
|
465
464
|
_parameters$originalQ3 = parameters.originalQuery,
|
|
466
465
|
originalQuery = _parameters$originalQ3 === void 0 ? original_query : _parameters$originalQ3,
|
|
@@ -603,7 +602,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
603
602
|
if (searchTerm && typeof searchTerm === 'string') {
|
|
604
603
|
// Ensure parameters are provided (required)
|
|
605
604
|
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
606
|
-
var baseUrl = "".concat(this.
|
|
605
|
+
var baseUrl = "".concat(this.options.serviceUrl, "/v2/behavioral_action/search_result_load?");
|
|
607
606
|
var num_results = parameters.num_results,
|
|
608
607
|
_parameters$numResult = parameters.numResults,
|
|
609
608
|
numResults = _parameters$numResult === void 0 ? num_results : _parameters$numResult,
|
|
@@ -784,7 +783,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
784
783
|
if (searchTerm && typeof searchTerm === 'string') {
|
|
785
784
|
// Ensure parameters are provided (required)
|
|
786
785
|
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
787
|
-
var baseUrl = "".concat(this.
|
|
786
|
+
var baseUrl = "".concat(this.options.serviceUrl, "/v2/behavioral_action/search_result_click?");
|
|
788
787
|
var num_results = parameters.num_results,
|
|
789
788
|
customer_id = parameters.customer_id,
|
|
790
789
|
item_id = parameters.item_id,
|
|
@@ -2130,6 +2129,335 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
2130
2129
|
return new Error('parameters are required of type object');
|
|
2131
2130
|
}
|
|
2132
2131
|
|
|
2132
|
+
/**
|
|
2133
|
+
* Send ASA request submitted event
|
|
2134
|
+
*
|
|
2135
|
+
* @function trackAssistantSubmit
|
|
2136
|
+
* @param {object} parameters - Additional parameters to be sent with request
|
|
2137
|
+
* @param {string} parameters.intent - Intent of user request
|
|
2138
|
+
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
|
|
2139
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2140
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
2141
|
+
* @returns {(true|Error)}
|
|
2142
|
+
* @description User submitted an assistant search
|
|
2143
|
+
* (pressing enter within assistant input element, or clicking assistant submit element)
|
|
2144
|
+
* @example
|
|
2145
|
+
* constructorio.tracker.trackAssistantSubmit(
|
|
2146
|
+
* {
|
|
2147
|
+
* intent: 'show me a recipe for a cookie',
|
|
2148
|
+
* },
|
|
2149
|
+
* );
|
|
2150
|
+
*/
|
|
2151
|
+
}, {
|
|
2152
|
+
key: "trackAssistantSubmit",
|
|
2153
|
+
value: function trackAssistantSubmit(parameters) {
|
|
2154
|
+
var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2155
|
+
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
2156
|
+
// Ensure parameters are provided (required)
|
|
2157
|
+
var baseUrl = "".concat(this.options.serviceUrl, "/v2/behavioral_action/assistant_submit?");
|
|
2158
|
+
var section = parameters.section,
|
|
2159
|
+
intent = parameters.intent;
|
|
2160
|
+
var bodyParams = {
|
|
2161
|
+
intent: intent,
|
|
2162
|
+
section: section
|
|
2163
|
+
};
|
|
2164
|
+
var requestURL = "".concat(baseUrl).concat(applyParamsAsString({}, this.options));
|
|
2165
|
+
var requestMethod = 'POST';
|
|
2166
|
+
var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
|
|
2167
|
+
requestMethod: requestMethod
|
|
2168
|
+
}));
|
|
2169
|
+
this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
|
|
2170
|
+
this.requests.send();
|
|
2171
|
+
return true;
|
|
2172
|
+
}
|
|
2173
|
+
this.requests.send();
|
|
2174
|
+
return new Error('parameters are required of type object');
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
/**
|
|
2178
|
+
* Send assistant results page load started
|
|
2179
|
+
*
|
|
2180
|
+
* @function trackAssistantResultLoadStarted
|
|
2181
|
+
* @param {object} parameters - Additional parameters to be sent with request
|
|
2182
|
+
* @param {string} parameters.intent - Intent of user request
|
|
2183
|
+
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
|
|
2184
|
+
* @param {string} [parameters.intentResultId] - The intent result id from the ASA response
|
|
2185
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2186
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
2187
|
+
* @returns {(true|Error)}
|
|
2188
|
+
* @description Assistant results page load begun (but has not necessarily loaded completely)
|
|
2189
|
+
* @example
|
|
2190
|
+
* constructorio.tracker.trackAssistantResultLoadStarted(
|
|
2191
|
+
* {
|
|
2192
|
+
* intent: 'show me a recipe for a cookie',
|
|
2193
|
+
* intentResultId: 'Zde93fd-f955-4020-8b8d-6b21b93cb5a2',
|
|
2194
|
+
* },
|
|
2195
|
+
* );
|
|
2196
|
+
*/
|
|
2197
|
+
}, {
|
|
2198
|
+
key: "trackAssistantResultLoadStarted",
|
|
2199
|
+
value: function trackAssistantResultLoadStarted(parameters) {
|
|
2200
|
+
var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2201
|
+
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
2202
|
+
// Ensure parameters are provided (required)
|
|
2203
|
+
var baseUrl = "".concat(this.options.serviceUrl, "/v2/behavioral_action/assistant_result_load_start?");
|
|
2204
|
+
var section = parameters.section,
|
|
2205
|
+
intentResultId = parameters.intentResultId,
|
|
2206
|
+
intent = parameters.intent;
|
|
2207
|
+
var bodyParams = {
|
|
2208
|
+
intent_result_id: intentResultId,
|
|
2209
|
+
intent: intent,
|
|
2210
|
+
section: section
|
|
2211
|
+
};
|
|
2212
|
+
var requestURL = "".concat(baseUrl).concat(applyParamsAsString({}, this.options));
|
|
2213
|
+
var requestMethod = 'POST';
|
|
2214
|
+
var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
|
|
2215
|
+
requestMethod: requestMethod
|
|
2216
|
+
}));
|
|
2217
|
+
this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
|
|
2218
|
+
this.requests.send();
|
|
2219
|
+
return true;
|
|
2220
|
+
}
|
|
2221
|
+
this.requests.send();
|
|
2222
|
+
return new Error('parameters are required of type object');
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
/**
|
|
2226
|
+
* Send assistant results page load finished
|
|
2227
|
+
*
|
|
2228
|
+
* @function trackAssistantResultLoadFinished
|
|
2229
|
+
* @param {object} parameters - Additional parameters to be sent with request
|
|
2230
|
+
* @param {string} parameters.intent - Intent of user request
|
|
2231
|
+
* @param {number} parameters.searchResultCount - Number of search results loaded
|
|
2232
|
+
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
|
|
2233
|
+
* @param {string} [parameters.intentResultId] - The intent result id from the ASA response
|
|
2234
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2235
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
2236
|
+
* @returns {(true|Error)}
|
|
2237
|
+
* @description Assistant results page load finished
|
|
2238
|
+
* @example
|
|
2239
|
+
* constructorio.tracker.trackAssistantResultLoadFinished(
|
|
2240
|
+
* {
|
|
2241
|
+
* intent: 'show me a recipe for a cookie',
|
|
2242
|
+
* intentResultId: 'Zde93fd-f955-4020-8b8d-6b21b93cb5a2',
|
|
2243
|
+
* searchResultCount: 5,
|
|
2244
|
+
* },
|
|
2245
|
+
* );
|
|
2246
|
+
*/
|
|
2247
|
+
}, {
|
|
2248
|
+
key: "trackAssistantResultLoadFinished",
|
|
2249
|
+
value: function trackAssistantResultLoadFinished(parameters) {
|
|
2250
|
+
var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2251
|
+
// Ensure parameters are provided (required)
|
|
2252
|
+
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
2253
|
+
var baseUrl = "".concat(this.options.serviceUrl, "/v2/behavioral_action/assistant_result_load_finish?");
|
|
2254
|
+
var section = parameters.section,
|
|
2255
|
+
searchResultCount = parameters.searchResultCount,
|
|
2256
|
+
intentResultId = parameters.intentResultId,
|
|
2257
|
+
intent = parameters.intent;
|
|
2258
|
+
var bodyParams = {
|
|
2259
|
+
intent_result_id: intentResultId,
|
|
2260
|
+
section: section,
|
|
2261
|
+
intent: intent,
|
|
2262
|
+
search_result_count: searchResultCount
|
|
2263
|
+
};
|
|
2264
|
+
var requestURL = "".concat(baseUrl).concat(applyParamsAsString({}, this.options));
|
|
2265
|
+
var requestMethod = 'POST';
|
|
2266
|
+
var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
|
|
2267
|
+
requestMethod: requestMethod
|
|
2268
|
+
}));
|
|
2269
|
+
this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
|
|
2270
|
+
this.requests.send();
|
|
2271
|
+
return true;
|
|
2272
|
+
}
|
|
2273
|
+
this.requests.send();
|
|
2274
|
+
return new Error('parameters are required of type object');
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
/**
|
|
2278
|
+
* Send assistant result click event to API
|
|
2279
|
+
*
|
|
2280
|
+
* @function trackAssistantResultClick
|
|
2281
|
+
* @param {object} parameters - Additional parameters to be sent with request
|
|
2282
|
+
* @param {string} parameters.intent - intent of the user
|
|
2283
|
+
* @param {string} parameters.searchResultId - result_id of the specific search result the clicked item belongs to
|
|
2284
|
+
* @param {string} parameters.itemId - Product item unique identifier
|
|
2285
|
+
* @param {string} parameters.itemName - Product item name
|
|
2286
|
+
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
|
|
2287
|
+
* @param {string} [parameters.variationId] - Product item variation unique identifier
|
|
2288
|
+
* @param {string} [parameters.intentResultId] - Browse result identifier (returned in response from Constructor)
|
|
2289
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2290
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
2291
|
+
* @returns {(true|Error)}
|
|
2292
|
+
* @description User clicked a result that appeared within an assistant search result
|
|
2293
|
+
* @example
|
|
2294
|
+
* constructorio.tracker.trackAssistantResultClick(
|
|
2295
|
+
* {
|
|
2296
|
+
* variationId: 'KMH879-7632',
|
|
2297
|
+
* searchResultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
|
|
2298
|
+
* intentResultId: 'Zde93fd-f955-4020-8b8d-6b21b93cb5a2',
|
|
2299
|
+
* intent: 'show me a recipe for a cookie',
|
|
2300
|
+
* itemId: 'KMH876',
|
|
2301
|
+
* },
|
|
2302
|
+
* );
|
|
2303
|
+
*/
|
|
2304
|
+
}, {
|
|
2305
|
+
key: "trackAssistantResultClick",
|
|
2306
|
+
value: function trackAssistantResultClick(parameters) {
|
|
2307
|
+
var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2308
|
+
// Ensure parameters are provided (required)
|
|
2309
|
+
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
2310
|
+
var requestPath = "".concat(this.options.serviceUrl, "/v2/behavioral_action/assistant_search_result_click?");
|
|
2311
|
+
var _parameters$section10 = parameters.section,
|
|
2312
|
+
section = _parameters$section10 === void 0 ? 'Products' : _parameters$section10,
|
|
2313
|
+
variationId = parameters.variationId,
|
|
2314
|
+
intentResultId = parameters.intentResultId,
|
|
2315
|
+
searchResultId = parameters.searchResultId,
|
|
2316
|
+
itemId = parameters.itemId,
|
|
2317
|
+
itemName = parameters.itemName,
|
|
2318
|
+
intent = parameters.intent;
|
|
2319
|
+
var bodyParams = {
|
|
2320
|
+
section: section,
|
|
2321
|
+
variation_id: variationId,
|
|
2322
|
+
intent_result_id: intentResultId,
|
|
2323
|
+
search_result_id: searchResultId,
|
|
2324
|
+
item_id: itemId,
|
|
2325
|
+
item_name: itemName,
|
|
2326
|
+
intent: intent
|
|
2327
|
+
};
|
|
2328
|
+
var requestURL = "".concat(requestPath).concat(applyParamsAsString({}, this.options));
|
|
2329
|
+
var requestMethod = 'POST';
|
|
2330
|
+
var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
|
|
2331
|
+
requestMethod: requestMethod
|
|
2332
|
+
}));
|
|
2333
|
+
this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
|
|
2334
|
+
this.requests.send();
|
|
2335
|
+
return true;
|
|
2336
|
+
}
|
|
2337
|
+
this.requests.send();
|
|
2338
|
+
return new Error('parameters are required of type object');
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
/**
|
|
2342
|
+
* Send assistant search result view event to API
|
|
2343
|
+
*
|
|
2344
|
+
* @function trackAssistantResultView
|
|
2345
|
+
* @param {object} parameters - Additional parameters to be sent with request
|
|
2346
|
+
* @param {string} parameters.intent - intent of the user
|
|
2347
|
+
* @param {string} parameters.searchResultId - result_id of the specific search result the clicked item belongs to
|
|
2348
|
+
* @param {number} parameters.numResultsViewed - Number of items viewed in this search result
|
|
2349
|
+
* @param {object[]} [parameters.items] - List of product item objects viewed
|
|
2350
|
+
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
|
|
2351
|
+
* @param {string} [parameters.intentResultId] - Browse result identifier (returned in response from Constructor)
|
|
2352
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2353
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
2354
|
+
* @returns {(true|Error)}
|
|
2355
|
+
* @description User viewed a search result within an assistant result
|
|
2356
|
+
* @example
|
|
2357
|
+
* constructorio.tracker.trackAssistantResultView(
|
|
2358
|
+
* {
|
|
2359
|
+
* searchResultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
|
|
2360
|
+
* intentResultId: 'Zde93fd-f955-4020-8b8d-6b21b93cb5a2',
|
|
2361
|
+
* intent: 'show me a recipe for a cookie',
|
|
2362
|
+
* numResultsViewed: 5,
|
|
2363
|
+
* items: [{itemId: 'KMH876'}, {itemId: 'KMH140'}, {itemId: 'KMH437'}],
|
|
2364
|
+
* },
|
|
2365
|
+
* );
|
|
2366
|
+
*/
|
|
2367
|
+
}, {
|
|
2368
|
+
key: "trackAssistantResultView",
|
|
2369
|
+
value: function trackAssistantResultView(parameters) {
|
|
2370
|
+
var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2371
|
+
// Ensure parameters are provided (required)
|
|
2372
|
+
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
2373
|
+
var requestPath = "".concat(this.options.serviceUrl, "/v2/behavioral_action/assistant_search_result_view?");
|
|
2374
|
+
var _parameters$section11 = parameters.section,
|
|
2375
|
+
section = _parameters$section11 === void 0 ? 'Products' : _parameters$section11,
|
|
2376
|
+
items = parameters.items,
|
|
2377
|
+
numResultsViewed = parameters.numResultsViewed,
|
|
2378
|
+
intentResultId = parameters.intentResultId,
|
|
2379
|
+
searchResultId = parameters.searchResultId,
|
|
2380
|
+
intent = parameters.intent;
|
|
2381
|
+
var bodyParams = {
|
|
2382
|
+
section: section,
|
|
2383
|
+
intent_result_id: intentResultId,
|
|
2384
|
+
search_result_id: searchResultId,
|
|
2385
|
+
num_results_viewed: numResultsViewed,
|
|
2386
|
+
items: items && Array.isArray(items) && items.slice(0, 100).map(function (item) {
|
|
2387
|
+
return helpers.toSnakeCaseKeys(item, false);
|
|
2388
|
+
}),
|
|
2389
|
+
intent: intent
|
|
2390
|
+
};
|
|
2391
|
+
var requestURL = "".concat(requestPath).concat(applyParamsAsString({}, this.options));
|
|
2392
|
+
var requestMethod = 'POST';
|
|
2393
|
+
var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
|
|
2394
|
+
requestMethod: requestMethod
|
|
2395
|
+
}));
|
|
2396
|
+
this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
|
|
2397
|
+
this.requests.send();
|
|
2398
|
+
return true;
|
|
2399
|
+
}
|
|
2400
|
+
this.requests.send();
|
|
2401
|
+
return new Error('parameters are required of type object');
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
/**
|
|
2405
|
+
* Send ASA search submitted event
|
|
2406
|
+
*
|
|
2407
|
+
* @function trackAssistantSearchSubmit
|
|
2408
|
+
* @param {object} parameters - Additional parameters to be sent with request
|
|
2409
|
+
* @param {string} parameters.intent - Intent of user request
|
|
2410
|
+
* @param {string} parameters.searchTerm - Term of submitted assistant search event
|
|
2411
|
+
* @param {string} parameters.searchResultId - resultId of search result the clicked item belongs to
|
|
2412
|
+
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
|
|
2413
|
+
* @param {string} [parameters.intentResultId] - intentResultId from the ASA response
|
|
2414
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
2415
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
2416
|
+
* @returns {(true|Error)}
|
|
2417
|
+
* @description User submitted an alternative assistant search result search term
|
|
2418
|
+
* @example
|
|
2419
|
+
* constructorio.tracker.trackAssistantSearchSubmit({
|
|
2420
|
+
* {
|
|
2421
|
+
* searchResultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
|
|
2422
|
+
* intentResultId: 'Zde93fd-f955-4020-8b8d-6b21b93cb5a2',
|
|
2423
|
+
* intent: 'show me a recipe for a cookie',
|
|
2424
|
+
* searchTerm: 'flour',
|
|
2425
|
+
* },
|
|
2426
|
+
* );
|
|
2427
|
+
*/
|
|
2428
|
+
}, {
|
|
2429
|
+
key: "trackAssistantSearchSubmit",
|
|
2430
|
+
value: function trackAssistantSearchSubmit(parameters) {
|
|
2431
|
+
var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2432
|
+
// Ensure parameters are provided (required)
|
|
2433
|
+
if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
|
|
2434
|
+
// Ensure parameters are provided (required)
|
|
2435
|
+
var baseUrl = "".concat(this.options.serviceUrl, "/v2/behavioral_action/assistant_search_submit?");
|
|
2436
|
+
var section = parameters.section,
|
|
2437
|
+
intent = parameters.intent,
|
|
2438
|
+
searchTerm = parameters.searchTerm,
|
|
2439
|
+
searchResultId = parameters.searchResultId,
|
|
2440
|
+
intentResultId = parameters.intentResultId;
|
|
2441
|
+
var bodyParams = {
|
|
2442
|
+
intent: intent,
|
|
2443
|
+
section: section,
|
|
2444
|
+
search_term: searchTerm,
|
|
2445
|
+
search_result_id: searchResultId,
|
|
2446
|
+
intent_result_id: intentResultId
|
|
2447
|
+
};
|
|
2448
|
+
var requestURL = "".concat(baseUrl).concat(applyParamsAsString({}, this.options));
|
|
2449
|
+
var requestMethod = 'POST';
|
|
2450
|
+
var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
|
|
2451
|
+
requestMethod: requestMethod
|
|
2452
|
+
}));
|
|
2453
|
+
this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
|
|
2454
|
+
this.requests.send();
|
|
2455
|
+
return true;
|
|
2456
|
+
}
|
|
2457
|
+
this.requests.send();
|
|
2458
|
+
return new Error('parameters is a required parameter of type object');
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2133
2461
|
/**
|
|
2134
2462
|
* Subscribe to success or error messages emitted by tracking requests
|
|
2135
2463
|
*
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
RequestFeature,
|
|
6
6
|
RequestFeatureVariant,
|
|
7
7
|
VariationsMap,
|
|
8
|
+
FilterExpression,
|
|
8
9
|
} from '.';
|
|
9
10
|
import EventDispatcher from './event-dispatcher';
|
|
10
11
|
|
|
@@ -17,6 +18,7 @@ export interface IAutocompleteParameters {
|
|
|
17
18
|
resultsPerSection?: Record<string, number>;
|
|
18
19
|
hiddenFields?: string[];
|
|
19
20
|
variationsMap?: VariationsMap;
|
|
21
|
+
preFilterExpression?: FilterExpression;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
declare class Autocomplete {
|
|
@@ -49,4 +51,6 @@ export interface AutocompleteRequestType extends Record<string, any> {
|
|
|
49
51
|
features: Partial<RequestFeature>;
|
|
50
52
|
feature_variants: Partial<RequestFeatureVariant>;
|
|
51
53
|
searchandized_items: Record<string, any>;
|
|
54
|
+
variations_map?: VariationsMap;
|
|
55
|
+
pre_filter_expression?: FilterExpression;
|
|
52
56
|
}
|
package/lib/types/browse.d.ts
CHANGED
|
@@ -141,4 +141,6 @@ export interface BrowseRequestType extends Record<string, any> {
|
|
|
141
141
|
features: Partial<RequestFeature>;
|
|
142
142
|
feature_variants: Partial<RequestFeatureVariant>;
|
|
143
143
|
searchandized_items: Record<string, any>;
|
|
144
|
+
variations_map?: VariationsMap;
|
|
145
|
+
pre_filter_expression?: FilterExpression;
|
|
144
146
|
}
|
package/lib/types/search.d.ts
CHANGED
|
@@ -84,6 +84,8 @@ export interface SearchRequestType extends Record<string, any> {
|
|
|
84
84
|
feature_variants: Partial<RequestFeatureVariant>;
|
|
85
85
|
searchandized_items: Record<string, any>;
|
|
86
86
|
original_query?: string;
|
|
87
|
+
variations_map?: VariationsMap;
|
|
88
|
+
pre_filter_expression?: FilterExpression;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
export interface Result extends Record<string, any> {
|
package/lib/types/tracker.d.ts
CHANGED
|
@@ -253,5 +253,70 @@ declare class Tracker {
|
|
|
253
253
|
networkParameters?: NetworkParameters
|
|
254
254
|
): true | Error;
|
|
255
255
|
|
|
256
|
+
trackAssistantSubmit(
|
|
257
|
+
parameters: {
|
|
258
|
+
intent: string;
|
|
259
|
+
section?: string;
|
|
260
|
+
},
|
|
261
|
+
networkParameters?: NetworkParameters
|
|
262
|
+
): true | Error;
|
|
263
|
+
|
|
264
|
+
trackAssistantResultLoadStarted(
|
|
265
|
+
parameters: {
|
|
266
|
+
intent: string;
|
|
267
|
+
section?: string;
|
|
268
|
+
intentResultId?: string;
|
|
269
|
+
},
|
|
270
|
+
networkParameters?: NetworkParameters
|
|
271
|
+
): true | Error;
|
|
272
|
+
|
|
273
|
+
trackAssistantResultLoadFinished(
|
|
274
|
+
parameters: {
|
|
275
|
+
intent: string;
|
|
276
|
+
searchResultCount: number;
|
|
277
|
+
section?: string;
|
|
278
|
+
intentResultId?: string;
|
|
279
|
+
},
|
|
280
|
+
networkParameters?: NetworkParameters
|
|
281
|
+
): true | Error;
|
|
282
|
+
|
|
283
|
+
trackAssistantResultClick(
|
|
284
|
+
parameters: {
|
|
285
|
+
intent: string;
|
|
286
|
+
searchResultId: string;
|
|
287
|
+
itemId?: string;
|
|
288
|
+
itemName?: string;
|
|
289
|
+
variationId?: string;
|
|
290
|
+
section?: string;
|
|
291
|
+
intentResultId?: string;
|
|
292
|
+
},
|
|
293
|
+
networkParameters?: NetworkParameters
|
|
294
|
+
): true | Error;
|
|
295
|
+
|
|
296
|
+
trackAssistantResultView(
|
|
297
|
+
parameters: {
|
|
298
|
+
intent: string;
|
|
299
|
+
searchResultId: string;
|
|
300
|
+
numResultsViewed: number;
|
|
301
|
+
items?: ItemTracked[];
|
|
302
|
+
intentResultId?: string;
|
|
303
|
+
section?: string;
|
|
304
|
+
},
|
|
305
|
+
networkParameters?: NetworkParameters
|
|
306
|
+
): true | Error;
|
|
307
|
+
|
|
308
|
+
trackAssistantSearchSubmit(
|
|
309
|
+
parameters: {
|
|
310
|
+
intent: string,
|
|
311
|
+
searchTerm: string;
|
|
312
|
+
userInput: string;
|
|
313
|
+
searchResultId: string;
|
|
314
|
+
groupId?: string;
|
|
315
|
+
section?: string;
|
|
316
|
+
intentResultId?: string;
|
|
317
|
+
},
|
|
318
|
+
networkParameters?: NetworkParameters
|
|
319
|
+
): true | Error;
|
|
320
|
+
|
|
256
321
|
on(messageType: string, callback: Function): true | Error;
|
|
257
322
|
}
|
package/lib/version.js
CHANGED