@constructor-io/constructorio-node 4.4.7 → 4.5.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.
- package/package.json +1 -1
- package/src/modules/browse.js +7 -0
- package/src/modules/catalog.js +177 -129
- package/src/modules/search.js +8 -0
- package/src/modules/tracker.js +311 -251
- package/src/types/browse.d.ts +2 -1
- package/src/types/search.d.ts +1 -0
- package/src/utils/helpers.js +13 -0
package/src/modules/tracker.js
CHANGED
|
@@ -270,10 +270,10 @@ class Tracker {
|
|
|
270
270
|
*
|
|
271
271
|
* @function trackItemDetailLoad
|
|
272
272
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
273
|
-
* @param {string} parameters.
|
|
274
|
-
* @param {string} parameters.
|
|
273
|
+
* @param {string} parameters.itemName - Product item name
|
|
274
|
+
* @param {string} parameters.itemId - Product item unique identifier
|
|
275
275
|
* @param {string} parameters.url - Current page URL
|
|
276
|
-
* @param {string} [parameters.
|
|
276
|
+
* @param {string} [parameters.variationId] - Product item variation unique identifier
|
|
277
277
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
278
278
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
279
279
|
* @param {number} userParameters.clientId - Client ID, utilized to personalize results
|
|
@@ -292,8 +292,8 @@ class Tracker {
|
|
|
292
292
|
* @example
|
|
293
293
|
* constructorio.tracker.trackItemDetailLoad(
|
|
294
294
|
* {
|
|
295
|
-
*
|
|
296
|
-
*
|
|
295
|
+
* itemName: 'Red T-Shirt',
|
|
296
|
+
* itemId: 'KMH876',
|
|
297
297
|
* url: 'https://constructor.io/product/KMH876',
|
|
298
298
|
* },
|
|
299
299
|
* );
|
|
@@ -308,26 +308,26 @@ class Tracker {
|
|
|
308
308
|
name,
|
|
309
309
|
item_id,
|
|
310
310
|
customer_id,
|
|
311
|
+
customerId = customer_id,
|
|
311
312
|
variation_id,
|
|
313
|
+
itemName = item_name || name,
|
|
314
|
+
itemId = item_id || customerId,
|
|
315
|
+
variationId = variation_id,
|
|
312
316
|
url,
|
|
313
317
|
} = parameters;
|
|
314
318
|
|
|
315
319
|
// Ensure support for both item_name and name as parameters
|
|
316
|
-
if (
|
|
317
|
-
bodyParams.item_name =
|
|
318
|
-
} else if (name) {
|
|
319
|
-
bodyParams.item_name = name;
|
|
320
|
+
if (itemName) {
|
|
321
|
+
bodyParams.item_name = itemName;
|
|
320
322
|
}
|
|
321
323
|
|
|
322
324
|
// Ensure support for both item_id and customer_id as parameters
|
|
323
|
-
if (
|
|
324
|
-
bodyParams.item_id =
|
|
325
|
-
} else if (customer_id) {
|
|
326
|
-
bodyParams.item_id = customer_id;
|
|
325
|
+
if (itemId) {
|
|
326
|
+
bodyParams.item_id = itemId;
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
if (
|
|
330
|
-
bodyParams.variation_id =
|
|
329
|
+
if (variationId) {
|
|
330
|
+
bodyParams.variation_id = variationId;
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
if (url) {
|
|
@@ -359,11 +359,11 @@ class Tracker {
|
|
|
359
359
|
* @function trackAutocompleteSelect
|
|
360
360
|
* @param {string} term - Term of selected autocomplete item
|
|
361
361
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
362
|
-
* @param {string} parameters.
|
|
362
|
+
* @param {string} parameters.originalQuery - The current autocomplete search query
|
|
363
363
|
* @param {string} parameters.section - Section the selected item resides within
|
|
364
364
|
* @param {string} [parameters.tr] - Trigger used to select the item (click, etc.)
|
|
365
|
-
* @param {string} [parameters.
|
|
366
|
-
* @param {string} [parameters.
|
|
365
|
+
* @param {string} [parameters.groupId] - Group identifier of selected item
|
|
366
|
+
* @param {string} [parameters.displayName] - Display name of group of selected item
|
|
367
367
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
368
368
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
369
369
|
* @param {number} userParameters.clientId - Client ID, utilized to personalize results
|
|
@@ -383,11 +383,11 @@ class Tracker {
|
|
|
383
383
|
* constructorio.tracker.trackAutocompleteSelect(
|
|
384
384
|
* 'T-Shirt',
|
|
385
385
|
* {
|
|
386
|
-
*
|
|
386
|
+
* originalQuery: 'Shirt',
|
|
387
387
|
* section: 'Products',
|
|
388
388
|
* tr: 'click',
|
|
389
|
-
*
|
|
390
|
-
*
|
|
389
|
+
* groupId: '88JU230',
|
|
390
|
+
* displayName: 'apparel',
|
|
391
391
|
* },
|
|
392
392
|
* {
|
|
393
393
|
* sessionId: 1,
|
|
@@ -407,29 +407,33 @@ class Tracker {
|
|
|
407
407
|
const queryParams = {};
|
|
408
408
|
const {
|
|
409
409
|
original_query,
|
|
410
|
+
originalQuery = original_query,
|
|
410
411
|
section,
|
|
411
412
|
original_section,
|
|
413
|
+
originalSection = original_section,
|
|
412
414
|
tr,
|
|
413
415
|
group_id,
|
|
416
|
+
groupId = group_id,
|
|
414
417
|
display_name,
|
|
418
|
+
displayName = display_name,
|
|
415
419
|
} = parameters;
|
|
416
420
|
|
|
417
|
-
if (
|
|
418
|
-
queryParams.original_query =
|
|
421
|
+
if (originalQuery) {
|
|
422
|
+
queryParams.original_query = originalQuery;
|
|
419
423
|
}
|
|
420
424
|
|
|
421
425
|
if (tr) {
|
|
422
426
|
queryParams.tr = tr;
|
|
423
427
|
}
|
|
424
428
|
|
|
425
|
-
if (
|
|
426
|
-
queryParams.section =
|
|
429
|
+
if (originalSection || section) {
|
|
430
|
+
queryParams.section = originalSection || section;
|
|
427
431
|
}
|
|
428
432
|
|
|
429
|
-
if (
|
|
433
|
+
if (groupId) {
|
|
430
434
|
queryParams.group = {
|
|
431
|
-
group_id,
|
|
432
|
-
display_name,
|
|
435
|
+
group_id: groupId,
|
|
436
|
+
display_name: displayName,
|
|
433
437
|
};
|
|
434
438
|
}
|
|
435
439
|
|
|
@@ -457,9 +461,9 @@ class Tracker {
|
|
|
457
461
|
* @function trackSearchSubmit
|
|
458
462
|
* @param {string} term - Term of submitted autocomplete event
|
|
459
463
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
460
|
-
* @param {string} parameters.
|
|
461
|
-
* @param {string} [parameters.
|
|
462
|
-
* @param {string} [parameters.
|
|
464
|
+
* @param {string} parameters.originalQuery - The current autocomplete search query
|
|
465
|
+
* @param {string} [parameters.groupId] - Group identifier of selected item
|
|
466
|
+
* @param {string} [parameters.displayName] - Display name of group of selected item
|
|
463
467
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
464
468
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
465
469
|
* @param {number} userParameters.clientId - Client ID, utilized to personalize results
|
|
@@ -479,9 +483,9 @@ class Tracker {
|
|
|
479
483
|
* constructorio.tracker.trackSearchSubmit(
|
|
480
484
|
* 'T-Shirt',
|
|
481
485
|
* {
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
486
|
+
* originalQuery: 'Shirt',
|
|
487
|
+
* groupId: '88JU230',
|
|
488
|
+
* displayName: 'apparel',
|
|
485
489
|
* },
|
|
486
490
|
* {
|
|
487
491
|
* sessionId: 1,
|
|
@@ -499,16 +503,23 @@ class Tracker {
|
|
|
499
503
|
if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
|
|
500
504
|
const url = `${this.options.serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(term))}/search?`;
|
|
501
505
|
const queryParams = {};
|
|
502
|
-
const {
|
|
506
|
+
const {
|
|
507
|
+
original_query,
|
|
508
|
+
originalQuery = original_query,
|
|
509
|
+
group_id,
|
|
510
|
+
groupId = group_id,
|
|
511
|
+
display_name,
|
|
512
|
+
displayName = display_name,
|
|
513
|
+
} = parameters;
|
|
503
514
|
|
|
504
|
-
if (
|
|
505
|
-
queryParams.original_query =
|
|
515
|
+
if (originalQuery) {
|
|
516
|
+
queryParams.original_query = originalQuery;
|
|
506
517
|
}
|
|
507
518
|
|
|
508
|
-
if (
|
|
519
|
+
if (groupId) {
|
|
509
520
|
queryParams.group = {
|
|
510
|
-
group_id,
|
|
511
|
-
display_name,
|
|
521
|
+
group_id: groupId,
|
|
522
|
+
display_name: displayName,
|
|
512
523
|
};
|
|
513
524
|
}
|
|
514
525
|
|
|
@@ -536,8 +547,8 @@ class Tracker {
|
|
|
536
547
|
* @function trackSearchResultsLoaded
|
|
537
548
|
* @param {string} term - Search results query term
|
|
538
549
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
539
|
-
* @param {number} parameters.
|
|
540
|
-
* @param {string[]} [parameters.
|
|
550
|
+
* @param {number} parameters.numResults - Total number of results
|
|
551
|
+
* @param {string[]} [parameters.itemIds] - List of product item unique identifiers in search results listing
|
|
541
552
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
542
553
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
543
554
|
* @param {number} userParameters.clientId - Client ID, utilized to personalize results
|
|
@@ -557,8 +568,8 @@ class Tracker {
|
|
|
557
568
|
* constructorio.tracker.trackSearchResultsLoaded(
|
|
558
569
|
* 'T-Shirt',
|
|
559
570
|
* {
|
|
560
|
-
*
|
|
561
|
-
*
|
|
571
|
+
* numResults: 167,
|
|
572
|
+
* itemIds: ['KMH876', 'KMH140', 'KMH437'],
|
|
562
573
|
* },
|
|
563
574
|
* {
|
|
564
575
|
* sessionId: 1,
|
|
@@ -576,18 +587,25 @@ class Tracker {
|
|
|
576
587
|
if (parameters && typeof parameters === 'object' && !Array.isArray(parameters)) {
|
|
577
588
|
const url = `${this.options.serviceUrl}/behavior?`;
|
|
578
589
|
const queryParams = { action: 'search-results', term };
|
|
579
|
-
const {
|
|
590
|
+
const {
|
|
591
|
+
num_results,
|
|
592
|
+
numResults = num_results,
|
|
593
|
+
customer_ids,
|
|
594
|
+
customerIds = customer_ids,
|
|
595
|
+
item_ids,
|
|
596
|
+
itemIds = item_ids,
|
|
597
|
+
} = parameters;
|
|
580
598
|
let customerIDs;
|
|
581
599
|
|
|
582
|
-
if (!helpers.isNil(
|
|
583
|
-
queryParams.num_results =
|
|
600
|
+
if (!helpers.isNil(numResults)) {
|
|
601
|
+
queryParams.num_results = numResults;
|
|
584
602
|
}
|
|
585
603
|
|
|
586
604
|
// Ensure support for both item_ids and customer_ids as parameters
|
|
587
|
-
if (
|
|
588
|
-
customerIDs =
|
|
589
|
-
} else if (
|
|
590
|
-
customerIDs =
|
|
605
|
+
if (itemIds && Array.isArray(itemIds)) {
|
|
606
|
+
customerIDs = itemIds;
|
|
607
|
+
} else if (customerIds && Array.isArray(customerIds)) {
|
|
608
|
+
customerIDs = customerIds;
|
|
591
609
|
}
|
|
592
610
|
|
|
593
611
|
if (customerIDs && Array.isArray(customerIDs) && customerIDs.length) {
|
|
@@ -618,11 +636,11 @@ class Tracker {
|
|
|
618
636
|
* @function trackSearchResultClick
|
|
619
637
|
* @param {string} term - Search results query term
|
|
620
638
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
621
|
-
* @param {string} parameters.
|
|
622
|
-
* @param {string} parameters.
|
|
623
|
-
* @param {string} [parameters.
|
|
624
|
-
* @param {string} [parameters.
|
|
625
|
-
* @param {string} [parameters.
|
|
639
|
+
* @param {string} parameters.itemName - Product item name
|
|
640
|
+
* @param {string} parameters.itemId - Product item unique identifier
|
|
641
|
+
* @param {string} [parameters.variationId] - Product item variation unique identifier
|
|
642
|
+
* @param {string} [parameters.resultId] - Search result identifier (returned in response from Constructor)
|
|
643
|
+
* @param {string} [parameters.itemIsConvertible] - Whether or not an item is available for a conversion
|
|
626
644
|
* @param {string} [parameters.section] - The section name for the item Ex. "Products"
|
|
627
645
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
628
646
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
@@ -643,9 +661,9 @@ class Tracker {
|
|
|
643
661
|
* constructorio.tracker.trackSearchResultClick(
|
|
644
662
|
* 'T-Shirt',
|
|
645
663
|
* {
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
664
|
+
* itemName: 'Red T-Shirt',
|
|
665
|
+
* itemId: 'KMH876',
|
|
666
|
+
* resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
|
|
649
667
|
* },
|
|
650
668
|
* {
|
|
651
669
|
* sessionId: 1,
|
|
@@ -666,38 +684,40 @@ class Tracker {
|
|
|
666
684
|
const {
|
|
667
685
|
item_name,
|
|
668
686
|
name,
|
|
687
|
+
itemName = item_name || name,
|
|
669
688
|
item_id,
|
|
689
|
+
itemId = item_id,
|
|
670
690
|
customer_id,
|
|
691
|
+
customerId = customer_id || itemId,
|
|
671
692
|
variation_id,
|
|
693
|
+
variationId = variation_id,
|
|
672
694
|
result_id,
|
|
695
|
+
resultId = result_id,
|
|
673
696
|
item_is_convertible,
|
|
697
|
+
itemIsConvertible = item_is_convertible,
|
|
674
698
|
section,
|
|
675
699
|
} = parameters;
|
|
676
700
|
|
|
677
701
|
// Ensure support for both item_name and name as parameters
|
|
678
|
-
if (
|
|
679
|
-
queryParams.name =
|
|
680
|
-
} else if (name) {
|
|
681
|
-
queryParams.name = name;
|
|
702
|
+
if (itemName) {
|
|
703
|
+
queryParams.name = itemName;
|
|
682
704
|
}
|
|
683
705
|
|
|
684
706
|
// Ensure support for both item_id and customer_id as parameters
|
|
685
|
-
if (
|
|
686
|
-
queryParams.customer_id =
|
|
687
|
-
} else if (customer_id) {
|
|
688
|
-
queryParams.customer_id = customer_id;
|
|
707
|
+
if (customerId) {
|
|
708
|
+
queryParams.customer_id = customerId;
|
|
689
709
|
}
|
|
690
710
|
|
|
691
|
-
if (
|
|
692
|
-
queryParams.variation_id =
|
|
711
|
+
if (variationId) {
|
|
712
|
+
queryParams.variation_id = variationId;
|
|
693
713
|
}
|
|
694
714
|
|
|
695
|
-
if (
|
|
696
|
-
queryParams.result_id =
|
|
715
|
+
if (resultId) {
|
|
716
|
+
queryParams.result_id = resultId;
|
|
697
717
|
}
|
|
698
718
|
|
|
699
|
-
if (typeof
|
|
700
|
-
queryParams.item_is_convertible =
|
|
719
|
+
if (typeof itemIsConvertible === 'boolean') {
|
|
720
|
+
queryParams.item_is_convertible = itemIsConvertible;
|
|
701
721
|
}
|
|
702
722
|
|
|
703
723
|
if (section) {
|
|
@@ -728,14 +748,13 @@ class Tracker {
|
|
|
728
748
|
* @function trackConversion
|
|
729
749
|
* @param {string} [term] - Search results query term that led to conversion event
|
|
730
750
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
731
|
-
* @param {string} parameters.
|
|
751
|
+
* @param {string} parameters.itemId - Product item unique identifier
|
|
732
752
|
* @param {number} [parameters.revenue] - Sale price if available, otherwise the regular (retail) price of item
|
|
733
|
-
* @param {string} [parameters.
|
|
734
|
-
* @param {string} [parameters.
|
|
753
|
+
* @param {string} [parameters.itemName] - Product item name
|
|
754
|
+
* @param {string} [parameters.variationId] - Product item variation unique identifier
|
|
735
755
|
* @param {string} [parameters.type='add_to_cart'] - Conversion type
|
|
736
|
-
* @param {boolean} [parameters.
|
|
737
|
-
* @param {string} [parameters.
|
|
738
|
-
* @param {string} [parameters.result_id] - Result identifier (returned in response from Constructor)
|
|
756
|
+
* @param {boolean} [parameters.isCustomType] - Specify if type is custom conversion type
|
|
757
|
+
* @param {string} [parameters.displayName] - Display name for the custom conversion type
|
|
739
758
|
* @param {string} [parameters.section] - Index section
|
|
740
759
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
741
760
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
@@ -757,12 +776,11 @@ class Tracker {
|
|
|
757
776
|
* constructorio.tracker.trackConversion(
|
|
758
777
|
* 'T-Shirt',
|
|
759
778
|
* {
|
|
760
|
-
*
|
|
779
|
+
* itemId: 'KMH876',
|
|
761
780
|
* revenue: 12.00,
|
|
762
|
-
*
|
|
763
|
-
*
|
|
781
|
+
* itemName: 'Red T-Shirt',
|
|
782
|
+
* variationId: 'KMH879-7632',
|
|
764
783
|
* type: 'like',
|
|
765
|
-
* result_id: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
|
|
766
784
|
* section: 'Products',
|
|
767
785
|
* },
|
|
768
786
|
* {
|
|
@@ -784,32 +802,33 @@ class Tracker {
|
|
|
784
802
|
const {
|
|
785
803
|
name,
|
|
786
804
|
item_name,
|
|
805
|
+
itemName = item_name || name,
|
|
787
806
|
item_id,
|
|
788
807
|
customer_id,
|
|
808
|
+
itemId = item_id || customer_id,
|
|
789
809
|
variation_id,
|
|
810
|
+
variationId = variation_id,
|
|
790
811
|
revenue,
|
|
791
812
|
section = 'Products',
|
|
792
813
|
display_name,
|
|
814
|
+
displayName = display_name,
|
|
793
815
|
type,
|
|
794
816
|
is_custom_type,
|
|
817
|
+
isCustomType = is_custom_type,
|
|
795
818
|
} = parameters;
|
|
796
819
|
|
|
797
820
|
// Ensure support for both item_id and customer_id as parameters
|
|
798
|
-
if (
|
|
799
|
-
bodyParams.item_id =
|
|
800
|
-
} else if (customer_id) {
|
|
801
|
-
bodyParams.item_id = customer_id;
|
|
821
|
+
if (itemId) {
|
|
822
|
+
bodyParams.item_id = itemId;
|
|
802
823
|
}
|
|
803
824
|
|
|
804
825
|
// Ensure support for both item_name and name as parameters
|
|
805
|
-
if (
|
|
806
|
-
bodyParams.item_name =
|
|
807
|
-
} else if (name) {
|
|
808
|
-
bodyParams.item_name = name;
|
|
826
|
+
if (itemName) {
|
|
827
|
+
bodyParams.item_name = itemName;
|
|
809
828
|
}
|
|
810
829
|
|
|
811
|
-
if (
|
|
812
|
-
bodyParams.variation_id =
|
|
830
|
+
if (variationId) {
|
|
831
|
+
bodyParams.variation_id = variationId;
|
|
813
832
|
}
|
|
814
833
|
|
|
815
834
|
if (revenue) {
|
|
@@ -829,12 +848,12 @@ class Tracker {
|
|
|
829
848
|
bodyParams.type = type;
|
|
830
849
|
}
|
|
831
850
|
|
|
832
|
-
if (
|
|
833
|
-
bodyParams.is_custom_type =
|
|
851
|
+
if (isCustomType) {
|
|
852
|
+
bodyParams.is_custom_type = isCustomType;
|
|
834
853
|
}
|
|
835
854
|
|
|
836
|
-
if (
|
|
837
|
-
bodyParams.display_name =
|
|
855
|
+
if (displayName) {
|
|
856
|
+
bodyParams.display_name = displayName;
|
|
838
857
|
}
|
|
839
858
|
|
|
840
859
|
const requestUrl = `${requestPath}${applyParamsAsString(queryParams, userParameters, this.options)}`;
|
|
@@ -863,7 +882,7 @@ class Tracker {
|
|
|
863
882
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
864
883
|
* @param {object[]} parameters.items - List of product item objects
|
|
865
884
|
* @param {number} parameters.revenue - The subtotal (excluding taxes, shipping, etc.) of the entire order
|
|
866
|
-
* @param {string} [parameters.
|
|
885
|
+
* @param {string} [parameters.orderId] - Unique order identifier
|
|
867
886
|
* @param {string} [parameters.section] - Index section
|
|
868
887
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
869
888
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
@@ -883,9 +902,9 @@ class Tracker {
|
|
|
883
902
|
* @example
|
|
884
903
|
* constructorio.tracker.trackPurchase(
|
|
885
904
|
* {
|
|
886
|
-
* items: [{
|
|
905
|
+
* items: [{ itemId: 'KMH876' }, { itemId: 'KMH140' }],
|
|
887
906
|
* revenue: 12.00,
|
|
888
|
-
*
|
|
907
|
+
* orderId: 'OUNXBG2HMA',
|
|
889
908
|
* section: 'Products',
|
|
890
909
|
* },
|
|
891
910
|
* {
|
|
@@ -903,14 +922,20 @@ class Tracker {
|
|
|
903
922
|
const requestPath = `${this.options.serviceUrl}/v2/behavioral_action/purchase?`;
|
|
904
923
|
const queryParams = {};
|
|
905
924
|
const bodyParams = {};
|
|
906
|
-
const {
|
|
925
|
+
const {
|
|
926
|
+
items,
|
|
927
|
+
revenue,
|
|
928
|
+
order_id,
|
|
929
|
+
orderId = order_id,
|
|
930
|
+
section,
|
|
931
|
+
} = parameters;
|
|
907
932
|
|
|
908
|
-
if (
|
|
909
|
-
bodyParams.order_id =
|
|
933
|
+
if (orderId) {
|
|
934
|
+
bodyParams.order_id = orderId;
|
|
910
935
|
}
|
|
911
936
|
|
|
912
937
|
if (items && Array.isArray(items)) {
|
|
913
|
-
bodyParams.items = items.slice(0, 100);
|
|
938
|
+
bodyParams.items = items.slice(0, 100).map((item) => helpers.toSnakeCaseKeys(item, false));
|
|
914
939
|
}
|
|
915
940
|
|
|
916
941
|
if (revenue) {
|
|
@@ -948,12 +973,11 @@ class Tracker {
|
|
|
948
973
|
* @function trackRecommendationView
|
|
949
974
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
950
975
|
* @param {string} parameters.url - Current page URL
|
|
951
|
-
* @param {string} parameters.
|
|
952
|
-
* @param {number} parameters.
|
|
953
|
-
* @param {
|
|
954
|
-
* @param {number} [parameters.
|
|
955
|
-
* @param {
|
|
956
|
-
* @param {string} [parameters.result_id] - Recommendation result identifier (returned in response from Constructor)
|
|
976
|
+
* @param {string} parameters.podId - Pod identifier
|
|
977
|
+
* @param {number} parameters.numResultsViewed - Number of results viewed
|
|
978
|
+
* @param {number} [parameters.resultCount] - Total number of results
|
|
979
|
+
* @param {number} [parameters.resultPage] - Page number of results
|
|
980
|
+
* @param {string} [parameters.resultId] - Recommendation result identifier (returned in response from Constructor)
|
|
957
981
|
* @param {string} [parameters.section="Products"] - Results section
|
|
958
982
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
959
983
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
@@ -973,12 +997,12 @@ class Tracker {
|
|
|
973
997
|
* @example
|
|
974
998
|
* constructorio.tracker.trackRecommendationView(
|
|
975
999
|
* {
|
|
976
|
-
*
|
|
977
|
-
*
|
|
978
|
-
*
|
|
1000
|
+
* resultCount: 22,
|
|
1001
|
+
* resultPage: 2,
|
|
1002
|
+
* resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
|
|
979
1003
|
* url: 'https://demo.constructor.io/sandbox/farmstand',
|
|
980
|
-
*
|
|
981
|
-
*
|
|
1004
|
+
* podId: '019927c2-f955-4020',
|
|
1005
|
+
* numResultsViewed: 3,
|
|
982
1006
|
* },
|
|
983
1007
|
* {
|
|
984
1008
|
* sessionId: 1,
|
|
@@ -996,24 +1020,29 @@ class Tracker {
|
|
|
996
1020
|
const bodyParams = {};
|
|
997
1021
|
const {
|
|
998
1022
|
result_count,
|
|
1023
|
+
resultCount = result_count,
|
|
999
1024
|
result_page,
|
|
1025
|
+
resultPage = result_page,
|
|
1000
1026
|
result_id,
|
|
1027
|
+
resultId = result_id,
|
|
1001
1028
|
section,
|
|
1002
1029
|
url,
|
|
1003
1030
|
pod_id,
|
|
1031
|
+
podId = pod_id,
|
|
1004
1032
|
num_results_viewed,
|
|
1033
|
+
numResultsViewed = num_results_viewed,
|
|
1005
1034
|
} = parameters;
|
|
1006
1035
|
|
|
1007
|
-
if (!helpers.isNil(
|
|
1008
|
-
bodyParams.result_count =
|
|
1036
|
+
if (!helpers.isNil(resultCount)) {
|
|
1037
|
+
bodyParams.result_count = resultCount;
|
|
1009
1038
|
}
|
|
1010
1039
|
|
|
1011
|
-
if (!helpers.isNil(
|
|
1012
|
-
bodyParams.result_page =
|
|
1040
|
+
if (!helpers.isNil(resultPage)) {
|
|
1041
|
+
bodyParams.result_page = resultPage;
|
|
1013
1042
|
}
|
|
1014
1043
|
|
|
1015
|
-
if (
|
|
1016
|
-
bodyParams.result_id =
|
|
1044
|
+
if (resultId) {
|
|
1045
|
+
bodyParams.result_id = resultId;
|
|
1017
1046
|
}
|
|
1018
1047
|
|
|
1019
1048
|
if (section) {
|
|
@@ -1026,12 +1055,12 @@ class Tracker {
|
|
|
1026
1055
|
bodyParams.url = url;
|
|
1027
1056
|
}
|
|
1028
1057
|
|
|
1029
|
-
if (
|
|
1030
|
-
bodyParams.pod_id =
|
|
1058
|
+
if (podId) {
|
|
1059
|
+
bodyParams.pod_id = podId;
|
|
1031
1060
|
}
|
|
1032
1061
|
|
|
1033
|
-
if (!helpers.isNil(
|
|
1034
|
-
bodyParams.num_results_viewed =
|
|
1062
|
+
if (!helpers.isNil(numResultsViewed)) {
|
|
1063
|
+
bodyParams.num_results_viewed = numResultsViewed;
|
|
1035
1064
|
}
|
|
1036
1065
|
|
|
1037
1066
|
const requestUrl = `${requestPath}${applyParamsAsString({}, userParameters, this.options)}`;
|
|
@@ -1058,17 +1087,17 @@ class Tracker {
|
|
|
1058
1087
|
*
|
|
1059
1088
|
* @function trackRecommendationClick
|
|
1060
1089
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
1061
|
-
* @param {string} parameters.
|
|
1062
|
-
* @param {string} parameters.
|
|
1063
|
-
* @param {string} parameters.
|
|
1064
|
-
* @param {string} parameters.
|
|
1065
|
-
* @param {string} [parameters.
|
|
1090
|
+
* @param {string} parameters.podId - Pod identifier
|
|
1091
|
+
* @param {string} parameters.strategyId - Strategy identifier
|
|
1092
|
+
* @param {string} parameters.itemId - Product item unique identifier
|
|
1093
|
+
* @param {string} parameters.itemName - Product item name
|
|
1094
|
+
* @param {string} [parameters.variationId] - Product item variation unique identifier
|
|
1066
1095
|
* @param {string} [parameters.section="Products"] - Index section
|
|
1067
|
-
* @param {string} [parameters.
|
|
1068
|
-
* @param {number} [parameters.
|
|
1069
|
-
* @param {number} [parameters.
|
|
1070
|
-
* @param {number} [parameters.
|
|
1071
|
-
* @param {number} [parameters.
|
|
1096
|
+
* @param {string} [parameters.resultId] - Recommendation result identifier (returned in response from Constructor)
|
|
1097
|
+
* @param {number} [parameters.resultCount] - Total number of results
|
|
1098
|
+
* @param {number} [parameters.resultPage] - Page number of results
|
|
1099
|
+
* @param {number} [parameters.resultPositionOnPage] - Position of result on page
|
|
1100
|
+
* @param {number} [parameters.numResultsPerPage] - Number of results on page
|
|
1072
1101
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
1073
1102
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
1074
1103
|
* @param {number} userParameters.clientId - Client ID, utilized to personalize results
|
|
@@ -1087,15 +1116,15 @@ class Tracker {
|
|
|
1087
1116
|
* @example
|
|
1088
1117
|
* constructorio.tracker.trackRecommendationClick(
|
|
1089
1118
|
* {
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1092
|
-
*
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1096
|
-
*
|
|
1097
|
-
*
|
|
1098
|
-
*
|
|
1119
|
+
* variationId: 'KMH879-7632',
|
|
1120
|
+
* resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
|
|
1121
|
+
* resultCount: 22,
|
|
1122
|
+
* resultPage: 2,
|
|
1123
|
+
* resultPositionOnPage: 2,
|
|
1124
|
+
* numResultsPerPage: 12,
|
|
1125
|
+
* podId: '019927c2-f955-4020',
|
|
1126
|
+
* strategyId: 'complimentary',
|
|
1127
|
+
* itemId: 'KMH876',
|
|
1099
1128
|
* },
|
|
1100
1129
|
* {
|
|
1101
1130
|
* sessionId: 1,
|
|
@@ -1113,20 +1142,30 @@ class Tracker {
|
|
|
1113
1142
|
const bodyParams = {};
|
|
1114
1143
|
const {
|
|
1115
1144
|
variation_id,
|
|
1145
|
+
variationId = variation_id,
|
|
1116
1146
|
section,
|
|
1117
1147
|
result_id,
|
|
1148
|
+
resultId = result_id,
|
|
1118
1149
|
result_count,
|
|
1150
|
+
resultCount = result_count,
|
|
1119
1151
|
result_page,
|
|
1152
|
+
resultPage = result_page,
|
|
1120
1153
|
result_position_on_page,
|
|
1154
|
+
resultPositionOnPage = result_position_on_page,
|
|
1121
1155
|
num_results_per_page,
|
|
1156
|
+
numResultsPerPage = num_results_per_page,
|
|
1122
1157
|
pod_id,
|
|
1158
|
+
podId = pod_id,
|
|
1123
1159
|
strategy_id,
|
|
1160
|
+
strategyId = strategy_id,
|
|
1124
1161
|
item_id,
|
|
1162
|
+
itemId = item_id,
|
|
1125
1163
|
item_name,
|
|
1164
|
+
itemName = item_name,
|
|
1126
1165
|
} = parameters;
|
|
1127
1166
|
|
|
1128
|
-
if (
|
|
1129
|
-
bodyParams.variation_id =
|
|
1167
|
+
if (variationId) {
|
|
1168
|
+
bodyParams.variation_id = variationId;
|
|
1130
1169
|
}
|
|
1131
1170
|
|
|
1132
1171
|
if (section) {
|
|
@@ -1135,40 +1174,40 @@ class Tracker {
|
|
|
1135
1174
|
bodyParams.section = 'Products';
|
|
1136
1175
|
}
|
|
1137
1176
|
|
|
1138
|
-
if (
|
|
1139
|
-
bodyParams.result_id =
|
|
1177
|
+
if (resultId) {
|
|
1178
|
+
bodyParams.result_id = resultId;
|
|
1140
1179
|
}
|
|
1141
1180
|
|
|
1142
|
-
if (!helpers.isNil(
|
|
1143
|
-
bodyParams.result_count =
|
|
1181
|
+
if (!helpers.isNil(resultCount)) {
|
|
1182
|
+
bodyParams.result_count = resultCount;
|
|
1144
1183
|
}
|
|
1145
1184
|
|
|
1146
|
-
if (!helpers.isNil(
|
|
1147
|
-
bodyParams.result_page =
|
|
1185
|
+
if (!helpers.isNil(resultPage)) {
|
|
1186
|
+
bodyParams.result_page = resultPage;
|
|
1148
1187
|
}
|
|
1149
1188
|
|
|
1150
|
-
if (!helpers.isNil(
|
|
1151
|
-
bodyParams.result_position_on_page =
|
|
1189
|
+
if (!helpers.isNil(resultPositionOnPage)) {
|
|
1190
|
+
bodyParams.result_position_on_page = resultPositionOnPage;
|
|
1152
1191
|
}
|
|
1153
1192
|
|
|
1154
|
-
if (!helpers.isNil(
|
|
1155
|
-
bodyParams.num_results_per_page =
|
|
1193
|
+
if (!helpers.isNil(numResultsPerPage)) {
|
|
1194
|
+
bodyParams.num_results_per_page = numResultsPerPage;
|
|
1156
1195
|
}
|
|
1157
1196
|
|
|
1158
|
-
if (
|
|
1159
|
-
bodyParams.pod_id =
|
|
1197
|
+
if (podId) {
|
|
1198
|
+
bodyParams.pod_id = podId;
|
|
1160
1199
|
}
|
|
1161
1200
|
|
|
1162
|
-
if (
|
|
1163
|
-
bodyParams.strategy_id =
|
|
1201
|
+
if (strategyId) {
|
|
1202
|
+
bodyParams.strategy_id = strategyId;
|
|
1164
1203
|
}
|
|
1165
1204
|
|
|
1166
|
-
if (
|
|
1167
|
-
bodyParams.item_id =
|
|
1205
|
+
if (itemId) {
|
|
1206
|
+
bodyParams.item_id = itemId;
|
|
1168
1207
|
}
|
|
1169
1208
|
|
|
1170
|
-
if (
|
|
1171
|
-
bodyParams.item_name =
|
|
1209
|
+
if (itemName) {
|
|
1210
|
+
bodyParams.item_name = itemName;
|
|
1172
1211
|
}
|
|
1173
1212
|
|
|
1174
1213
|
const requestUrl = `${requestPath}${applyParamsAsString({}, userParameters, this.options)}`;
|
|
@@ -1196,15 +1235,15 @@ class Tracker {
|
|
|
1196
1235
|
* @function trackBrowseResultsLoaded
|
|
1197
1236
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
1198
1237
|
* @param {string} parameters.url - Current page URL
|
|
1199
|
-
* @param {string} parameters.
|
|
1200
|
-
* @param {string} parameters.
|
|
1238
|
+
* @param {string} parameters.filterName - Filter name
|
|
1239
|
+
* @param {string} parameters.filterValue - Filter value
|
|
1201
1240
|
* @param {string} [parameters.section="Products"] - Index section
|
|
1202
|
-
* @param {number} [parameters.
|
|
1203
|
-
* @param {number} [parameters.
|
|
1204
|
-
* @param {string} [parameters.
|
|
1205
|
-
* @param {object} [parameters.
|
|
1206
|
-
* @param {string} [parameters.
|
|
1207
|
-
* @param {string} [parameters.
|
|
1241
|
+
* @param {number} [parameters.resultCount] - Total number of results
|
|
1242
|
+
* @param {number} [parameters.resultPage] - Page number of results
|
|
1243
|
+
* @param {string} [parameters.resultId] - Browse result identifier (returned in response from Constructor)
|
|
1244
|
+
* @param {object} [parameters.selectedFilters] - Selected filters
|
|
1245
|
+
* @param {string} [parameters.sortOrder] - Sort order ('ascending' or 'descending')
|
|
1246
|
+
* @param {string} [parameters.sortBy] - Sorting method
|
|
1208
1247
|
* @param {object[]} [parameters.items] - List of product item objects
|
|
1209
1248
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
1210
1249
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
@@ -1224,16 +1263,16 @@ class Tracker {
|
|
|
1224
1263
|
* @example
|
|
1225
1264
|
* constructorio.tracker.trackBrowseResultsLoaded(
|
|
1226
1265
|
* {
|
|
1227
|
-
*
|
|
1228
|
-
*
|
|
1229
|
-
*
|
|
1230
|
-
*
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
* items: [{
|
|
1266
|
+
* resultCount: 22,
|
|
1267
|
+
* resultPage: 2,
|
|
1268
|
+
* resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
|
|
1269
|
+
* selectedFilters: { brand: ['foo'], color: ['black'] },
|
|
1270
|
+
* sortOrder: 'ascending',
|
|
1271
|
+
* sortBy: 'price',
|
|
1272
|
+
* items: [{ itemId: 'KMH876' }, { itemId: 'KMH140' }],
|
|
1234
1273
|
* url: 'https://demo.constructor.io/sandbox/farmstand',
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1274
|
+
* filterName: 'brand',
|
|
1275
|
+
* filterValue: 'XYZ',
|
|
1237
1276
|
* },
|
|
1238
1277
|
* {
|
|
1239
1278
|
* sessionId: 1,
|
|
@@ -1252,14 +1291,22 @@ class Tracker {
|
|
|
1252
1291
|
const {
|
|
1253
1292
|
section,
|
|
1254
1293
|
result_count,
|
|
1294
|
+
resultCount = result_count,
|
|
1255
1295
|
result_page,
|
|
1296
|
+
resultPage = result_page,
|
|
1256
1297
|
result_id,
|
|
1298
|
+
resultId = result_id,
|
|
1257
1299
|
selected_filters,
|
|
1300
|
+
selectedFilters = selected_filters,
|
|
1258
1301
|
url,
|
|
1259
1302
|
sort_order,
|
|
1303
|
+
sortOrder = sort_order,
|
|
1260
1304
|
sort_by,
|
|
1305
|
+
sortBy = sort_by,
|
|
1261
1306
|
filter_name,
|
|
1307
|
+
filterName = filter_name,
|
|
1262
1308
|
filter_value,
|
|
1309
|
+
filterValue = filter_value,
|
|
1263
1310
|
items,
|
|
1264
1311
|
} = parameters;
|
|
1265
1312
|
|
|
@@ -1269,44 +1316,44 @@ class Tracker {
|
|
|
1269
1316
|
bodyParams.section = 'Products';
|
|
1270
1317
|
}
|
|
1271
1318
|
|
|
1272
|
-
if (!helpers.isNil(
|
|
1273
|
-
bodyParams.result_count =
|
|
1319
|
+
if (!helpers.isNil(resultCount)) {
|
|
1320
|
+
bodyParams.result_count = resultCount;
|
|
1274
1321
|
}
|
|
1275
1322
|
|
|
1276
|
-
if (!helpers.isNil(
|
|
1277
|
-
bodyParams.result_page =
|
|
1323
|
+
if (!helpers.isNil(resultPage)) {
|
|
1324
|
+
bodyParams.result_page = resultPage;
|
|
1278
1325
|
}
|
|
1279
1326
|
|
|
1280
|
-
if (
|
|
1281
|
-
bodyParams.result_id =
|
|
1327
|
+
if (resultId) {
|
|
1328
|
+
bodyParams.result_id = resultId;
|
|
1282
1329
|
}
|
|
1283
1330
|
|
|
1284
|
-
if (
|
|
1285
|
-
bodyParams.selected_filters =
|
|
1331
|
+
if (selectedFilters) {
|
|
1332
|
+
bodyParams.selected_filters = selectedFilters;
|
|
1286
1333
|
}
|
|
1287
1334
|
|
|
1288
1335
|
if (url) {
|
|
1289
1336
|
bodyParams.url = url;
|
|
1290
1337
|
}
|
|
1291
1338
|
|
|
1292
|
-
if (
|
|
1293
|
-
bodyParams.sort_order =
|
|
1339
|
+
if (sortOrder) {
|
|
1340
|
+
bodyParams.sort_order = sortOrder;
|
|
1294
1341
|
}
|
|
1295
1342
|
|
|
1296
|
-
if (
|
|
1297
|
-
bodyParams.sort_by =
|
|
1343
|
+
if (sortBy) {
|
|
1344
|
+
bodyParams.sort_by = sortBy;
|
|
1298
1345
|
}
|
|
1299
1346
|
|
|
1300
|
-
if (
|
|
1301
|
-
bodyParams.filter_name =
|
|
1347
|
+
if (filterName) {
|
|
1348
|
+
bodyParams.filter_name = filterName;
|
|
1302
1349
|
}
|
|
1303
1350
|
|
|
1304
|
-
if (
|
|
1305
|
-
bodyParams.filter_value =
|
|
1351
|
+
if (filterValue) {
|
|
1352
|
+
bodyParams.filter_value = filterValue;
|
|
1306
1353
|
}
|
|
1307
1354
|
|
|
1308
1355
|
if (items && Array.isArray(items)) {
|
|
1309
|
-
bodyParams.items = items.slice(0, 100);
|
|
1356
|
+
bodyParams.items = items.slice(0, 100).map((item) => helpers.toSnakeCaseKeys(item, false));
|
|
1310
1357
|
}
|
|
1311
1358
|
|
|
1312
1359
|
const requestUrl = `${requestPath}${applyParamsAsString({}, userParameters, this.options)}`;
|
|
@@ -1333,17 +1380,17 @@ class Tracker {
|
|
|
1333
1380
|
*
|
|
1334
1381
|
* @function trackBrowseResultClick
|
|
1335
1382
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
1336
|
-
* @param {string} parameters.
|
|
1337
|
-
* @param {string} parameters.
|
|
1338
|
-
* @param {string} parameters.
|
|
1383
|
+
* @param {string} parameters.filterName - Filter name
|
|
1384
|
+
* @param {string} parameters.filterValue - Filter value
|
|
1385
|
+
* @param {string} parameters.itemId - Product item unique identifier
|
|
1339
1386
|
* @param {string} [parameters.section="Products"] - Index section
|
|
1340
|
-
* @param {string} [parameters.
|
|
1341
|
-
* @param {string} [parameters.
|
|
1342
|
-
* @param {number} [parameters.
|
|
1343
|
-
* @param {number} [parameters.
|
|
1344
|
-
* @param {number} [parameters.
|
|
1345
|
-
* @param {number} [parameters.
|
|
1346
|
-
* @param {object} [parameters.
|
|
1387
|
+
* @param {string} [parameters.variationId] - Product item variation unique identifier
|
|
1388
|
+
* @param {string} [parameters.resultId] - Browse result identifier (returned in response from Constructor)
|
|
1389
|
+
* @param {number} [parameters.resultCount] - Total number of results
|
|
1390
|
+
* @param {number} [parameters.resultPage] - Page number of results
|
|
1391
|
+
* @param {number} [parameters.resultPositionOnPage] - Position of clicked item
|
|
1392
|
+
* @param {number} [parameters.numResultsPerPage] - Number of results shown
|
|
1393
|
+
* @param {object} [parameters.selectedFilters] - Selected filters
|
|
1347
1394
|
* @param {object} userParameters - Parameters relevant to the user request
|
|
1348
1395
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
1349
1396
|
* @param {number} userParameters.clientId - Client ID, utilized to personalize results
|
|
@@ -1362,16 +1409,16 @@ class Tracker {
|
|
|
1362
1409
|
* @example
|
|
1363
1410
|
* constructorio.tracker.trackBrowseResultClick(
|
|
1364
1411
|
* {
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
1368
|
-
*
|
|
1369
|
-
*
|
|
1370
|
-
*
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1374
|
-
*
|
|
1412
|
+
* variationId: 'KMH879-7632',
|
|
1413
|
+
* resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
|
|
1414
|
+
* resultCount: 22,
|
|
1415
|
+
* resultPage: 2,
|
|
1416
|
+
* resultPositionOnPage: 2,
|
|
1417
|
+
* numResultsPerPage: 12,
|
|
1418
|
+
* selectedFilters: { brand: ['foo'], color: ['black'] },
|
|
1419
|
+
* filterName: 'brand',
|
|
1420
|
+
* filterValue: 'XYZ',
|
|
1421
|
+
* itemId: 'KMH876',
|
|
1375
1422
|
* },
|
|
1376
1423
|
* {
|
|
1377
1424
|
* sessionId: 1,
|
|
@@ -1390,15 +1437,25 @@ class Tracker {
|
|
|
1390
1437
|
const {
|
|
1391
1438
|
section,
|
|
1392
1439
|
variation_id,
|
|
1440
|
+
variationId = variation_id,
|
|
1393
1441
|
result_id,
|
|
1442
|
+
resultId = result_id,
|
|
1394
1443
|
result_count,
|
|
1444
|
+
resultCount = result_count,
|
|
1395
1445
|
result_page,
|
|
1446
|
+
resultPage = result_page,
|
|
1396
1447
|
result_position_on_page,
|
|
1448
|
+
resultPositionOnPage = result_position_on_page,
|
|
1397
1449
|
num_results_per_page,
|
|
1450
|
+
numResultsPerPage = num_results_per_page,
|
|
1398
1451
|
selected_filters,
|
|
1452
|
+
selectedFilters = selected_filters,
|
|
1399
1453
|
filter_name,
|
|
1454
|
+
filterName = filter_name,
|
|
1400
1455
|
filter_value,
|
|
1456
|
+
filterValue = filter_value,
|
|
1401
1457
|
item_id,
|
|
1458
|
+
itemId = item_id,
|
|
1402
1459
|
} = parameters;
|
|
1403
1460
|
|
|
1404
1461
|
if (section) {
|
|
@@ -1407,44 +1464,44 @@ class Tracker {
|
|
|
1407
1464
|
bodyParams.section = 'Products';
|
|
1408
1465
|
}
|
|
1409
1466
|
|
|
1410
|
-
if (
|
|
1411
|
-
bodyParams.variation_id =
|
|
1467
|
+
if (variationId) {
|
|
1468
|
+
bodyParams.variation_id = variationId;
|
|
1412
1469
|
}
|
|
1413
1470
|
|
|
1414
|
-
if (
|
|
1415
|
-
bodyParams.result_id =
|
|
1471
|
+
if (resultId) {
|
|
1472
|
+
bodyParams.result_id = resultId;
|
|
1416
1473
|
}
|
|
1417
1474
|
|
|
1418
|
-
if (!helpers.isNil(
|
|
1419
|
-
bodyParams.result_count =
|
|
1475
|
+
if (!helpers.isNil(resultCount)) {
|
|
1476
|
+
bodyParams.result_count = resultCount;
|
|
1420
1477
|
}
|
|
1421
1478
|
|
|
1422
|
-
if (!helpers.isNil(
|
|
1423
|
-
bodyParams.result_page =
|
|
1479
|
+
if (!helpers.isNil(resultPage)) {
|
|
1480
|
+
bodyParams.result_page = resultPage;
|
|
1424
1481
|
}
|
|
1425
1482
|
|
|
1426
|
-
if (!helpers.isNil(
|
|
1427
|
-
bodyParams.result_position_on_page =
|
|
1483
|
+
if (!helpers.isNil(resultPositionOnPage)) {
|
|
1484
|
+
bodyParams.result_position_on_page = resultPositionOnPage;
|
|
1428
1485
|
}
|
|
1429
1486
|
|
|
1430
|
-
if (!helpers.isNil(
|
|
1431
|
-
bodyParams.num_results_per_page =
|
|
1487
|
+
if (!helpers.isNil(numResultsPerPage)) {
|
|
1488
|
+
bodyParams.num_results_per_page = numResultsPerPage;
|
|
1432
1489
|
}
|
|
1433
1490
|
|
|
1434
|
-
if (
|
|
1435
|
-
bodyParams.selected_filters =
|
|
1491
|
+
if (selectedFilters) {
|
|
1492
|
+
bodyParams.selected_filters = selectedFilters;
|
|
1436
1493
|
}
|
|
1437
1494
|
|
|
1438
|
-
if (
|
|
1439
|
-
bodyParams.filter_name =
|
|
1495
|
+
if (filterName) {
|
|
1496
|
+
bodyParams.filter_name = filterName;
|
|
1440
1497
|
}
|
|
1441
1498
|
|
|
1442
|
-
if (
|
|
1443
|
-
bodyParams.filter_value =
|
|
1499
|
+
if (filterValue) {
|
|
1500
|
+
bodyParams.filter_value = filterValue;
|
|
1444
1501
|
}
|
|
1445
1502
|
|
|
1446
|
-
if (
|
|
1447
|
-
bodyParams.item_id =
|
|
1503
|
+
if (itemId) {
|
|
1504
|
+
bodyParams.item_id = itemId;
|
|
1448
1505
|
}
|
|
1449
1506
|
|
|
1450
1507
|
const requestUrl = `${requestPath}${applyParamsAsString({}, userParameters, this.options)}`;
|
|
@@ -1471,9 +1528,9 @@ class Tracker {
|
|
|
1471
1528
|
*
|
|
1472
1529
|
* @function trackGenericResultClick
|
|
1473
1530
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
1474
|
-
* @param {string} parameters.
|
|
1475
|
-
* @param {string} [parameters.
|
|
1476
|
-
* @param {string} [parameters.
|
|
1531
|
+
* @param {string} parameters.itemId - Product item unique identifier
|
|
1532
|
+
* @param {string} [parameters.itemName] - Product item name
|
|
1533
|
+
* @param {string} [parameters.variationId] - Product item variation unique identifier
|
|
1477
1534
|
* @param {string} [parameters.section="Products"] - Index section
|
|
1478
1535
|
* @param {object} [userParameters] - Parameters relevant to the user request
|
|
1479
1536
|
* @param {number} userParameters.sessionId - Session ID, utilized to personalize results
|
|
@@ -1493,9 +1550,9 @@ class Tracker {
|
|
|
1493
1550
|
* @example
|
|
1494
1551
|
* constructorio.tracker.trackGenericResultClick(
|
|
1495
1552
|
* {
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
1498
|
-
*
|
|
1553
|
+
* itemId: 'KMH876',
|
|
1554
|
+
* itemName: 'Red T-Shirt',
|
|
1555
|
+
* variationId: 'KMH879-7632',
|
|
1499
1556
|
* },
|
|
1500
1557
|
* {
|
|
1501
1558
|
* sessionId: 1,
|
|
@@ -1508,25 +1565,28 @@ class Tracker {
|
|
|
1508
1565
|
*/
|
|
1509
1566
|
trackGenericResultClick(parameters, userParameters, networkParameters = {}) {
|
|
1510
1567
|
// Ensure required parameters are provided
|
|
1511
|
-
if (typeof parameters === 'object' && parameters && parameters.item_id) {
|
|
1568
|
+
if (typeof parameters === 'object' && parameters && (parameters.item_id || parameters.itemId)) {
|
|
1512
1569
|
const requestPath = `${this.options.serviceUrl}/v2/behavioral_action/result_click?`;
|
|
1513
1570
|
const bodyParams = {};
|
|
1514
1571
|
const {
|
|
1515
1572
|
item_id,
|
|
1573
|
+
itemId = item_id,
|
|
1516
1574
|
item_name,
|
|
1575
|
+
itemName = item_name,
|
|
1517
1576
|
variation_id,
|
|
1577
|
+
variationId = variation_id,
|
|
1518
1578
|
section,
|
|
1519
1579
|
} = parameters;
|
|
1520
1580
|
|
|
1521
1581
|
bodyParams.section = section || 'Products';
|
|
1522
|
-
bodyParams.item_id =
|
|
1582
|
+
bodyParams.item_id = itemId;
|
|
1523
1583
|
|
|
1524
|
-
if (
|
|
1525
|
-
bodyParams.item_name =
|
|
1584
|
+
if (itemName) {
|
|
1585
|
+
bodyParams.item_name = itemName;
|
|
1526
1586
|
}
|
|
1527
1587
|
|
|
1528
|
-
if (
|
|
1529
|
-
bodyParams.variation_id =
|
|
1588
|
+
if (variationId) {
|
|
1589
|
+
bodyParams.variation_id = variationId;
|
|
1530
1590
|
}
|
|
1531
1591
|
|
|
1532
1592
|
const requestUrl = `${requestPath}${applyParamsAsString({}, userParameters, this.options)}`;
|
|
@@ -1545,7 +1605,7 @@ class Tracker {
|
|
|
1545
1605
|
return true;
|
|
1546
1606
|
}
|
|
1547
1607
|
|
|
1548
|
-
return new Error('A parameters object with an "
|
|
1608
|
+
return new Error('A parameters object with an "itemId" property is required.');
|
|
1549
1609
|
}
|
|
1550
1610
|
|
|
1551
1611
|
/**
|