@constructor-io/constructorio-ui-autocomplete 1.25.1 → 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.
- package/dist/constructorio-ui-autocomplete-bundled.js +9 -9
- package/lib/cjs/hooks/useDownShift.js +3 -2
- package/lib/cjs/utils/tracking.js +29 -1
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/hooks/useDownShift.js +4 -3
- package/lib/mjs/utils/tracking.js +25 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/utils/tracking.d.ts +2 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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;
|
package/lib/cjs/version.js
CHANGED
|
@@ -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
|
-
|
|
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
|
+
};
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.25.
|
|
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>;
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.25.
|
|
1
|
+
declare const _default: "1.25.3";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED