@searchspring/snap-controller 0.72.1 → 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
|
@@ -81,8 +81,8 @@ var AbstractController_1 = require("../Abstract/AbstractController");
|
|
|
81
81
|
var snap_store_mobx_1 = require("@searchspring/snap-store-mobx");
|
|
82
82
|
var getParams_1 = require("../utils/getParams");
|
|
83
83
|
var types_1 = require("../types");
|
|
84
|
-
var beacon_1 = require("@searchspring/beacon");
|
|
85
84
|
var isClickWithinProductLink_1 = require("../utils/isClickWithinProductLink");
|
|
85
|
+
var isClickWithinBannerLink_1 = require("../utils/isClickWithinBannerLink");
|
|
86
86
|
var BACKGROUND_FILTER_FIELD_MATCHES = ['collection', 'category', 'categories', 'hierarchy', 'brand', 'manufacturer'];
|
|
87
87
|
var BACKGROUND_FILTERS_VALUE_FLAGS = [1, 0, '1', '0', 'true', 'false', true, false];
|
|
88
88
|
var defaultConfig = {
|
|
@@ -101,7 +101,6 @@ var defaultConfig = {
|
|
|
101
101
|
},
|
|
102
102
|
},
|
|
103
103
|
};
|
|
104
|
-
var schemaMap = {};
|
|
105
104
|
var SearchController = /** @class */ (function (_super) {
|
|
106
105
|
__extends(SearchController, _super);
|
|
107
106
|
function SearchController(config, _a, context) {
|
|
@@ -113,23 +112,71 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
113
112
|
_this.page = {
|
|
114
113
|
type: 'search',
|
|
115
114
|
};
|
|
116
|
-
_this.events = {
|
|
115
|
+
_this.events = {};
|
|
117
116
|
_this.track = {
|
|
117
|
+
banner: {
|
|
118
|
+
impression: function (_a) {
|
|
119
|
+
var _b, _c, _d;
|
|
120
|
+
var uid = _a.uid, responseId = _a.responseId;
|
|
121
|
+
if ((_c = (_b = _this.events[responseId]) === null || _b === void 0 ? void 0 : _b.banner[uid]) === null || _c === void 0 ? void 0 : _c.impression) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
var banner = { uid: uid };
|
|
125
|
+
var data = {
|
|
126
|
+
responseId: responseId,
|
|
127
|
+
banners: [banner],
|
|
128
|
+
results: [],
|
|
129
|
+
};
|
|
130
|
+
_this.eventManager.fire('track.banner.impression', { controller: _this, product: { uid: uid }, trackEvent: data });
|
|
131
|
+
_this.tracker.events[_this.page.type].impression({ data: data, siteId: (_d = _this.config.globals) === null || _d === void 0 ? void 0 : _d.siteId });
|
|
132
|
+
_this.events[responseId].banner[uid] = _this.events[responseId].banner[uid] || {};
|
|
133
|
+
_this.events[responseId].banner[uid].impression = true;
|
|
134
|
+
},
|
|
135
|
+
click: function (e, banner) {
|
|
136
|
+
var _a, _b, _c;
|
|
137
|
+
var responseId = banner.responseId, uid = banner.uid;
|
|
138
|
+
if ((0, isClickWithinBannerLink_1.isClickWithinBannerLink)(e)) {
|
|
139
|
+
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) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
_this.track.banner.clickThrough(e, banner);
|
|
143
|
+
_this.events[responseId].banner[uid] = _this.events[responseId].banner[uid] || {};
|
|
144
|
+
_this.events[responseId].banner[uid].clickThrough = true;
|
|
145
|
+
setTimeout(function () {
|
|
146
|
+
_this.events[responseId].banner[uid].clickThrough = false;
|
|
147
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
clickThrough: function (e, _a) {
|
|
151
|
+
var _b;
|
|
152
|
+
var uid = _a.uid, responseId = _a.responseId;
|
|
153
|
+
var banner = { uid: uid };
|
|
154
|
+
var data = {
|
|
155
|
+
responseId: responseId,
|
|
156
|
+
banners: [banner],
|
|
157
|
+
};
|
|
158
|
+
_this.eventManager.fire('track.banner.clickThrough', { controller: _this, event: e, product: { uid: uid }, trackEvent: data });
|
|
159
|
+
_this.tracker.events[_this.page.type].clickThrough({ data: data, siteId: (_b = _this.config.globals) === null || _b === void 0 ? void 0 : _b.siteId });
|
|
160
|
+
_this.events[responseId].banner[uid] = _this.events[responseId].banner[uid] || {};
|
|
161
|
+
_this.events[responseId].banner[uid].clickThrough = true;
|
|
162
|
+
setTimeout(function () {
|
|
163
|
+
_this.events[responseId].banner[uid].clickThrough = false;
|
|
164
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
165
|
+
},
|
|
166
|
+
},
|
|
118
167
|
product: {
|
|
119
168
|
clickThrough: function (e, result) {
|
|
120
169
|
var _a, _b, _c, _d, _e, _f;
|
|
121
|
-
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
170
|
+
var responseId = result.responseId;
|
|
124
171
|
var target = e.target;
|
|
125
|
-
var resultHref = ((
|
|
172
|
+
var resultHref = ((_b = (_a = result.display) === null || _a === void 0 ? void 0 : _a.mappings.core) === null || _b === void 0 ? void 0 : _b.url) || ((_c = result.mappings.core) === null || _c === void 0 ? void 0 : _c.url) || '';
|
|
126
173
|
var elemHref = target === null || target === void 0 ? void 0 : target.getAttribute('href');
|
|
127
174
|
// the href that should be used for restoration - if the elemHref contains the resultHref - use resultHref
|
|
128
175
|
var storedHref = (elemHref === null || elemHref === void 0 ? void 0 : elemHref.indexOf(resultHref)) != -1 ? resultHref : elemHref || resultHref;
|
|
129
176
|
var scrollMap = {};
|
|
130
177
|
// generate the selector using element class and parent classes
|
|
131
178
|
var selector = generateHrefSelector(target, storedHref);
|
|
132
|
-
var domRect = selector ? (
|
|
179
|
+
var domRect = selector ? (_d = document === null || document === void 0 ? void 0 : document.querySelector(selector)) === null || _d === void 0 ? void 0 : _d.getBoundingClientRect() : undefined;
|
|
133
180
|
// store element position data to scrollMap
|
|
134
181
|
if (selector || storedHref || domRect) {
|
|
135
182
|
try {
|
|
@@ -147,68 +194,98 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
147
194
|
}
|
|
148
195
|
// store position data or empty object
|
|
149
196
|
_this.storage.set('scrollMap', scrollMap);
|
|
150
|
-
var
|
|
197
|
+
var item = {
|
|
198
|
+
type: result.type,
|
|
199
|
+
uid: result.id,
|
|
200
|
+
parentId: result.id,
|
|
201
|
+
sku: (_e = result.mappings.core) === null || _e === void 0 ? void 0 : _e.sku,
|
|
202
|
+
};
|
|
203
|
+
var data = {
|
|
204
|
+
responseId: responseId,
|
|
205
|
+
results: [item],
|
|
206
|
+
};
|
|
151
207
|
_this.eventManager.fire('track.product.clickThrough', { controller: _this, event: e, product: result, trackEvent: data });
|
|
152
208
|
_this.tracker.events[_this.page.type].clickThrough({ data: data, siteId: (_f = _this.config.globals) === null || _f === void 0 ? void 0 : _f.siteId });
|
|
153
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
154
|
-
_this.events.product[result.id].clickThrough = true;
|
|
155
209
|
},
|
|
156
210
|
click: function (e, result) {
|
|
157
|
-
var _a;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
211
|
+
var _a, _b, _c, _d, _e, _f;
|
|
212
|
+
var responseId = result.responseId;
|
|
213
|
+
if (result.type === 'banner' && (0, isClickWithinBannerLink_1.isClickWithinBannerLink)(e)) {
|
|
214
|
+
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) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
_this.track.product.clickThrough(e, result);
|
|
218
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
219
|
+
_this.events[responseId].product[result.id].inlineBannerClickThrough = true;
|
|
220
|
+
setTimeout(function () {
|
|
221
|
+
_this.events[responseId].product[result.id].inlineBannerClickThrough = false;
|
|
222
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
163
223
|
}
|
|
164
|
-
(0, isClickWithinProductLink_1.isClickWithinProductLink)(e, result)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
_this.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return;
|
|
224
|
+
else if ((0, isClickWithinProductLink_1.isClickWithinProductLink)(e, result)) {
|
|
225
|
+
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) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
_this.track.product.clickThrough(e, result);
|
|
229
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
230
|
+
_this.events[responseId].product[result.id].productClickThrough = true;
|
|
231
|
+
setTimeout(function () {
|
|
232
|
+
_this.events[responseId].product[result.id].productClickThrough = false;
|
|
233
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
175
234
|
}
|
|
176
|
-
var data = schemaMap[result.id];
|
|
177
|
-
_this.eventManager.fire('track.product.render', { controller: _this, product: result, trackEvent: data });
|
|
178
|
-
_this.tracker.events[_this.page.type].render({ data: data, siteId: (_b = _this.config.globals) === null || _b === void 0 ? void 0 : _b.siteId });
|
|
179
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
180
|
-
_this.events.product[result.id].render = true;
|
|
181
235
|
},
|
|
182
236
|
impression: function (result) {
|
|
183
|
-
var _a, _b, _c;
|
|
184
|
-
|
|
237
|
+
var _a, _b, _c, _d;
|
|
238
|
+
var responseId = result.responseId;
|
|
239
|
+
if ((_b = (_a = _this.events[responseId]) === null || _a === void 0 ? void 0 : _a.product[result.id]) === null || _b === void 0 ? void 0 : _b.impression) {
|
|
185
240
|
return;
|
|
186
241
|
}
|
|
187
|
-
var
|
|
242
|
+
var item = {
|
|
243
|
+
type: result.type,
|
|
244
|
+
uid: result.id,
|
|
245
|
+
parentId: result.id,
|
|
246
|
+
sku: (_c = result.mappings.core) === null || _c === void 0 ? void 0 : _c.sku,
|
|
247
|
+
};
|
|
248
|
+
var data = {
|
|
249
|
+
responseId: responseId,
|
|
250
|
+
results: [item],
|
|
251
|
+
banners: [],
|
|
252
|
+
};
|
|
188
253
|
_this.eventManager.fire('track.product.impression', { controller: _this, product: result, trackEvent: data });
|
|
189
|
-
_this.tracker.events[_this.page.type].impression({ data: data, siteId: (
|
|
190
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
191
|
-
_this.events.product[result.id].impression = true;
|
|
254
|
+
_this.tracker.events[_this.page.type].impression({ data: data, siteId: (_d = _this.config.globals) === null || _d === void 0 ? void 0 : _d.siteId });
|
|
255
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
256
|
+
_this.events[responseId].product[result.id].impression = true;
|
|
192
257
|
},
|
|
193
258
|
addToCart: function (result) {
|
|
194
|
-
var _a;
|
|
195
|
-
var
|
|
259
|
+
var _a, _b, _c;
|
|
260
|
+
var responseId = result.responseId;
|
|
261
|
+
var product = {
|
|
262
|
+
parentId: result.id,
|
|
263
|
+
uid: result.id,
|
|
264
|
+
sku: (_a = result.mappings.core) === null || _a === void 0 ? void 0 : _a.sku,
|
|
265
|
+
qty: result.quantity || 1,
|
|
266
|
+
price: Number((_b = result.mappings.core) === null || _b === void 0 ? void 0 : _b.price),
|
|
267
|
+
};
|
|
268
|
+
var data = {
|
|
269
|
+
responseId: responseId,
|
|
270
|
+
results: [product],
|
|
271
|
+
};
|
|
196
272
|
_this.eventManager.fire('track.product.addToCart', { controller: _this, product: result, trackEvent: data });
|
|
197
|
-
_this.tracker.events[_this.page.type].addToCart({
|
|
198
|
-
data: data,
|
|
199
|
-
siteId: (_a = _this.config.globals) === null || _a === void 0 ? void 0 : _a.siteId,
|
|
200
|
-
});
|
|
273
|
+
_this.tracker.events[_this.page.type].addToCart({ data: data, siteId: (_c = _this.config.globals) === null || _c === void 0 ? void 0 : _c.siteId });
|
|
201
274
|
},
|
|
202
275
|
},
|
|
203
|
-
redirect: function (
|
|
204
|
-
var
|
|
205
|
-
var
|
|
206
|
-
|
|
207
|
-
|
|
276
|
+
redirect: function (_a) {
|
|
277
|
+
var _b;
|
|
278
|
+
var redirectURL = _a.redirectURL, responseId = _a.responseId;
|
|
279
|
+
var data = {
|
|
280
|
+
responseId: responseId,
|
|
281
|
+
redirect: redirectURL,
|
|
282
|
+
};
|
|
283
|
+
_this.eventManager.fire('track.redirect', { controller: _this, redirectURL: redirectURL, trackEvent: data });
|
|
284
|
+
_this.tracker.events.search.redirect({ data: data, siteId: (_b = _this.config.globals) === null || _b === void 0 ? void 0 : _b.siteId });
|
|
208
285
|
},
|
|
209
286
|
};
|
|
210
287
|
_this.search = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
211
|
-
var params_1, err_1, stringyParams, prevStringyParams, searchProfile, meta, response, preventBackfill, dontBackfill, backfillRequestsParams_1, backfillRequests, backfillResponses, backfillResults, afterSearchProfile, err_2, afterStoreProfile, err_3, err_4;
|
|
288
|
+
var params_1, err_1, stringyParams, prevStringyParams, searchProfile, meta, response, preventBackfill, dontBackfill, backfillRequestsParams_1, backfillRequests, backfillResponses, backfillResults, responseId, responseId, afterSearchProfile, err_2, afterStoreProfile, err_3, err_4;
|
|
212
289
|
var _a, _b;
|
|
213
290
|
var _this = this;
|
|
214
291
|
var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
@@ -258,7 +335,7 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
258
335
|
}
|
|
259
336
|
searchProfile = this.profiler.create({ type: 'event', name: 'search', context: params_1 }).start();
|
|
260
337
|
meta = {};
|
|
261
|
-
response =
|
|
338
|
+
response = void 0;
|
|
262
339
|
if (!(((_g = this.config.settings) === null || _g === void 0 ? void 0 : _g.infinite) && ((_h = params_1.pagination) === null || _h === void 0 ? void 0 : _h.page) && params_1.pagination.page > 1)) return [3 /*break*/, 11];
|
|
263
340
|
preventBackfill = ((_j = this.config.settings.infinite) === null || _j === void 0 ? void 0 : _j.backfill) && !this.store.results.length && params_1.pagination.page > this.config.settings.infinite.backfill;
|
|
264
341
|
dontBackfill = !((_k = this.config.settings.infinite) === null || _k === void 0 ? void 0 : _k.backfill) && !this.store.results.length;
|
|
@@ -285,7 +362,7 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
285
362
|
}
|
|
286
363
|
}
|
|
287
364
|
backfillRequestsParams_1.push(backfillParams);
|
|
288
|
-
return _this.client.
|
|
365
|
+
return _this.client[_this.page.type](backfillParams);
|
|
289
366
|
});
|
|
290
367
|
return [4 /*yield*/, Promise.all(backfillRequests)];
|
|
291
368
|
case 7:
|
|
@@ -294,8 +371,9 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
294
371
|
// set the meta and response to the first page of backfillResponses
|
|
295
372
|
meta = backfillResponses[0][0];
|
|
296
373
|
response = backfillResponses[0][1];
|
|
297
|
-
backfillResults = backfillResponses.reduce(function (results, response
|
|
298
|
-
|
|
374
|
+
backfillResults = backfillResponses.reduce(function (results, response) {
|
|
375
|
+
var responseId = response[1].tracking.responseId;
|
|
376
|
+
_this.events[responseId] = _this.events[responseId] || { product: {}, banner: {} };
|
|
299
377
|
return results.concat.apply(results, response[1].results);
|
|
300
378
|
}, []);
|
|
301
379
|
// overwrite pagination params to expected state
|
|
@@ -304,25 +382,25 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
304
382
|
// set the response results with results from backfill responses
|
|
305
383
|
response.results = backfillResults;
|
|
306
384
|
return [3 /*break*/, 10];
|
|
307
|
-
case 8: return [4 /*yield*/, this.client.
|
|
385
|
+
case 8: return [4 /*yield*/, this.client[this.page.type](params_1)];
|
|
308
386
|
case 9:
|
|
309
387
|
// infinite with no backfills.
|
|
310
388
|
_a = _o.sent(), meta = _a[0], response = _a[1];
|
|
311
|
-
|
|
389
|
+
responseId = response.tracking.responseId;
|
|
390
|
+
this.events[responseId] = this.events[responseId] || { product: {}, banner: {} };
|
|
312
391
|
// append new results to previous results
|
|
313
392
|
response.results = __spreadArray(__spreadArray([], this.previousResults, true), (response.results || []), true);
|
|
314
393
|
_o.label = 10;
|
|
315
394
|
case 10: return [3 /*break*/, 13];
|
|
316
395
|
case 11:
|
|
317
396
|
// normal request
|
|
318
|
-
// reset events for new search
|
|
319
|
-
this.events = { product: {} };
|
|
320
397
|
// clear previousResults to prevent infinite scroll from using them
|
|
321
398
|
this.previousResults = [];
|
|
322
|
-
return [4 /*yield*/, this.client.
|
|
399
|
+
return [4 /*yield*/, this.client[this.page.type](params_1)];
|
|
323
400
|
case 12:
|
|
324
401
|
_b = _o.sent(), meta = _b[0], response = _b[1];
|
|
325
|
-
|
|
402
|
+
responseId = response.tracking.responseId;
|
|
403
|
+
this.events[responseId] = this.events[responseId] || { product: {}, banner: {} };
|
|
326
404
|
_o.label = 13;
|
|
327
405
|
case 13:
|
|
328
406
|
// MockClient will overwrite the client search() method and use SearchData to return mock data which already contains meta data
|
|
@@ -523,7 +601,7 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
523
601
|
if (redirectURL && ((_d = (_c = config === null || config === void 0 ? void 0 : config.settings) === null || _c === void 0 ? void 0 : _c.redirects) === null || _d === void 0 ? void 0 : _d.merchandising) && !((_f = (_e = search === null || search === void 0 ? void 0 : search.response) === null || _e === void 0 ? void 0 : _e.filters) === null || _f === void 0 ? void 0 : _f.length) && !searchStore.loaded) {
|
|
524
602
|
//set loaded to true to prevent infinite search/reloading from happening
|
|
525
603
|
searchStore.loaded = true;
|
|
526
|
-
this.track.redirect(redirectURL);
|
|
604
|
+
this.track.redirect({ redirectURL: redirectURL, responseId: search.response.tracking.responseId });
|
|
527
605
|
window.location.replace(redirectURL);
|
|
528
606
|
return [2 /*return*/, false];
|
|
529
607
|
}
|
|
@@ -603,8 +681,7 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
603
681
|
}); });
|
|
604
682
|
}
|
|
605
683
|
_this.eventManager.on('afterStore', function (search, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
606
|
-
var controller,
|
|
607
|
-
var _this = this;
|
|
684
|
+
var controller, responseId, data, config_1, nonBackgroundFilters;
|
|
608
685
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
609
686
|
return __generator(this, function (_k) {
|
|
610
687
|
switch (_k.label) {
|
|
@@ -612,20 +689,12 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
612
689
|
case 1:
|
|
613
690
|
_k.sent();
|
|
614
691
|
controller = search.controller;
|
|
692
|
+
responseId = search.response.tracking.responseId;
|
|
615
693
|
if (controller.store.loaded && !controller.store.error) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
data = getSearchSchemaData({ params: search.request, response: search.response });
|
|
619
|
-
this.eventManager.fire('track.product.render', { controller: this, trackEvent: data });
|
|
694
|
+
if (!search.response._cached) {
|
|
695
|
+
data = { responseId: responseId };
|
|
620
696
|
this.tracker.events[this.page.type].render({ data: data, siteId: (_a = this.config.globals) === null || _a === void 0 ? void 0 : _a.siteId });
|
|
621
697
|
}
|
|
622
|
-
products.forEach(function (result) {
|
|
623
|
-
if (!search.response._cached) {
|
|
624
|
-
_this.track.product.render(result);
|
|
625
|
-
}
|
|
626
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
627
|
-
_this.events.product[result.id].render = true;
|
|
628
|
-
});
|
|
629
698
|
config_1 = search.controller.config;
|
|
630
699
|
nonBackgroundFilters = (_c = (_b = search === null || search === void 0 ? void 0 : search.request) === null || _b === void 0 ? void 0 : _b.filters) === null || _c === void 0 ? void 0 : _c.filter(function (filter) { return !filter.background; });
|
|
631
700
|
if (((_e = (_d = config_1 === null || config_1 === void 0 ? void 0 : config_1.settings) === null || _d === void 0 ? void 0 : _d.redirects) === null || _e === void 0 ? void 0 : _e.singleResult) &&
|
|
@@ -792,26 +861,6 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
792
861
|
return SearchController;
|
|
793
862
|
}(AbstractController_1.AbstractController));
|
|
794
863
|
exports.SearchController = SearchController;
|
|
795
|
-
function createResultSchemaMapping(_a) {
|
|
796
|
-
var _b;
|
|
797
|
-
var request = _a.request, response = _a.response;
|
|
798
|
-
var _ = response[0], searchResponse = response[1];
|
|
799
|
-
var schema = getSearchSchemaData({
|
|
800
|
-
params: request,
|
|
801
|
-
response: searchResponse,
|
|
802
|
-
});
|
|
803
|
-
(_b = searchResponse.results) === null || _b === void 0 ? void 0 : _b.forEach(function (result, idx) {
|
|
804
|
-
var _a, _b, _c, _d;
|
|
805
|
-
schemaMap[result.id] = __assign(__assign({}, schema), { results: [
|
|
806
|
-
{
|
|
807
|
-
type: beacon_1.ItemTypeEnum.Product,
|
|
808
|
-
position: idx + 1,
|
|
809
|
-
uid: ((_b = (_a = result.mappings) === null || _a === void 0 ? void 0 : _a.core) === null || _b === void 0 ? void 0 : _b.uid) || '',
|
|
810
|
-
sku: (_d = (_c = result.mappings) === null || _c === void 0 ? void 0 : _c.core) === null || _d === void 0 ? void 0 : _d.sku,
|
|
811
|
-
},
|
|
812
|
-
] });
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
864
|
function getStorableRequestParams(request) {
|
|
816
865
|
var _a, _b, _c, _d;
|
|
817
866
|
return {
|
|
@@ -858,76 +907,3 @@ function generateHrefSelector(element, href, levels) {
|
|
|
858
907
|
return;
|
|
859
908
|
}
|
|
860
909
|
exports.generateHrefSelector = generateHrefSelector;
|
|
861
|
-
function getSearchRedirectSchemaData(_a) {
|
|
862
|
-
var redirectURL = _a.redirectURL;
|
|
863
|
-
return {
|
|
864
|
-
redirect: redirectURL,
|
|
865
|
-
};
|
|
866
|
-
}
|
|
867
|
-
function getSearchAddtocartSchemaData(_a) {
|
|
868
|
-
var searchSchemaData = _a.searchSchemaData, results = _a.results;
|
|
869
|
-
return __assign(__assign({}, searchSchemaData), { results: (results === null || results === void 0 ? void 0 : results.map(function (result) {
|
|
870
|
-
var core = result.mappings.core;
|
|
871
|
-
return {
|
|
872
|
-
uid: core.uid || '',
|
|
873
|
-
sku: core.sku,
|
|
874
|
-
price: Number(core.price),
|
|
875
|
-
qty: result.quantity || 1,
|
|
876
|
-
};
|
|
877
|
-
})) || [] });
|
|
878
|
-
}
|
|
879
|
-
function getSearchSchemaData(_a) {
|
|
880
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
881
|
-
var params = _a.params, response = _a.response;
|
|
882
|
-
var filters = (_b = params.filters) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, filter) {
|
|
883
|
-
var _a;
|
|
884
|
-
var _b, _c, _d, _e;
|
|
885
|
-
var key = filter.background ? 'bgfilter' : 'filter';
|
|
886
|
-
acc[key] = acc[key] || [];
|
|
887
|
-
var value = filter.type === 'range' &&
|
|
888
|
-
!isNaN((_b = filter.value) === null || _b === void 0 ? void 0 : _b.low) &&
|
|
889
|
-
!isNaN((_c = filter.value) === null || _c === void 0 ? void 0 : _c.high)
|
|
890
|
-
? ["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)]
|
|
891
|
-
: ["".concat(filter.value)];
|
|
892
|
-
var existing = acc[key].find(function (item) { return item.field === filter.field; });
|
|
893
|
-
if (existing && !existing.value.includes(value[0])) {
|
|
894
|
-
(_a = existing.value).push.apply(_a, value);
|
|
895
|
-
}
|
|
896
|
-
else {
|
|
897
|
-
acc[key].push({
|
|
898
|
-
field: filter.field,
|
|
899
|
-
value: value,
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
return acc;
|
|
903
|
-
}, {});
|
|
904
|
-
var correctedQuery;
|
|
905
|
-
if (((_c = response === null || response === void 0 ? void 0 : response.search) === null || _c === void 0 ? void 0 : _c.originalQuery) && ((_d = response === null || response === void 0 ? void 0 : response.search) === null || _d === void 0 ? void 0 : _d.query)) {
|
|
906
|
-
correctedQuery = (_e = response === null || response === void 0 ? void 0 : response.search) === null || _e === void 0 ? void 0 : _e.query;
|
|
907
|
-
}
|
|
908
|
-
var campaigns = ((_f = response === null || response === void 0 ? void 0 : response.merchandising) === null || _f === void 0 ? void 0 : _f.campaigns) || [];
|
|
909
|
-
var experiments = ((_g = response === null || response === void 0 ? void 0 : response.merchandising) === null || _g === void 0 ? void 0 : _g.experiments) || [];
|
|
910
|
-
return __assign(__assign({ q: ((_j = (_h = params.search) === null || _h === void 0 ? void 0 : _h.query) === null || _j === void 0 ? void 0 : _j.string) || '', rq: ((_k = params.search) === null || _k === void 0 ? void 0 : _k.subQuery) ? (_l = params.search) === null || _l === void 0 ? void 0 : _l.subQuery : undefined, correctedQuery: correctedQuery, matchType: (_m = response === null || response === void 0 ? void 0 : response.search) === null || _m === void 0 ? void 0 : _m.matchType }, filters), { sort: (_o = params.sorts) === null || _o === void 0 ? void 0 : _o.map(function (sort) {
|
|
911
|
-
return {
|
|
912
|
-
field: sort.field,
|
|
913
|
-
dir: sort.direction,
|
|
914
|
-
};
|
|
915
|
-
}), pagination: {
|
|
916
|
-
totalResults: (_p = response === null || response === void 0 ? void 0 : response.pagination) === null || _p === void 0 ? void 0 : _p.totalResults,
|
|
917
|
-
page: (_q = response === null || response === void 0 ? void 0 : response.pagination) === null || _q === void 0 ? void 0 : _q.page,
|
|
918
|
-
resultsPerPage: (_r = response === null || response === void 0 ? void 0 : response.pagination) === null || _r === void 0 ? void 0 : _r.pageSize,
|
|
919
|
-
}, merchandising: {
|
|
920
|
-
personalized: (_s = response === null || response === void 0 ? void 0 : response.merchandising) === null || _s === void 0 ? void 0 : _s.personalized,
|
|
921
|
-
redirect: (_t = response === null || response === void 0 ? void 0 : response.merchandising) === null || _t === void 0 ? void 0 : _t.redirect,
|
|
922
|
-
triggeredCampaigns: (campaigns.length &&
|
|
923
|
-
campaigns.map(function (campaign) {
|
|
924
|
-
var experiement = experiments.find(function (experiment) { return experiment.campaignId === campaign.id; });
|
|
925
|
-
return {
|
|
926
|
-
id: campaign.id,
|
|
927
|
-
experimentId: experiement === null || experiement === void 0 ? void 0 : experiement.experimentId,
|
|
928
|
-
variationId: experiement === null || experiement === void 0 ? void 0 : experiement.variationId,
|
|
929
|
-
};
|
|
930
|
-
})) ||
|
|
931
|
-
undefined,
|
|
932
|
-
}, banners: [], results: [] });
|
|
933
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isClickWithinBannerLink.d.ts","sourceRoot":"","sources":["../../../src/utils/isClickWithinBannerLink.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,MAAO,UAAU,KAAG,OAcvD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isClickWithinBannerLink = void 0;
|
|
4
|
+
var isClickWithinProductLink_1 = require("./isClickWithinProductLink");
|
|
5
|
+
var TRACKING_ATTRIBUTE = 'sstracking';
|
|
6
|
+
var isClickWithinBannerLink = function (e) {
|
|
7
|
+
var currentElement = e.target;
|
|
8
|
+
var href = null;
|
|
9
|
+
var level = 0;
|
|
10
|
+
while (currentElement && (level < isClickWithinProductLink_1.CLICK_THROUGH_CLOSEST_MAX_LEVELS || !currentElement.getAttribute(TRACKING_ATTRIBUTE))) {
|
|
11
|
+
href = currentElement.getAttribute('href');
|
|
12
|
+
var isAnchor = currentElement.tagName.toLowerCase() === 'a';
|
|
13
|
+
if (href && isAnchor) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
currentElement = currentElement.parentElement;
|
|
17
|
+
level++;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
21
|
+
exports.isClickWithinBannerLink = isClickWithinBannerLink;
|
|
@@ -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"}
|