@constructor-io/constructorio-ui-autocomplete 1.25.2 → 1.25.3

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.
@@ -23,7 +23,7 @@ const useDownShift = (_a) => {
23
23
  // Autocomplete Select tracking
24
24
  // Recommendation Select tracking
25
25
  if (selectedItem.podId && ((_a = selectedItem.data) === null || _a === void 0 ? void 0 : _a.id) && selectedItem.strategy) {
26
- cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackRecommendationClick({
26
+ const recommendationData = {
27
27
  itemName: selectedItem.value,
28
28
  itemId: selectedItem.data.id,
29
29
  variationId: selectedItem.data.variation_id,
@@ -31,7 +31,8 @@ const useDownShift = (_a) => {
31
31
  strategyId: selectedItem.strategy.id,
32
32
  section: selectedItem.section,
33
33
  resultId: selectedItem.result_id,
34
- });
34
+ };
35
+ (0, tracking_1.trackRecommendationSelect)(cioClient, recommendationData);
35
36
  // Select tracking for all other Constructor sections:
36
37
  // (ie: Search Suggestions, Products, Custom Cio sections, etc)
37
38
  // This does not apply to custom user defined sections that aren't part of Constructor index
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trackAutocompleteSelect = exports.trackSearchSubmit = exports.trackRecommendationView = exports.isTrackingRequestSent = void 0;
3
+ exports.captureTrackingRequest = exports.trackRecommendationSelect = exports.trackAutocompleteSelect = exports.trackSearchSubmit = exports.trackRecommendationView = exports.isTrackingRequestSent = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const typeGuards_1 = require("../typeGuards");
5
6
  // eslint-disable-next-line import/no-cycle
6
7
  const beaconUtils_1 = require("./beaconUtils");
@@ -50,3 +51,30 @@ const trackAutocompleteSelect = (cioClient, itemName, autocompleteData = {}) =>
50
51
  }
51
52
  };
52
53
  exports.trackAutocompleteSelect = trackAutocompleteSelect;
54
+ const trackRecommendationSelect = (cioClient, recommendationData = {}) => {
55
+ (0, storage_1.storageRemoveItem)(beaconUtils_1.CONSTANTS.SEARCH_TERM_STORAGE_KEY);
56
+ cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackRecommendationClick(recommendationData);
57
+ };
58
+ exports.trackRecommendationSelect = trackRecommendationSelect;
59
+ const captureTrackingRequest = (urlPattern, action) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
60
+ let trackingCaptured = false;
61
+ const originalSetItem = Storage.prototype.setItem;
62
+ Storage.prototype.setItem = function setItemInterceptor(key, value) {
63
+ if (key === '_constructorio_requests') {
64
+ try {
65
+ const requests = JSON.parse(value);
66
+ if (requests.some((req) => { var _a; return (_a = req === null || req === void 0 ? void 0 : req.url) === null || _a === void 0 ? void 0 : _a.includes(urlPattern); })) {
67
+ trackingCaptured = true;
68
+ }
69
+ }
70
+ catch (e) {
71
+ // Ignore parsing errors
72
+ }
73
+ }
74
+ return originalSetItem.call(this, key, value);
75
+ };
76
+ yield action();
77
+ Storage.prototype.setItem = originalSetItem;
78
+ return trackingCaptured || isTrackingRequestSent(urlPattern);
79
+ });
80
+ exports.captureTrackingRequest = captureTrackingRequest;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.25.2';
3
+ exports.default = '1.25.3';
@@ -1,5 +1,5 @@
1
1
  import { useCombobox } from 'downshift';
2
- import { trackSearchSubmit, trackAutocompleteSelect } from '../utils/tracking';
2
+ import { trackSearchSubmit, trackAutocompleteSelect, trackRecommendationSelect, } from '../utils/tracking';
3
3
  let idCounter = 0;
4
4
  const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = '', ...rest }) => useCombobox({
5
5
  id: `cio-autocomplete-${idCounter++}`,
@@ -20,7 +20,7 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
20
20
  // Autocomplete Select tracking
21
21
  // Recommendation Select tracking
22
22
  if (selectedItem.podId && selectedItem.data?.id && selectedItem.strategy) {
23
- cioClient?.tracker.trackRecommendationClick({
23
+ const recommendationData = {
24
24
  itemName: selectedItem.value,
25
25
  itemId: selectedItem.data.id,
26
26
  variationId: selectedItem.data.variation_id,
@@ -28,7 +28,8 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
28
28
  strategyId: selectedItem.strategy.id,
29
29
  section: selectedItem.section,
30
30
  resultId: selectedItem.result_id,
31
- });
31
+ };
32
+ trackRecommendationSelect(cioClient, recommendationData);
32
33
  // Select tracking for all other Constructor sections:
33
34
  // (ie: Search Suggestions, Products, Custom Cio sections, etc)
34
35
  // This does not apply to custom user defined sections that aren't part of Constructor index
@@ -39,3 +39,28 @@ export const trackAutocompleteSelect = (cioClient, itemName, autocompleteData =
39
39
  storageRemoveItem(CONSTANTS.SEARCH_TERM_STORAGE_KEY);
40
40
  }
41
41
  };
42
+ export const trackRecommendationSelect = (cioClient, recommendationData = {}) => {
43
+ storageRemoveItem(CONSTANTS.SEARCH_TERM_STORAGE_KEY);
44
+ cioClient?.tracker.trackRecommendationClick(recommendationData);
45
+ };
46
+ export const captureTrackingRequest = async (urlPattern, action) => {
47
+ let trackingCaptured = false;
48
+ const originalSetItem = Storage.prototype.setItem;
49
+ Storage.prototype.setItem = function setItemInterceptor(key, value) {
50
+ if (key === '_constructorio_requests') {
51
+ try {
52
+ const requests = JSON.parse(value);
53
+ if (requests.some((req) => req?.url?.includes(urlPattern))) {
54
+ trackingCaptured = true;
55
+ }
56
+ }
57
+ catch (e) {
58
+ // Ignore parsing errors
59
+ }
60
+ }
61
+ return originalSetItem.call(this, key, value);
62
+ };
63
+ await action();
64
+ Storage.prototype.setItem = originalSetItem;
65
+ return trackingCaptured || isTrackingRequestSent(urlPattern);
66
+ };
@@ -1 +1 @@
1
- export default '1.25.2';
1
+ export default '1.25.3';
@@ -5,3 +5,5 @@ export declare function isTrackingRequestSent(trackingRequestUrl: string): any;
5
5
  export declare const trackRecommendationView: (target: HTMLElement, activeSectionsWithData: Section[], cioClient: Nullable<ConstructorIOClient>) => void;
6
6
  export declare const trackSearchSubmit: (cioClient: any, term: any, autocompleteData?: {}) => void;
7
7
  export declare const trackAutocompleteSelect: (cioClient: any, itemName: any, autocompleteData?: any) => void;
8
+ export declare const trackRecommendationSelect: (cioClient: any, recommendationData?: any) => void;
9
+ export declare const captureTrackingRequest: (urlPattern: string, action: () => Promise<void>) => Promise<boolean>;
@@ -1,2 +1,2 @@
1
- declare const _default: "1.25.2";
1
+ declare const _default: "1.25.3";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-autocomplete",
3
- "version": "1.25.2",
3
+ "version": "1.25.3",
4
4
  "description": "Constructor.io Autocomplete UI library for web applications",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",