@constructor-io/constructorio-node 3.8.7 → 3.8.8
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/package.json +1 -1
- package/src/modules/tracker.js +71 -0
package/package.json
CHANGED
package/src/modules/tracker.js
CHANGED
|
@@ -264,6 +264,77 @@ class Tracker {
|
|
|
264
264
|
return true;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
+
/**
|
|
268
|
+
* Send item detail load event to API
|
|
269
|
+
*
|
|
270
|
+
* @function trackItemDetailLoad
|
|
271
|
+
* @param {object} parameters - Additional parameters to be sent with request
|
|
272
|
+
* @param {string} parameters.item_name - Product item name
|
|
273
|
+
* @param {string} parameters.item_id - Product item unique identifier
|
|
274
|
+
* @param {string} [parameters.variation_id] - Product item variation unique identifier
|
|
275
|
+
* @param {object} userParameters - Parameters relevant to the user request
|
|
276
|
+
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
277
|
+
* @param {number} userParameters.clientId - Client ID, utilized to personalize results
|
|
278
|
+
* @param {string} [userParameters.userId] - User ID, utilized to personalize results
|
|
279
|
+
* @param {string} [userParameters.segments] - User segments
|
|
280
|
+
* @param {object} [userParameters.testCells] - User test cells
|
|
281
|
+
* @param {string} [userParameters.originReferrer] - Client page URL (including path)
|
|
282
|
+
* @param {string} [userParameters.referer] - Client page URL (including path)
|
|
283
|
+
* @param {string} [userParameters.userIp] - Client user IP
|
|
284
|
+
* @param {string} [userParameters.userAgent] - Client user agent
|
|
285
|
+
* @param {string} [userParameters.acceptLanguage] - Client accept language
|
|
286
|
+
* @param {object} [networkParameters] - Parameters relevant to the network request
|
|
287
|
+
* @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
|
|
288
|
+
* @returns {(true|Error)}
|
|
289
|
+
* @description User loaded an item detail page
|
|
290
|
+
* @example
|
|
291
|
+
* constructorio.tracker.trackItemDetailLoad(
|
|
292
|
+
* {
|
|
293
|
+
* item_name: 'Red T-Shirt',
|
|
294
|
+
* item_id: 'KMH876',
|
|
295
|
+
* },
|
|
296
|
+
* );
|
|
297
|
+
*/
|
|
298
|
+
trackItemDetailLoad(parameters, userParameters, networkParameters = {}) {
|
|
299
|
+
// Ensure parameters are provided (required)
|
|
300
|
+
if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
|
|
301
|
+
const url = `${this.options.serviceUrl}/behavior?`;
|
|
302
|
+
const queryParams = { action: 'item_detail_load' };
|
|
303
|
+
const { item_name, name, item_id, customer_id, variation_id } = parameters;
|
|
304
|
+
|
|
305
|
+
// Ensure support for both item_name and name as parameters
|
|
306
|
+
if (item_name) {
|
|
307
|
+
queryParams.name = item_name;
|
|
308
|
+
} else if (name) {
|
|
309
|
+
queryParams.name = name;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Ensure support for both item_id and customer_id as parameters
|
|
313
|
+
if (item_id) {
|
|
314
|
+
queryParams.customer_id = item_id;
|
|
315
|
+
} else if (customer_id) {
|
|
316
|
+
queryParams.customer_id = customer_id;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (variation_id) {
|
|
320
|
+
queryParams.variation_id = variation_id;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const requestUrl = `${url}${applyParamsAsString(queryParams, userParameters, this.options)}`;
|
|
324
|
+
|
|
325
|
+
send.call(
|
|
326
|
+
this,
|
|
327
|
+
requestUrl,
|
|
328
|
+
userParameters,
|
|
329
|
+
networkParameters,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return new Error('parameters are required of type object');
|
|
336
|
+
}
|
|
337
|
+
|
|
267
338
|
/**
|
|
268
339
|
* Send autocomplete select event to API
|
|
269
340
|
*
|