@searchspring/snap-controller 0.72.2 → 0.73.5
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/cjs/Autocomplete/AutocompleteController.d.ts +13 -13
- package/dist/cjs/Autocomplete/AutocompleteController.d.ts.map +1 -1
- package/dist/cjs/Autocomplete/AutocompleteController.js +151 -147
- package/dist/cjs/Recommendation/RecommendationController.d.ts +5 -13
- package/dist/cjs/Recommendation/RecommendationController.d.ts.map +1 -1
- package/dist/cjs/Recommendation/RecommendationController.js +81 -92
- package/dist/cjs/Search/SearchController.d.ts +12 -5
- package/dist/cjs/Search/SearchController.d.ts.map +1 -1
- package/dist/cjs/Search/SearchController.js +144 -168
- package/dist/cjs/utils/isClickWithinBannerLink.d.ts +2 -0
- package/dist/cjs/utils/isClickWithinBannerLink.d.ts.map +1 -0
- package/dist/cjs/utils/isClickWithinBannerLink.js +21 -0
- package/dist/esm/Autocomplete/AutocompleteController.d.ts +13 -13
- package/dist/esm/Autocomplete/AutocompleteController.d.ts.map +1 -1
- package/dist/esm/Autocomplete/AutocompleteController.js +131 -139
- package/dist/esm/Recommendation/RecommendationController.d.ts +5 -13
- package/dist/esm/Recommendation/RecommendationController.d.ts.map +1 -1
- package/dist/esm/Recommendation/RecommendationController.js +72 -80
- package/dist/esm/Search/SearchController.d.ts +12 -5
- package/dist/esm/Search/SearchController.d.ts.map +1 -1
- package/dist/esm/Search/SearchController.js +128 -165
- package/dist/esm/utils/isClickWithinBannerLink.d.ts +2 -0
- package/dist/esm/utils/isClickWithinBannerLink.d.ts.map +1 -0
- package/dist/esm/utils/isClickWithinBannerLink.js +17 -0
- package/package.json +10 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { StorageStore, Product, Banner } from '@searchspring/snap-store-mobx';
|
|
2
|
+
import { StorageStore, Product, Banner, MerchandisingContentBanner } from '@searchspring/snap-store-mobx';
|
|
3
3
|
import { AbstractController } from '../Abstract/AbstractController';
|
|
4
4
|
import { ControllerTypes } from '../types';
|
|
5
5
|
import { AutocompleteStore } from '@searchspring/snap-store-mobx';
|
|
@@ -7,14 +7,21 @@ import type { AutocompleteControllerConfig, ControllerServices, ContextVariables
|
|
|
7
7
|
import type { AutocompleteRequestModel } from '@searchspring/snapi-types';
|
|
8
8
|
export declare const INPUT_DELAY = 200;
|
|
9
9
|
type AutocompleteTrackMethods = {
|
|
10
|
+
banner: {
|
|
11
|
+
click: (e: MouseEvent, merchandisingBanner: MerchandisingContentBanner) => void;
|
|
12
|
+
clickThrough: (e: MouseEvent, merchandisingBanner: MerchandisingContentBanner) => void;
|
|
13
|
+
impression: (merchandisingBanner: MerchandisingContentBanner) => void;
|
|
14
|
+
};
|
|
10
15
|
product: {
|
|
11
|
-
clickThrough: (e: MouseEvent, result: Product) => void;
|
|
16
|
+
clickThrough: (e: MouseEvent, result: Product | Banner) => void;
|
|
12
17
|
click: (e: MouseEvent, result: Product | Banner) => void;
|
|
13
|
-
|
|
14
|
-
impression: (result: Product) => void;
|
|
18
|
+
impression: (result: Product | Banner) => void;
|
|
15
19
|
addToCart: (results: Product) => void;
|
|
16
20
|
};
|
|
17
|
-
redirect: (redirectURL
|
|
21
|
+
redirect: ({ redirectURL, responseId }: {
|
|
22
|
+
redirectURL: string;
|
|
23
|
+
responseId: string;
|
|
24
|
+
}) => void;
|
|
18
25
|
};
|
|
19
26
|
export declare class AutocompleteController extends AbstractController {
|
|
20
27
|
type: ControllerTypes;
|
|
@@ -22,14 +29,7 @@ export declare class AutocompleteController extends AbstractController {
|
|
|
22
29
|
config: AutocompleteControllerConfig;
|
|
23
30
|
storage: StorageStore;
|
|
24
31
|
private lastSearchQuery;
|
|
25
|
-
events
|
|
26
|
-
product: Record<string, {
|
|
27
|
-
click?: boolean;
|
|
28
|
-
clickThrough?: boolean;
|
|
29
|
-
impression?: boolean;
|
|
30
|
-
render?: boolean;
|
|
31
|
-
}>;
|
|
32
|
-
};
|
|
32
|
+
private events;
|
|
33
33
|
constructor(config: AutocompleteControllerConfig, { client, store, urlManager, eventManager, profiler, logger, tracker }: ControllerServices, context?: ContextVariables);
|
|
34
34
|
track: AutocompleteTrackMethods;
|
|
35
35
|
get params(): AutocompleteRequestModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteController.d.ts","sourceRoot":"","sources":["../../../src/Autocomplete/AutocompleteController.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAa,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"AutocompleteController.d.ts","sourceRoot":"","sources":["../../../src/Autocomplete/AutocompleteController.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAa,OAAO,EAAE,MAAM,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AACrH,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,4BAA4B,EAA6C,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9I,OAAO,KAAK,EAAE,wBAAwB,EAA4C,MAAM,2BAA2B,CAAC;AAiBpH,eAAO,MAAM,WAAW,MAAM,CAAC;AA+B/B,KAAK,wBAAwB,GAAG;IAC/B,MAAM,EAAE;QACP,KAAK,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,mBAAmB,EAAE,0BAA0B,KAAK,IAAI,CAAC;QAChF,YAAY,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,mBAAmB,EAAE,0BAA0B,KAAK,IAAI,CAAC;QACvF,UAAU,EAAE,CAAC,mBAAmB,EAAE,0BAA0B,KAAK,IAAI,CAAC;KACtE,CAAC;IACF,OAAO,EAAE;QACR,YAAY,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,KAAK,IAAI,CAAC;QAChE,KAAK,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,KAAK,IAAI,CAAC;QACzD,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,KAAK,IAAI,CAAC;QAC/C,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;KACtC,CAAC;IACF,QAAQ,EAAE,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC7F,CAAC;AAEF,qBAAa,sBAAuB,SAAQ,kBAAkB;IACtD,IAAI,kBAAgC;IACnC,KAAK,EAAE,iBAAiB,CAAC;IACzB,MAAM,EAAE,4BAA4B,CAAC;IACtC,OAAO,EAAE,YAAY,CAAC;IAC7B,OAAO,CAAC,eAAe,CAAqB;IAE5C,OAAO,CAAC,MAAM,CAgBP;gBAGN,MAAM,EAAE,4BAA4B,EACpC,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,kBAAkB,EAC1F,OAAO,CAAC,EAAE,gBAAgB;IA0E3B,KAAK,EAAE,wBAAwB,CAuI7B;IAEF,IAAI,MAAM,IAAI,wBAAwB,CAkDrC;IAEK,UAAU,CAAC,YAAY,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BhE,KAAK,IAAI,IAAI;IASb,QAAQ;;0BAEc,aAAa,KAAG,QAAQ,OAAO,GAAG,SAAS,CAAC;wBAiDpD,aAAa,KAAG,IAAI;uBAMrB,UAAU,KAAG,IAAI;4BAQN,MAAM,SAAS,CAAC,gBAAgB,CAAC,KAAG,QAAQ,IAAI,CAAC;mCA+ChD,MAAM,WAAW,CAAC,gBAAgB,CAAC,KAAG,IAAI;uBAqBtD,KAAK;;;;uBA0DL,UAAU,KAAG,IAAI;;MAS5B;IAEF,MAAM,IAAI,IAAI;IAgBR,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAgF3B,cAAc,QAAa,QAAQ,IAAI,CAAC,CAwBtC;IAEF,MAAM,QAAa,QAAQ,IAAI,CAAC,CA+J9B;IAEF,SAAS,cAAqB,OAAO,EAAE,GAAG,OAAO,KAAG,QAAQ,IAAI,CAAC,CAQ/D;CACF"}
|
|
@@ -71,8 +71,8 @@ var snap_store_mobx_1 = require("@searchspring/snap-store-mobx");
|
|
|
71
71
|
var AbstractController_1 = require("../Abstract/AbstractController");
|
|
72
72
|
var getParams_1 = require("../utils/getParams");
|
|
73
73
|
var types_1 = require("../types");
|
|
74
|
-
var beacon_1 = require("@searchspring/beacon");
|
|
75
74
|
var isClickWithinProductLink_1 = require("../utils/isClickWithinProductLink");
|
|
75
|
+
var isClickWithinBannerLink_1 = require("../utils/isClickWithinBannerLink");
|
|
76
76
|
var INPUT_ATTRIBUTE = 'ss-autocomplete-input';
|
|
77
77
|
exports.INPUT_DELAY = 200;
|
|
78
78
|
var KEY_ENTER = 13;
|
|
@@ -109,69 +109,149 @@ var AutocompleteController = /** @class */ (function (_super) {
|
|
|
109
109
|
var client = _a.client, store = _a.store, urlManager = _a.urlManager, eventManager = _a.eventManager, profiler = _a.profiler, logger = _a.logger, tracker = _a.tracker;
|
|
110
110
|
var _this = _super.call(this, config, { client: client, store: store, urlManager: urlManager, eventManager: eventManager, profiler: profiler, logger: logger, tracker: tracker }, context) || this;
|
|
111
111
|
_this.type = types_1.ControllerTypes.autocomplete;
|
|
112
|
-
_this.events = {
|
|
113
|
-
product: {},
|
|
114
|
-
};
|
|
112
|
+
_this.events = {};
|
|
115
113
|
_this.track = {
|
|
114
|
+
banner: {
|
|
115
|
+
impression: function (banner) {
|
|
116
|
+
var _a, _b, _c, _d;
|
|
117
|
+
var responseId = banner.responseId, uid = banner.uid;
|
|
118
|
+
if ((_c = (_b = (_a = _this.events[responseId]) === null || _a === void 0 ? void 0 : _a.banner) === null || _b === void 0 ? void 0 : _b[uid]) === null || _c === void 0 ? void 0 : _c.impression) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
var data = {
|
|
122
|
+
responseId: responseId,
|
|
123
|
+
banners: [banner],
|
|
124
|
+
results: [],
|
|
125
|
+
};
|
|
126
|
+
_this.eventManager.fire('track.banner.impression', { controller: _this, product: { uid: uid }, trackEvent: data });
|
|
127
|
+
_this.tracker.events.autocomplete.impression({ data: data, siteId: (_d = _this.config.globals) === null || _d === void 0 ? void 0 : _d.siteId });
|
|
128
|
+
_this.events[responseId].banner[uid] = _this.events[responseId].banner[uid] || {};
|
|
129
|
+
_this.events[responseId].banner[uid].impression = true;
|
|
130
|
+
},
|
|
131
|
+
click: function (e, banner) {
|
|
132
|
+
var _a, _b, _c;
|
|
133
|
+
var responseId = banner.responseId, uid = banner.uid;
|
|
134
|
+
if ((0, isClickWithinBannerLink_1.isClickWithinBannerLink)(e)) {
|
|
135
|
+
if ((_c = (_b = (_a = _this.events) === null || _a === void 0 ? void 0 : _a[responseId]) === null || _b === void 0 ? void 0 : _b.banner[uid]) === null || _c === void 0 ? void 0 : _c.clickThrough) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
_this.track.banner.clickThrough(e, banner);
|
|
139
|
+
_this.events[responseId].banner[uid] = _this.events[responseId].banner[uid] || {};
|
|
140
|
+
_this.events[responseId].banner[uid].clickThrough = true;
|
|
141
|
+
setTimeout(function () {
|
|
142
|
+
_this.events[responseId].banner[uid].clickThrough = false;
|
|
143
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
clickThrough: function (e, _a) {
|
|
147
|
+
var _b;
|
|
148
|
+
var uid = _a.uid, responseId = _a.responseId;
|
|
149
|
+
var banner = { uid: uid };
|
|
150
|
+
var data = {
|
|
151
|
+
responseId: responseId,
|
|
152
|
+
banners: [banner],
|
|
153
|
+
};
|
|
154
|
+
_this.eventManager.fire('track.banner.clickThrough', { controller: _this, event: e, product: { uid: uid }, trackEvent: data });
|
|
155
|
+
_this.tracker.events.autocomplete.clickThrough({ data: data, siteId: (_b = _this.config.globals) === null || _b === void 0 ? void 0 : _b.siteId });
|
|
156
|
+
_this.events[responseId].banner[uid] = _this.events[responseId].banner[uid] || {};
|
|
157
|
+
_this.events[responseId].banner[uid].clickThrough = true;
|
|
158
|
+
setTimeout(function () {
|
|
159
|
+
_this.events[responseId].banner[uid].clickThrough = false;
|
|
160
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
161
|
+
},
|
|
162
|
+
},
|
|
116
163
|
product: {
|
|
117
164
|
clickThrough: function (e, result) {
|
|
118
165
|
var _a, _b;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
166
|
+
var responseId = result.responseId;
|
|
167
|
+
var item = {
|
|
168
|
+
type: result.type,
|
|
169
|
+
uid: result.id,
|
|
170
|
+
parentId: result.id,
|
|
171
|
+
sku: (_a = result.mappings.core) === null || _a === void 0 ? void 0 : _a.sku,
|
|
172
|
+
};
|
|
173
|
+
var data = {
|
|
174
|
+
responseId: responseId,
|
|
175
|
+
results: [item],
|
|
176
|
+
};
|
|
123
177
|
_this.eventManager.fire('track.product.clickThrough', { controller: _this, event: e, product: result, trackEvent: data });
|
|
124
178
|
_this.tracker.events.autocomplete.clickThrough({ data: data, siteId: (_b = _this.config.globals) === null || _b === void 0 ? void 0 : _b.siteId });
|
|
125
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
126
|
-
_this.events.product[result.id].clickThrough = true;
|
|
127
179
|
},
|
|
128
180
|
click: function (e, result) {
|
|
129
|
-
var _a;
|
|
130
|
-
|
|
131
|
-
|
|
181
|
+
var _a, _b, _c, _d, _e, _f;
|
|
182
|
+
var responseId = result.responseId;
|
|
183
|
+
if (result.type === 'banner' && (0, isClickWithinBannerLink_1.isClickWithinBannerLink)(e)) {
|
|
184
|
+
if ((_c = (_b = (_a = _this.events) === null || _a === void 0 ? void 0 : _a[responseId]) === null || _b === void 0 ? void 0 : _b.product[result.id]) === null || _c === void 0 ? void 0 : _c.inlineBannerClickThrough) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
_this.track.product.clickThrough(e, result);
|
|
188
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
189
|
+
_this.events[responseId].product[result.id].inlineBannerClickThrough = true;
|
|
190
|
+
setTimeout(function () {
|
|
191
|
+
_this.events[responseId].product[result.id].inlineBannerClickThrough = false;
|
|
192
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
132
193
|
}
|
|
133
|
-
if (
|
|
134
|
-
|
|
194
|
+
else if ((0, isClickWithinProductLink_1.isClickWithinProductLink)(e, result)) {
|
|
195
|
+
if ((_f = (_e = (_d = _this.events) === null || _d === void 0 ? void 0 : _d[responseId]) === null || _e === void 0 ? void 0 : _e.product[result.id]) === null || _f === void 0 ? void 0 : _f.productClickThrough) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
_this.track.product.clickThrough(e, result);
|
|
199
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
200
|
+
_this.events[responseId].product[result.id].productClickThrough = true;
|
|
201
|
+
setTimeout(function () {
|
|
202
|
+
_this.events[responseId].product[result.id].productClickThrough = false;
|
|
203
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
135
204
|
}
|
|
136
|
-
(0, isClickWithinProductLink_1.isClickWithinProductLink)(e, result) && _this.track.product.clickThrough(e, result);
|
|
137
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
138
|
-
_this.events.product[result.id].click = true;
|
|
139
|
-
setTimeout(function () {
|
|
140
|
-
_this.events.product[result.id].click = false;
|
|
141
|
-
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
142
|
-
},
|
|
143
|
-
render: function (result) {
|
|
144
|
-
var _a, _b;
|
|
145
|
-
if ((_a = _this.events.product[result.id]) === null || _a === void 0 ? void 0 : _a.render)
|
|
146
|
-
return;
|
|
147
|
-
var data = getAutocompleteSchemaData({ params: _this.params, store: _this.store, results: result ? [result] : [] });
|
|
148
|
-
_this.eventManager.fire('track.product.render', { controller: _this, product: result, trackEvent: data });
|
|
149
|
-
_this.tracker.events.autocomplete.render({ data: data, siteId: (_b = _this.config.globals) === null || _b === void 0 ? void 0 : _b.siteId });
|
|
150
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
151
|
-
_this.events.product[result.id].render = true;
|
|
152
205
|
},
|
|
153
206
|
impression: function (result) {
|
|
154
|
-
var _a, _b, _c;
|
|
155
|
-
|
|
207
|
+
var _a, _b, _c, _d, _e;
|
|
208
|
+
var responseId = result.responseId;
|
|
209
|
+
if ((_c = (_b = (_a = _this.events) === null || _a === void 0 ? void 0 : _a[responseId]) === null || _b === void 0 ? void 0 : _b.product[result.id]) === null || _c === void 0 ? void 0 : _c.impression) {
|
|
156
210
|
return;
|
|
157
|
-
|
|
211
|
+
}
|
|
212
|
+
var item = {
|
|
213
|
+
type: result.type,
|
|
214
|
+
uid: result.id,
|
|
215
|
+
parentId: result.id,
|
|
216
|
+
sku: (_d = result.mappings.core) === null || _d === void 0 ? void 0 : _d.sku,
|
|
217
|
+
};
|
|
218
|
+
var data = {
|
|
219
|
+
responseId: responseId,
|
|
220
|
+
results: [item],
|
|
221
|
+
banners: [],
|
|
222
|
+
};
|
|
158
223
|
_this.eventManager.fire('track.product.impression', { controller: _this, product: result, trackEvent: data });
|
|
159
|
-
_this.tracker.events.autocomplete.impression({ data: data, siteId: (
|
|
160
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
161
|
-
_this.events.product[result.id].impression = true;
|
|
224
|
+
_this.tracker.events.autocomplete.impression({ data: data, siteId: (_e = _this.config.globals) === null || _e === void 0 ? void 0 : _e.siteId });
|
|
225
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
226
|
+
_this.events[responseId].product[result.id].impression = true;
|
|
162
227
|
},
|
|
163
228
|
addToCart: function (result) {
|
|
164
|
-
var _a;
|
|
165
|
-
var
|
|
229
|
+
var _a, _b, _c;
|
|
230
|
+
var responseId = result.responseId;
|
|
231
|
+
var product = {
|
|
232
|
+
parentId: result.id,
|
|
233
|
+
uid: result.id,
|
|
234
|
+
sku: (_a = result.mappings.core) === null || _a === void 0 ? void 0 : _a.sku,
|
|
235
|
+
qty: result.quantity || 1,
|
|
236
|
+
price: Number((_b = result.mappings.core) === null || _b === void 0 ? void 0 : _b.price),
|
|
237
|
+
};
|
|
238
|
+
var data = {
|
|
239
|
+
responseId: responseId,
|
|
240
|
+
results: [product],
|
|
241
|
+
};
|
|
166
242
|
_this.eventManager.fire('track.product.addToCart', { controller: _this, product: result, trackEvent: data });
|
|
167
|
-
_this.tracker.events.autocomplete.addToCart({ data: data, siteId: (
|
|
243
|
+
_this.tracker.events.autocomplete.addToCart({ data: data, siteId: (_c = _this.config.globals) === null || _c === void 0 ? void 0 : _c.siteId });
|
|
168
244
|
},
|
|
169
245
|
},
|
|
170
|
-
redirect: function (
|
|
171
|
-
var
|
|
172
|
-
var
|
|
246
|
+
redirect: function (_a) {
|
|
247
|
+
var _b;
|
|
248
|
+
var redirectURL = _a.redirectURL, responseId = _a.responseId;
|
|
249
|
+
var data = {
|
|
250
|
+
responseId: responseId,
|
|
251
|
+
redirect: redirectURL,
|
|
252
|
+
};
|
|
173
253
|
_this.eventManager.fire('track.redirect', { controller: _this, redirectURL: redirectURL, trackEvent: data });
|
|
174
|
-
_this.tracker.events.autocomplete.redirect({ data: data, siteId: (
|
|
254
|
+
_this.tracker.events.autocomplete.redirect({ data: data, siteId: (_b = _this.config.globals) === null || _b === void 0 ? void 0 : _b.siteId });
|
|
175
255
|
},
|
|
176
256
|
};
|
|
177
257
|
_this.handlers = {
|
|
@@ -350,6 +430,7 @@ var AutocompleteController = /** @class */ (function (_super) {
|
|
|
350
430
|
if (((!_this.store.state.input && !value) || _this.store.state.input == value) && _this.store.loaded) {
|
|
351
431
|
return;
|
|
352
432
|
}
|
|
433
|
+
_this.store.state.source = 'input';
|
|
353
434
|
_this.store.state.input = value;
|
|
354
435
|
// remove merch redirect to prevent race condition
|
|
355
436
|
_this.store.merchandising.redirect = '';
|
|
@@ -433,7 +514,7 @@ var AutocompleteController = /** @class */ (function (_super) {
|
|
|
433
514
|
});
|
|
434
515
|
}); };
|
|
435
516
|
_this.search = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
436
|
-
var params, err_3, searchProfile, _a, meta, response, impressedResultIds, afterSearchProfile, err_4, afterStoreProfile, err_5, err_6;
|
|
517
|
+
var params, err_3, searchProfile, _a, meta, response, responseId_1, impressedResultIds, afterSearchProfile, err_4, afterStoreProfile, err_5, err_6;
|
|
437
518
|
var _this = this;
|
|
438
519
|
var _b, _c, _d, _e;
|
|
439
520
|
return __generator(this, function (_f) {
|
|
@@ -491,17 +572,20 @@ var AutocompleteController = /** @class */ (function (_super) {
|
|
|
491
572
|
}
|
|
492
573
|
searchProfile.stop();
|
|
493
574
|
this.log.profile(searchProfile);
|
|
575
|
+
responseId_1 = response.tracking.responseId;
|
|
576
|
+
this.events[responseId_1] = this.events[responseId_1] || { product: {}, banner: {} };
|
|
494
577
|
if (((_d = response.search) === null || _d === void 0 ? void 0 : _d.query) === this.lastSearchQuery) {
|
|
495
|
-
impressedResultIds = Object.keys(this.events.product).filter(function (resultId) { var _a; return (_a = _this.events.product[resultId]) === null ||
|
|
496
|
-
this.events = {
|
|
578
|
+
impressedResultIds = Object.keys(this.events[responseId_1].product || {}).filter(function (resultId) { var _a, _b; return (_b = (_a = _this.events[responseId_1].product) === null || _a === void 0 ? void 0 : _a[resultId]) === null || _b === void 0 ? void 0 : _b.impression; });
|
|
579
|
+
this.events[responseId_1] = {
|
|
497
580
|
product: impressedResultIds.reduce(function (acc, resultId) {
|
|
498
581
|
acc[resultId] = { impression: true };
|
|
499
582
|
return acc;
|
|
500
583
|
}, {}),
|
|
584
|
+
banner: this.events[responseId_1].banner,
|
|
501
585
|
};
|
|
502
586
|
}
|
|
503
587
|
else {
|
|
504
|
-
this.events = { product: {} };
|
|
588
|
+
this.events[responseId_1] = { product: {}, banner: {} };
|
|
505
589
|
this.lastSearchQuery = (_e = response.search) === null || _e === void 0 ? void 0 : _e.query;
|
|
506
590
|
}
|
|
507
591
|
afterSearchProfile = this.profiler.create({ type: 'event', name: 'afterSearch', context: params }).start();
|
|
@@ -640,8 +724,7 @@ var AutocompleteController = /** @class */ (function (_super) {
|
|
|
640
724
|
key: "ss-controller-".concat(_this.config.id),
|
|
641
725
|
});
|
|
642
726
|
_this.eventManager.on('afterStore', function (search, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
643
|
-
var controller,
|
|
644
|
-
var _this = this;
|
|
727
|
+
var controller, responseId, data;
|
|
645
728
|
var _a;
|
|
646
729
|
return __generator(this, function (_b) {
|
|
647
730
|
switch (_b.label) {
|
|
@@ -649,22 +732,12 @@ var AutocompleteController = /** @class */ (function (_super) {
|
|
|
649
732
|
case 1:
|
|
650
733
|
_b.sent();
|
|
651
734
|
controller = search.controller;
|
|
735
|
+
responseId = search.response.tracking.responseId;
|
|
652
736
|
if (controller.store.loaded && !controller.store.error) {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
data = getAutocompleteSchemaData({ params: search.request, store: this.store });
|
|
656
|
-
this.eventManager.fire('track.product.render', { controller: this, trackEvent: data });
|
|
737
|
+
if (!search.response._cached) {
|
|
738
|
+
data = { responseId: responseId };
|
|
657
739
|
this.tracker.events.autocomplete.render({ data: data, siteId: (_a = this.config.globals) === null || _a === void 0 ? void 0 : _a.siteId });
|
|
658
740
|
}
|
|
659
|
-
products.forEach(function (result) {
|
|
660
|
-
if (!search.response._cached) {
|
|
661
|
-
_this.track.product.render(result);
|
|
662
|
-
}
|
|
663
|
-
else {
|
|
664
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
665
|
-
_this.events.product[result.id].render = true;
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
741
|
}
|
|
669
742
|
return [2 /*return*/];
|
|
670
743
|
}
|
|
@@ -688,26 +761,26 @@ var AutocompleteController = /** @class */ (function (_super) {
|
|
|
688
761
|
}); });
|
|
689
762
|
_this.eventManager.on('beforeSubmit', function (ac, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
690
763
|
var loading, inputState, redirectURL, results, filteredResults, singleResultUrl;
|
|
691
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
692
|
-
return __generator(this, function (
|
|
693
|
-
switch (
|
|
764
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
765
|
+
return __generator(this, function (_k) {
|
|
766
|
+
switch (_k.label) {
|
|
694
767
|
case 0: return [4 /*yield*/, next()];
|
|
695
768
|
case 1:
|
|
696
|
-
|
|
769
|
+
_k.sent();
|
|
697
770
|
loading = ac.controller.store.loading;
|
|
698
771
|
if (loading)
|
|
699
772
|
return [2 /*return*/];
|
|
700
773
|
inputState = ac.controller.store.state.input;
|
|
701
774
|
redirectURL = (_a = ac.controller.store.merchandising) === null || _a === void 0 ? void 0 : _a.redirect;
|
|
702
775
|
if (((_d = (_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.settings) === null || _c === void 0 ? void 0 : _c.redirects) === null || _d === void 0 ? void 0 : _d.merchandising) && inputState && redirectURL) {
|
|
703
|
-
this.track.redirect(redirectURL);
|
|
776
|
+
this.track.redirect({ redirectURL: redirectURL, responseId: (_e = ac.controller.store.merchandising) === null || _e === void 0 ? void 0 : _e.responseId });
|
|
704
777
|
window.location.href = redirectURL;
|
|
705
778
|
return [2 /*return*/, false];
|
|
706
779
|
}
|
|
707
|
-
if ((
|
|
780
|
+
if ((_h = (_g = (_f = this.config) === null || _f === void 0 ? void 0 : _f.settings) === null || _g === void 0 ? void 0 : _g.redirects) === null || _h === void 0 ? void 0 : _h.singleResult) {
|
|
708
781
|
results = ac.controller.store.results;
|
|
709
782
|
filteredResults = results.filter(function (result) { return result.type == 'product'; });
|
|
710
|
-
singleResultUrl = filteredResults.length === 1 && ((
|
|
783
|
+
singleResultUrl = filteredResults.length === 1 && ((_j = filteredResults[0].mappings.core) === null || _j === void 0 ? void 0 : _j.url);
|
|
711
784
|
if (singleResultUrl) {
|
|
712
785
|
window.location.href = singleResultUrl;
|
|
713
786
|
return [2 /*return*/, false];
|
|
@@ -738,6 +811,14 @@ var AutocompleteController = /** @class */ (function (_super) {
|
|
|
738
811
|
if (pageLoadId) {
|
|
739
812
|
params.tracking.pageLoadId = pageLoadId;
|
|
740
813
|
}
|
|
814
|
+
if (this.store.state.input) {
|
|
815
|
+
params.search = params.search || {};
|
|
816
|
+
params.search.input = this.store.state.input;
|
|
817
|
+
}
|
|
818
|
+
if (this.store.state.source) {
|
|
819
|
+
params.search = params.search || {};
|
|
820
|
+
params.search.source = this.store.state.source;
|
|
821
|
+
}
|
|
741
822
|
if (!((_b = (_a = this.config.globals) === null || _a === void 0 ? void 0 : _a.personalization) === null || _b === void 0 ? void 0 : _b.disabled)) {
|
|
742
823
|
var cartItems = this.tracker.cookies.cart.get();
|
|
743
824
|
if (cartItems.length) {
|
|
@@ -966,80 +1047,3 @@ function unbindFormParameters(form, fn) {
|
|
|
966
1047
|
}
|
|
967
1048
|
}
|
|
968
1049
|
}
|
|
969
|
-
function getAutocompleteRedirectSchemaData(_a) {
|
|
970
|
-
var redirectURL = _a.redirectURL;
|
|
971
|
-
return {
|
|
972
|
-
redirect: redirectURL,
|
|
973
|
-
};
|
|
974
|
-
}
|
|
975
|
-
function getAutocompleteAddtocartSchemaData(_a) {
|
|
976
|
-
var params = _a.params, store = _a.store, results = _a.results;
|
|
977
|
-
var base = getAutocompleteSchemaData({ params: params, store: store, results: results });
|
|
978
|
-
return __assign(__assign({}, base), { results: (results === null || results === void 0 ? void 0 : results.map(function (result) {
|
|
979
|
-
var core = result.mappings.core;
|
|
980
|
-
return {
|
|
981
|
-
uid: core.uid || '',
|
|
982
|
-
sku: core.sku,
|
|
983
|
-
price: Number(core.price),
|
|
984
|
-
qty: result.quantity || 1,
|
|
985
|
-
};
|
|
986
|
-
})) || [] });
|
|
987
|
-
}
|
|
988
|
-
function getAutocompleteSchemaData(_a) {
|
|
989
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
990
|
-
var params = _a.params, store = _a.store, results = _a.results;
|
|
991
|
-
var filters = (_b = params.filters) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, filter) {
|
|
992
|
-
var _a;
|
|
993
|
-
var _b, _c, _d, _e;
|
|
994
|
-
var key = filter.background ? 'bgfilter' : 'filter';
|
|
995
|
-
acc[key] = acc[key] || [];
|
|
996
|
-
var value = filter.type === 'range' &&
|
|
997
|
-
!isNaN((_b = filter.value) === null || _b === void 0 ? void 0 : _b.low) &&
|
|
998
|
-
!isNaN((_c = filter.value) === null || _c === void 0 ? void 0 : _c.high)
|
|
999
|
-
? ["low=".concat((_d = filter.value) === null || _d === void 0 ? void 0 : _d.low), "high=".concat((_e = filter.value) === null || _e === void 0 ? void 0 : _e.high)]
|
|
1000
|
-
: ["".concat(filter.value)];
|
|
1001
|
-
var existing = acc[key].find(function (item) { return item.field === filter.field; });
|
|
1002
|
-
if (existing && !existing.value.includes(value[0])) {
|
|
1003
|
-
(_a = existing.value).push.apply(_a, value);
|
|
1004
|
-
}
|
|
1005
|
-
else {
|
|
1006
|
-
acc[key].push({
|
|
1007
|
-
field: filter.field,
|
|
1008
|
-
value: value,
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
return acc;
|
|
1012
|
-
}, {});
|
|
1013
|
-
return __assign(__assign({ q: ((_d = (_c = store.search) === null || _c === void 0 ? void 0 : _c.originalQuery) === null || _d === void 0 ? void 0 : _d.string) || ((_f = (_e = store.search) === null || _e === void 0 ? void 0 : _e.query) === null || _f === void 0 ? void 0 : _f.string) || '', rq: ((_g = params.search) === null || _g === void 0 ? void 0 : _g.subQuery) ? (_h = params.search) === null || _h === void 0 ? void 0 : _h.subQuery : undefined, correctedQuery: ((_k = (_j = store.search) === null || _j === void 0 ? void 0 : _j.originalQuery) === null || _k === void 0 ? void 0 : _k.string) ? (_m = (_l = store.search) === null || _l === void 0 ? void 0 : _l.query) === null || _m === void 0 ? void 0 : _m.string : undefined, matchType: store.search.matchType }, filters), { sort: (_o = params.sorts) === null || _o === void 0 ? void 0 : _o.map(function (sort) {
|
|
1014
|
-
return {
|
|
1015
|
-
field: sort.field,
|
|
1016
|
-
dir: sort.direction,
|
|
1017
|
-
};
|
|
1018
|
-
}), pagination: {
|
|
1019
|
-
totalResults: store.pagination.totalResults,
|
|
1020
|
-
page: store.pagination.page,
|
|
1021
|
-
resultsPerPage: store.pagination.pageSize,
|
|
1022
|
-
}, merchandising: {
|
|
1023
|
-
personalized: store.merchandising.personalized,
|
|
1024
|
-
redirect: store.merchandising.redirect,
|
|
1025
|
-
triggeredCampaigns: (((_p = store.merchandising.campaigns) === null || _p === void 0 ? void 0 : _p.length) &&
|
|
1026
|
-
((_q = store.merchandising.campaigns) === null || _q === void 0 ? void 0 : _q.map(function (campaign) {
|
|
1027
|
-
var experiement = store.merchandising.experiments.find(function (experiment) { return experiment.campaignId === campaign.id; });
|
|
1028
|
-
return {
|
|
1029
|
-
id: campaign.id,
|
|
1030
|
-
experimentId: experiement === null || experiement === void 0 ? void 0 : experiement.experimentId,
|
|
1031
|
-
variationId: experiement === null || experiement === void 0 ? void 0 : experiement.variationId,
|
|
1032
|
-
};
|
|
1033
|
-
}))) ||
|
|
1034
|
-
undefined,
|
|
1035
|
-
}, banners: [], results: (results === null || results === void 0 ? void 0 : results.map(function (result) {
|
|
1036
|
-
var core = result.mappings.core;
|
|
1037
|
-
var position = result.position;
|
|
1038
|
-
return {
|
|
1039
|
-
type: beacon_1.ItemTypeEnum.Product,
|
|
1040
|
-
position: position,
|
|
1041
|
-
uid: core.uid || '',
|
|
1042
|
-
sku: core.sku,
|
|
1043
|
-
};
|
|
1044
|
-
})) || [] });
|
|
1045
|
-
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Product } from '@searchspring/snap-store-mobx';
|
|
2
2
|
import { AbstractController } from '../Abstract/AbstractController';
|
|
3
3
|
import { ControllerTypes } from '../types';
|
|
4
|
-
import type { RecommendationStore } from '@searchspring/snap-store-mobx';
|
|
4
|
+
import type { Banner, RecommendationStore } from '@searchspring/snap-store-mobx';
|
|
5
5
|
import type { RecommendRequestModel } from '@searchspring/snap-client';
|
|
6
6
|
import type { RecommendationControllerConfig, ControllerServices, ContextVariables } from '../types';
|
|
7
7
|
type RecommendationTrackMethods = {
|
|
8
8
|
product: {
|
|
9
|
-
clickThrough: (e: MouseEvent, result: Product) => void;
|
|
10
|
-
click: (e: MouseEvent, result: Product) => void;
|
|
11
|
-
|
|
12
|
-
impression: (result: Product) => void;
|
|
9
|
+
clickThrough: (e: MouseEvent, result: Product | Banner) => void;
|
|
10
|
+
click: (e: MouseEvent, result: Product | Banner) => void;
|
|
11
|
+
impression: (result: Product | Banner) => void;
|
|
13
12
|
addToCart: (result: Product) => void;
|
|
14
13
|
};
|
|
15
14
|
};
|
|
@@ -17,14 +16,7 @@ export declare class RecommendationController extends AbstractController {
|
|
|
17
16
|
type: ControllerTypes;
|
|
18
17
|
store: RecommendationStore;
|
|
19
18
|
config: RecommendationControllerConfig;
|
|
20
|
-
events
|
|
21
|
-
product: Record<string, {
|
|
22
|
-
click?: boolean;
|
|
23
|
-
clickThrough?: boolean;
|
|
24
|
-
impression?: boolean;
|
|
25
|
-
render?: boolean;
|
|
26
|
-
}>;
|
|
27
|
-
};
|
|
19
|
+
private events;
|
|
28
20
|
constructor(config: RecommendationControllerConfig, { client, store, urlManager, eventManager, profiler, logger, tracker }: ControllerServices, context?: ContextVariables);
|
|
29
21
|
track: RecommendationTrackMethods;
|
|
30
22
|
get params(): RecommendRequestModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecommendationController.d.ts","sourceRoot":"","sources":["../../../src/Recommendation/RecommendationController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"RecommendationController.d.ts","sourceRoot":"","sources":["../../../src/Recommendation/RecommendationController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAW3C,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,gBAAgB,EAAiB,MAAM,UAAU,CAAC;AAIpH,KAAK,0BAA0B,GAAG;IACjC,OAAO,EAAE;QACR,YAAY,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,KAAK,IAAI,CAAC;QAChE,KAAK,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,KAAK,IAAI,CAAC;QACzD,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,KAAK,IAAI,CAAC;QAC/C,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;KACrC,CAAC;CACF,CAAC;AAUF,qBAAa,wBAAyB,SAAQ,kBAAkB;IACxD,IAAI,kBAAkC;IACrC,KAAK,EAAE,mBAAmB,CAAC;IAC3B,MAAM,EAAE,8BAA8B,CAAC;IAE/C,OAAO,CAAC,MAAM,CAUP;gBAGN,MAAM,EAAE,8BAA8B,EACtC,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,kBAAkB,EAC1F,OAAO,CAAC,EAAE,gBAAgB;IAoD3B,KAAK,EAAE,0BAA0B,CAqF/B;IAEF,IAAI,MAAM,IAAI,qBAAqB,CA4BlC;IAED,MAAM,QAAa,QAAQ,IAAI,CAAC,CA6H9B;IAEF,SAAS,cAAqB,OAAO,EAAE,GAAG,OAAO,KAAG,QAAQ,IAAI,CAAC,CAQ/D;CACF"}
|