@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
|
@@ -70,7 +70,6 @@ var deepmerge_1 = __importDefault(require("deepmerge"));
|
|
|
70
70
|
var snap_store_mobx_1 = require("@searchspring/snap-store-mobx");
|
|
71
71
|
var AbstractController_1 = require("../Abstract/AbstractController");
|
|
72
72
|
var types_1 = require("../types");
|
|
73
|
-
var beacon_1 = require("@searchspring/beacon");
|
|
74
73
|
var isClickWithinProductLink_1 = require("../utils/isClickWithinProductLink");
|
|
75
74
|
var defaultConfig = {
|
|
76
75
|
id: 'recommend',
|
|
@@ -86,69 +85,101 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
86
85
|
var _b;
|
|
87
86
|
var _this = _super.call(this, config, { client: client, store: store, urlManager: urlManager, eventManager: eventManager, profiler: profiler, logger: logger, tracker: tracker }, context) || this;
|
|
88
87
|
_this.type = types_1.ControllerTypes.recommendation;
|
|
89
|
-
_this.events = {
|
|
90
|
-
product: {},
|
|
91
|
-
};
|
|
88
|
+
_this.events = {};
|
|
92
89
|
_this.track = {
|
|
93
90
|
product: {
|
|
94
91
|
clickThrough: function (e, result) {
|
|
95
|
-
var _a, _b;
|
|
96
|
-
|
|
92
|
+
var _a, _b, _c, _d;
|
|
93
|
+
var responseId = result.responseId;
|
|
94
|
+
if ((_b = (_a = _this.events[responseId]) === null || _a === void 0 ? void 0 : _a.product[result.id]) === null || _b === void 0 ? void 0 : _b.productClickThrough)
|
|
97
95
|
return;
|
|
98
|
-
var
|
|
96
|
+
var beaconResult = {
|
|
97
|
+
type: result.type,
|
|
98
|
+
uid: result.id,
|
|
99
|
+
parentId: result.id,
|
|
100
|
+
sku: (_c = result.mappings.core) === null || _c === void 0 ? void 0 : _c.sku,
|
|
101
|
+
};
|
|
102
|
+
var data = {
|
|
103
|
+
tag: _this.store.profile.tag,
|
|
104
|
+
responseId: responseId,
|
|
105
|
+
results: [beaconResult],
|
|
106
|
+
};
|
|
99
107
|
_this.eventManager.fire('track.product.clickThrough', { controller: _this, event: e, product: result, trackEvent: data });
|
|
100
|
-
_this.tracker.events.recommendations.clickThrough({ data: data, siteId: (
|
|
101
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
102
|
-
_this.events.product[result.id].
|
|
108
|
+
_this.tracker.events.recommendations.clickThrough({ data: data, siteId: (_d = _this.config.globals) === null || _d === void 0 ? void 0 : _d.siteId });
|
|
109
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
110
|
+
_this.events[responseId].product[result.id].productClickThrough = true;
|
|
103
111
|
},
|
|
104
112
|
click: function (e, result) {
|
|
105
|
-
var _a;
|
|
106
|
-
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
113
|
+
var _a, _b, _c, _d, _e;
|
|
114
|
+
var responseId = result.responseId;
|
|
109
115
|
if (result.type === 'banner') {
|
|
110
|
-
|
|
116
|
+
if ((_b = (_a = _this.events[responseId]) === null || _a === void 0 ? void 0 : _a.product[result.id]) === null || _b === void 0 ? void 0 : _b.inlineBannerClickThrough) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
_this.track.product.clickThrough(e, result);
|
|
120
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
121
|
+
_this.events[responseId].product[result.id].inlineBannerClickThrough = true;
|
|
122
|
+
setTimeout(function () {
|
|
123
|
+
_this.events[responseId].product[result.id].inlineBannerClickThrough = false;
|
|
124
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
125
|
+
}
|
|
126
|
+
else if ((0, isClickWithinProductLink_1.isClickWithinProductLink)(e, result)) {
|
|
127
|
+
if ((_e = (_d = (_c = _this.events) === null || _c === void 0 ? void 0 : _c[responseId]) === null || _d === void 0 ? void 0 : _d.product[result.id]) === null || _e === void 0 ? void 0 : _e.productClickThrough) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
_this.track.product.clickThrough(e, result);
|
|
131
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
132
|
+
_this.events[responseId].product[result.id].productClickThrough = true;
|
|
133
|
+
setTimeout(function () {
|
|
134
|
+
_this.events[responseId].product[result.id].productClickThrough = false;
|
|
135
|
+
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
111
136
|
}
|
|
112
|
-
(0, isClickWithinProductLink_1.isClickWithinProductLink)(e, result) && _this.track.product.clickThrough(e, result);
|
|
113
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
114
|
-
_this.events.product[result.id].click = true;
|
|
115
|
-
setTimeout(function () {
|
|
116
|
-
_this.events.product[result.id].click = false;
|
|
117
|
-
}, isClickWithinProductLink_1.CLICK_DUPLICATION_TIMEOUT);
|
|
118
137
|
},
|
|
119
138
|
impression: function (result) {
|
|
120
|
-
var _a, _b, _c;
|
|
121
|
-
|
|
139
|
+
var _a, _b, _c, _d;
|
|
140
|
+
var responseId = result.responseId;
|
|
141
|
+
if ((_b = (_a = _this.events[responseId]) === null || _a === void 0 ? void 0 : _a.product[result.id]) === null || _b === void 0 ? void 0 : _b.impression) {
|
|
122
142
|
return;
|
|
123
|
-
|
|
143
|
+
}
|
|
144
|
+
var item = {
|
|
145
|
+
type: result.type,
|
|
146
|
+
uid: result.id,
|
|
147
|
+
parentId: result.id,
|
|
148
|
+
sku: (_c = result.mappings.core) === null || _c === void 0 ? void 0 : _c.sku,
|
|
149
|
+
};
|
|
150
|
+
var data = {
|
|
151
|
+
tag: _this.store.profile.tag,
|
|
152
|
+
responseId: responseId,
|
|
153
|
+
results: [item],
|
|
154
|
+
banners: [],
|
|
155
|
+
};
|
|
124
156
|
_this.eventManager.fire('track.product.impression', { controller: _this, product: result, trackEvent: data });
|
|
125
|
-
_this.tracker.events.recommendations.impression({ data: data, siteId: (
|
|
126
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
127
|
-
_this.events.product[result.id].impression = true;
|
|
128
|
-
return data;
|
|
129
|
-
},
|
|
130
|
-
render: function (result) {
|
|
131
|
-
var _a, _b;
|
|
132
|
-
if ((_a = _this.events.product[result.id]) === null || _a === void 0 ? void 0 : _a.render)
|
|
133
|
-
return;
|
|
134
|
-
var data = getRecommendationsSchemaData({ store: _this.store, results: [result] });
|
|
135
|
-
_this.eventManager.fire('track.product.render', { controller: _this, product: result, trackEvent: data });
|
|
136
|
-
_this.tracker.events.recommendations.render({ data: data, siteId: (_b = _this.config.globals) === null || _b === void 0 ? void 0 : _b.siteId });
|
|
137
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
138
|
-
_this.events.product[result.id].render = true;
|
|
139
|
-
return data;
|
|
157
|
+
_this.tracker.events.recommendations.impression({ data: data, siteId: (_d = _this.config.globals) === null || _d === void 0 ? void 0 : _d.siteId });
|
|
158
|
+
_this.events[responseId].product[result.id] = _this.events[responseId].product[result.id] || {};
|
|
159
|
+
_this.events[responseId].product[result.id].impression = true;
|
|
140
160
|
},
|
|
141
161
|
addToCart: function (result) {
|
|
142
|
-
var _a;
|
|
143
|
-
var
|
|
162
|
+
var _a, _b, _c;
|
|
163
|
+
var responseId = result.responseId;
|
|
164
|
+
var product = {
|
|
165
|
+
parentId: result.id,
|
|
166
|
+
uid: result.id,
|
|
167
|
+
sku: (_a = result.mappings.core) === null || _a === void 0 ? void 0 : _a.sku,
|
|
168
|
+
qty: result.quantity || 1,
|
|
169
|
+
price: Number((_b = result.mappings.core) === null || _b === void 0 ? void 0 : _b.price),
|
|
170
|
+
};
|
|
171
|
+
var data = {
|
|
172
|
+
responseId: responseId,
|
|
173
|
+
tag: _this.store.profile.tag,
|
|
174
|
+
results: [product],
|
|
175
|
+
};
|
|
144
176
|
_this.eventManager.fire('track.product.addToCart', { controller: _this, product: result, trackEvent: data });
|
|
145
|
-
_this.tracker.events.recommendations.addToCart({ data: data, siteId: (
|
|
146
|
-
return data;
|
|
177
|
+
_this.tracker.events.recommendations.addToCart({ data: data, siteId: (_c = _this.config.globals) === null || _c === void 0 ? void 0 : _c.siteId });
|
|
147
178
|
},
|
|
148
179
|
},
|
|
149
180
|
};
|
|
150
181
|
_this.search = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
151
|
-
var params, err_1, searchProfile, response, afterSearchProfile, err_2, afterStoreProfile, err_3, err_4;
|
|
182
|
+
var params, err_1, searchProfile, response, responseId, afterSearchProfile, err_2, afterStoreProfile, err_3, err_4;
|
|
152
183
|
return __generator(this, function (_a) {
|
|
153
184
|
switch (_a.label) {
|
|
154
185
|
case 0:
|
|
@@ -160,8 +191,6 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
160
191
|
_a.label = 2;
|
|
161
192
|
case 2:
|
|
162
193
|
params = this.params;
|
|
163
|
-
// reset events for new search
|
|
164
|
-
this.events = { product: {} };
|
|
165
194
|
this.store.loading = true;
|
|
166
195
|
_a.label = 3;
|
|
167
196
|
case 3:
|
|
@@ -191,6 +220,8 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
191
220
|
response = _a.sent();
|
|
192
221
|
searchProfile.stop();
|
|
193
222
|
this.log.profile(searchProfile);
|
|
223
|
+
responseId = response.responseId;
|
|
224
|
+
this.events[responseId] = this.events[responseId] || { product: {} };
|
|
194
225
|
afterSearchProfile = this.profiler.create({ type: 'event', name: 'afterSearch', context: params }).start();
|
|
195
226
|
_a.label = 8;
|
|
196
227
|
case 8:
|
|
@@ -327,8 +358,7 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
327
358
|
_this.config = (0, deepmerge_1.default)(defaultConfig, _this.config);
|
|
328
359
|
_this.store.setConfig(_this.config);
|
|
329
360
|
_this.eventManager.on('afterStore', function (search, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
330
|
-
var controller,
|
|
331
|
-
var _this = this;
|
|
361
|
+
var controller, responseId, data;
|
|
332
362
|
var _a;
|
|
333
363
|
return __generator(this, function (_b) {
|
|
334
364
|
switch (_b.label) {
|
|
@@ -336,22 +366,12 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
336
366
|
case 1:
|
|
337
367
|
_b.sent();
|
|
338
368
|
controller = search.controller;
|
|
369
|
+
responseId = search.response.responseId;
|
|
339
370
|
if (controller.store.loaded && !controller.store.error) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
data = getRecommendationsSchemaData({ store: this.store });
|
|
343
|
-
this.eventManager.fire('track.product.render', { controller: this, trackEvent: data });
|
|
371
|
+
if (!search.response._cached) {
|
|
372
|
+
data = { responseId: responseId, tag: controller.store.profile.tag };
|
|
344
373
|
this.tracker.events.recommendations.render({ data: data, siteId: (_a = this.config.globals) === null || _a === void 0 ? void 0 : _a.siteId });
|
|
345
374
|
}
|
|
346
|
-
products.forEach(function (result) {
|
|
347
|
-
if (!search.response._cached) {
|
|
348
|
-
_this.track.product.render(result);
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
_this.events.product[result.id] = _this.events.product[result.id] || {};
|
|
352
|
-
_this.events.product[result.id].render = true;
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
375
|
}
|
|
356
376
|
return [2 /*return*/];
|
|
357
377
|
}
|
|
@@ -397,34 +417,3 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
397
417
|
return RecommendationController;
|
|
398
418
|
}(AbstractController_1.AbstractController));
|
|
399
419
|
exports.RecommendationController = RecommendationController;
|
|
400
|
-
function getRecommendationsAddtocartSchemaData(_a) {
|
|
401
|
-
var store = _a.store, results = _a.results;
|
|
402
|
-
return {
|
|
403
|
-
tag: store.profile.tag,
|
|
404
|
-
results: (results === null || results === void 0 ? void 0 : results.map(function (result) {
|
|
405
|
-
var core = result.mappings.core;
|
|
406
|
-
return {
|
|
407
|
-
uid: (core === null || core === void 0 ? void 0 : core.uid) || '',
|
|
408
|
-
sku: core === null || core === void 0 ? void 0 : core.sku,
|
|
409
|
-
price: Number(core === null || core === void 0 ? void 0 : core.price),
|
|
410
|
-
qty: result.quantity || 1,
|
|
411
|
-
};
|
|
412
|
-
})) || [],
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
function getRecommendationsSchemaData(_a) {
|
|
416
|
-
var store = _a.store, results = _a.results;
|
|
417
|
-
return {
|
|
418
|
-
tag: store.profile.tag,
|
|
419
|
-
results: (results === null || results === void 0 ? void 0 : results.map(function (result) {
|
|
420
|
-
var core = result.mappings.core;
|
|
421
|
-
var position = result.position;
|
|
422
|
-
return {
|
|
423
|
-
type: beacon_1.ItemTypeEnum.Product,
|
|
424
|
-
position: position,
|
|
425
|
-
uid: core.uid || '',
|
|
426
|
-
sku: core.sku,
|
|
427
|
-
};
|
|
428
|
-
})) || [],
|
|
429
|
-
};
|
|
430
|
-
}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { AbstractController } from '../Abstract/AbstractController';
|
|
2
|
-
import { StorageStore } from '@searchspring/snap-store-mobx';
|
|
2
|
+
import { StorageStore, MerchandisingContentBanner } from '@searchspring/snap-store-mobx';
|
|
3
3
|
import { ControllerTypes } from '../types';
|
|
4
4
|
import type { Product, Banner, SearchStore } from '@searchspring/snap-store-mobx';
|
|
5
5
|
import type { SearchControllerConfig, ControllerServices, ContextVariables } from '../types';
|
|
6
6
|
import { type SearchRequestModel } from '@searchspring/snapi-types';
|
|
7
7
|
type SearchTrackMethods = {
|
|
8
|
+
banner: {
|
|
9
|
+
click: (e: MouseEvent, merchandisingBanner: MerchandisingContentBanner) => void;
|
|
10
|
+
clickThrough: (e: MouseEvent, merchandisingBanner: MerchandisingContentBanner) => void;
|
|
11
|
+
impression: (merchandisingBanner: MerchandisingContentBanner) => void;
|
|
12
|
+
};
|
|
8
13
|
product: {
|
|
9
|
-
clickThrough: (e: MouseEvent, result: Product) => void;
|
|
14
|
+
clickThrough: (e: MouseEvent, result: Product | Banner) => void;
|
|
10
15
|
click: (e: MouseEvent, result: Product | Banner) => void;
|
|
11
|
-
|
|
12
|
-
impression: (result: Product) => void;
|
|
16
|
+
impression: (result: Product | Banner) => void;
|
|
13
17
|
addToCart: (results: Product) => void;
|
|
14
18
|
};
|
|
15
|
-
redirect: (redirectURL
|
|
19
|
+
redirect: ({ redirectURL, responseId }: {
|
|
20
|
+
redirectURL: string;
|
|
21
|
+
responseId: string;
|
|
22
|
+
}) => void;
|
|
16
23
|
};
|
|
17
24
|
export declare class SearchController extends AbstractController {
|
|
18
25
|
type: ControllerTypes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchController.d.ts","sourceRoot":"","sources":["../../../src/Search/SearchController.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAa,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"SearchController.d.ts","sourceRoot":"","sources":["../../../src/Search/SearchController.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAa,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAEpG,OAAO,EAAE,eAAe,EAAuB,MAAM,UAAU,CAAC;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAc,MAAM,+BAA+B,CAAC;AAC9F,OAAO,KAAK,EACX,sBAAsB,EAGtB,kBAAkB,EAClB,gBAAgB,EAIhB,MAAM,UAAU,CAAC;AAElB,OAAO,EACN,KAAK,kBAAkB,EAYvB,MAAM,2BAA2B,CAAC;AAsCnC,KAAK,kBAAkB,GAAG;IACzB,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,gBAAiB,SAAQ,kBAAkB;IAChD,IAAI,kBAA0B;IAC7B,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,sBAAsB,CAAC;IACvC,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,eAAe,CAAwC;IAC/D,OAAO,CAAC,IAAI,CAEV;IACF,OAAO,CAAC,MAAM,CAgBP;gBAGN,MAAM,EAAE,sBAAsB,EAC9B,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,kBAAkB,EAC1F,OAAO,CAAC,EAAE,gBAAgB;IAsP3B,KAAK,EAAE,kBAAkB,CAqKvB;IAEF,IAAI,MAAM,IAAI,kBAAkB,CA8C/B;IAED,MAAM,QAAa,QAAQ,IAAI,CAAC,CA0N9B;IAEF,SAAS,cAAqB,OAAO,EAAE,GAAG,OAAO,KAAG,QAAQ,IAAI,CAAC,CAQ/D;CACF;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,CAiBxF;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,MAAM,GAAG,SAAS,CAgCvG"}
|