@sentecacommerce-theme/lib 0.12.89 → 0.12.90

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.
Files changed (31) hide show
  1. package/dist/cjs/analytics/Pixel/hooks/index.js +36 -0
  2. package/dist/cjs/analytics/Pixel/hooks/usePixelFinishOrder.js +27 -0
  3. package/dist/cjs/analytics/Pixel/hooks/usePixelViewBasket.js +24 -0
  4. package/dist/cjs/analytics/Pixel/hooks/usePixelViewCategory.js +22 -0
  5. package/dist/cjs/analytics/Pixel/mainScript.js +197 -14
  6. package/dist/cjs/analytics/Pixel/minifiedPixel.js +1 -1
  7. package/dist/cjs/analytics/Pixel/usePixel.js +3 -0
  8. package/dist/cjs/analytics/Pixel/utils.js +17 -0
  9. package/dist/cjs/hooks/ui-hooks/useAccordion/index.js +0 -1
  10. package/dist/cjs/listing/api/queries/useListingQuery.js +4 -2
  11. package/dist/cjs/listing/ssr/prefetchListing.js +2 -1
  12. package/dist/esm/analytics/Pixel/hooks/index.js +3 -0
  13. package/dist/esm/analytics/Pixel/hooks/usePixelFinishOrder.js +22 -0
  14. package/dist/esm/analytics/Pixel/hooks/usePixelViewBasket.js +19 -0
  15. package/dist/esm/analytics/Pixel/hooks/usePixelViewCategory.js +17 -0
  16. package/dist/esm/analytics/Pixel/mainScript.js +199 -14
  17. package/dist/esm/analytics/Pixel/minifiedPixel.js +1 -1
  18. package/dist/esm/analytics/Pixel/usePixel.js +3 -0
  19. package/dist/esm/analytics/Pixel/utils.js +12 -0
  20. package/dist/esm/hooks/ui-hooks/useAccordion/index.js +0 -1
  21. package/dist/esm/listing/api/queries/useListingQuery.js +4 -2
  22. package/dist/esm/listing/ssr/prefetchListing.js +2 -1
  23. package/dist/types/analytics/Pixel/hooks/index.d.ts +3 -0
  24. package/dist/types/analytics/Pixel/hooks/usePixelFinishOrder.d.ts +4 -0
  25. package/dist/types/analytics/Pixel/hooks/usePixelViewBasket.d.ts +4 -0
  26. package/dist/types/analytics/Pixel/hooks/usePixelViewCategory.d.ts +3 -0
  27. package/dist/types/analytics/Pixel/types.d.ts +9 -0
  28. package/dist/types/analytics/Pixel/utils.d.ts +3 -0
  29. package/dist/types/listing/api/queries/useListingQuery.d.ts +2 -1
  30. package/dist/types/listing/types.d.ts +3 -2
  31. package/package.json +4 -4
@@ -38,6 +38,42 @@ Object.keys(_usePixelProductClick).forEach(function(key) {
38
38
  }
39
39
  });
40
40
  });
41
+ var _usePixelViewBasket = _interopRequireWildcard(require("./usePixelViewBasket"));
42
+ Object.keys(_usePixelViewBasket).forEach(function(key) {
43
+ if (key === "default" || key === "__esModule") return;
44
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
45
+ if (key in exports && exports[key] === _usePixelViewBasket[key]) return;
46
+ Object.defineProperty(exports, key, {
47
+ enumerable: true,
48
+ get: function() {
49
+ return _usePixelViewBasket[key];
50
+ }
51
+ });
52
+ });
53
+ var _usePixelViewCategory = _interopRequireWildcard(require("./usePixelViewCategory"));
54
+ Object.keys(_usePixelViewCategory).forEach(function(key) {
55
+ if (key === "default" || key === "__esModule") return;
56
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
57
+ if (key in exports && exports[key] === _usePixelViewCategory[key]) return;
58
+ Object.defineProperty(exports, key, {
59
+ enumerable: true,
60
+ get: function() {
61
+ return _usePixelViewCategory[key];
62
+ }
63
+ });
64
+ });
65
+ var _usePixelFinishOrder = _interopRequireWildcard(require("./usePixelFinishOrder"));
66
+ Object.keys(_usePixelFinishOrder).forEach(function(key) {
67
+ if (key === "default" || key === "__esModule") return;
68
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
69
+ if (key in exports && exports[key] === _usePixelFinishOrder[key]) return;
70
+ Object.defineProperty(exports, key, {
71
+ enumerable: true,
72
+ get: function() {
73
+ return _usePixelFinishOrder[key];
74
+ }
75
+ });
76
+ });
41
77
  var _useDistrictMeta = _interopRequireWildcard(require("./useDistrictMeta"));
42
78
  Object.keys(_useDistrictMeta).forEach(function(key) {
43
79
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,27 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.usePixelFinishOrder = void 0;
5
+ var _utils = require("../utils");
6
+ var _typeof = function(obj) {
7
+ "@swc/helpers - typeof";
8
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
9
+ };
10
+ var usePixelFinishOrder = function() {
11
+ var sendFinishOrderEvent = function(order) {
12
+ var payload = {
13
+ orderId: order.orderRefNumber,
14
+ productsData: (0, _utils).mapProducts(order.lineItems)
15
+ };
16
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
17
+ var pixel = window.pixel;
18
+ if (payload) {
19
+ pixel.finishOrder(payload);
20
+ }
21
+ }
22
+ };
23
+ return {
24
+ sendFinishOrderEvent: sendFinishOrderEvent
25
+ };
26
+ };
27
+ exports.usePixelFinishOrder = usePixelFinishOrder;
@@ -0,0 +1,24 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.usePixelViewBasket = void 0;
5
+ var _utils = require("../utils");
6
+ var _typeof = function(obj) {
7
+ "@swc/helpers - typeof";
8
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
9
+ };
10
+ var usePixelViewBasket = function() {
11
+ var sendViewBasketEvent = function(data) {
12
+ var payload = (0, _utils).mapProducts(data);
13
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
14
+ var pixel = window.pixel;
15
+ if (payload) {
16
+ pixel.viewBasket(payload);
17
+ }
18
+ }
19
+ };
20
+ return {
21
+ sendViewBasketEvent: sendViewBasketEvent
22
+ };
23
+ };
24
+ exports.usePixelViewBasket = usePixelViewBasket;
@@ -0,0 +1,22 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.usePixelViewCategory = void 0;
5
+ var _typeof = function(obj) {
6
+ "@swc/helpers - typeof";
7
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
8
+ };
9
+ var usePixelViewCategory = function() {
10
+ var sendViewCategoryEvent = function(categoryBreadcrumb) {
11
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
12
+ var pixel = window.pixel;
13
+ if (categoryBreadcrumb) {
14
+ pixel.viewCategory(categoryBreadcrumb);
15
+ }
16
+ }
17
+ };
18
+ return {
19
+ sendViewCategoryEvent: sendViewCategoryEvent
20
+ };
21
+ };
22
+ exports.usePixelViewCategory = usePixelViewCategory;
@@ -88,16 +88,6 @@ function _objectSpread(target) {
88
88
  }
89
89
  });
90
90
  }
91
- function ensureStringValuesMayExist() {
92
- var params = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, keys = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
93
- keys.forEach(function(k) {
94
- if (params[k]) {
95
- if (typeof params[k] !== 'string') {
96
- err("".concat(k, " is empty or contains invalid string value"));
97
- }
98
- }
99
- });
100
- }
101
91
  function ensureStringValuesExist() {
102
92
  var params = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, keys = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
103
93
  keys.forEach(function(k) {
@@ -115,18 +105,20 @@ function _objectSpread(target) {
115
105
  //check the config
116
106
  if (typeof global.pixel_cfg !== 'object') {
117
107
  err('Pixel is missing config');
118
- } else if (!global.pixel_cfg.initialUserId || !global.pixel_cfg.appName) {
119
- err('Missing required pixel config fields. Please check if appName and initialUserId are present.');
108
+ } else if (!global.pixel_cfg.hubUrl || !global.pixel_cfg.initialUserId || !global.pixel_cfg.appName) {
109
+ err('Missing required pixel config fields. Please check if appName, hubUrl and initialUserId are present.');
120
110
  }
121
111
  /**
112
+ * hubUrl = the url of the integration hub
122
113
  * source = name of the client interface eg: app, website
123
114
  * debug = either or not to print logs
124
115
  * initialUserId = the initial id of the user/visitor
125
- */ var _pixel_cfg = global.pixel_cfg, appName = _pixel_cfg.appName, _source = _pixel_cfg.source, source = _source === void 0 ? 'web-client' : _source, _debug = _pixel_cfg.debug, debug = _debug === void 0 ? false : _debug, initialUserId = _pixel_cfg.initialUserId;
116
+ */ var _pixel_cfg = global.pixel_cfg, hubUrl = _pixel_cfg.hubUrl, appName = _pixel_cfg.appName, _source = _pixel_cfg.source, source = _source === void 0 ? 'web-client' : _source, _debug = _pixel_cfg.debug, debug = _debug === void 0 ? false : _debug, _criteoPartnerId = _pixel_cfg.criteoPartnerId, criteoPartnerId = _criteoPartnerId === void 0 ? false : _criteoPartnerId, _rtbHouseHash = _pixel_cfg.rtbHouseHash, rtbHouseHash = _rtbHouseHash === void 0 ? false : _rtbHouseHash, initialUserId = _pixel_cfg.initialUserId;
126
117
  var Q = [] //events queue
127
118
  ;
128
119
  var userId = initialUserId //is modified upon setUserId
129
120
  ;
121
+ var userEmail = '';
130
122
  var title = undefined;
131
123
  var allowTracking = false //should explicity state positive intention
132
124
  ;
@@ -161,8 +153,9 @@ function _objectSpread(target) {
161
153
  log("sending.. payload=".concat(JSON.stringify(payload)));
162
154
  _ctx.prev = 1;
163
155
  _ctx.next = 4;
164
- return fetch("/hub/analytics/collect", {
156
+ return fetch("".concat(hubUrl, "/analytics/collect"), {
165
157
  method: 'POST',
158
+ mode: 'cors',
166
159
  cache: 'no-cache',
167
160
  headers: {
168
161
  'Content-Type': 'application/json'
@@ -199,6 +192,54 @@ function _objectSpread(target) {
199
192
  log("adding new event to queue ".concat(JSON.stringify(enrichedPayload)));
200
193
  Q.push(enrichedPayload);
201
194
  }
195
+ function dispatchCriteoEvents(events) {
196
+ if (criteoPartnerId) {
197
+ window.criteo_q = window.criteo_q || [];
198
+ window.criteo_q.push(events);
199
+ }
200
+ }
201
+ function sendRtbRequest(tag) {
202
+ if (rtbHouseHash) {
203
+ try {
204
+ var rtbTags = [
205
+ "pr_".concat(rtbHouseHash, "_").concat(tag)
206
+ ];
207
+ rtbTags.push("pr_".concat(rtbHouseHash, "_lid_").concat(getLid()));
208
+ var ifr = document.createElement('iframe'), sr = encodeURIComponent(document.referrer ? document.referrer : ''), su = encodeURIComponent(document.location.href ? document.location.href : ''), tmstmp = encodeURIComponent('' + Date.now());
209
+ var ifrSrc = 'https://creativecdn.com/tags?type=iframe';
210
+ for(var i = 0; i < rtbTags.length; i++){
211
+ ifrSrc += '&id=' + encodeURIComponent(rtbTags[i]);
212
+ }
213
+ ifrSrc += "&su=".concat(su, "&sr=").concat(sr, "&ts=").concat(tmstmp);
214
+ ifr.setAttribute('src', ifrSrc);
215
+ ifr.setAttribute('width', '1');
216
+ ifr.setAttribute('height', '1');
217
+ ifr.setAttribute('scrolling', 'no');
218
+ ifr.setAttribute('frameBorder', '0');
219
+ ifr.setAttribute('style', 'display:none');
220
+ ifr.setAttribute('referrerpolicy', 'no-referrer-when-downgrade');
221
+ if (document.body) {
222
+ document.body.appendChild(ifr);
223
+ } else {
224
+ window.addEventListener('DOMContentLoaded', function() {
225
+ document.body.appendChild(ifr);
226
+ });
227
+ }
228
+ } catch (e) {
229
+ log(e);
230
+ }
231
+ }
232
+ }
233
+ function getLid() {
234
+ var key = '__rtbhouse.lid', lid = window.localStorage.getItem(key);
235
+ if (!lid) {
236
+ lid = '';
237
+ var pool = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
238
+ for(var i = 0; i < 20; i++)lid += pool.charAt(Math.floor(Math.random() * pool.length));
239
+ window.localStorage.setItem(key, lid);
240
+ }
241
+ return lid;
242
+ }
202
243
  function loop() {
203
244
  var iid = global.setTimeout(_asyncToGenerator(_regeneratorRuntime.default.mark(function _callee() {
204
245
  var ev;
@@ -236,6 +277,113 @@ function _objectSpread(target) {
236
277
  ]);
237
278
  })), 500);
238
279
  }
280
+ var criteoAPI = {
281
+ loadCriteo: function loadCriteo() {
282
+ if (criteoPartnerId) {
283
+ log('Loading criteo');
284
+ var criteo = document.createElement('script');
285
+ criteo.setAttribute('src', "//dynamic.criteo.com/js/ld/ld.js?a=".concat(criteoPartnerId));
286
+ document.head.appendChild(criteo);
287
+ dispatchCriteoEvents([
288
+ {
289
+ event: 'setAccount',
290
+ account: criteoPartnerId
291
+ },
292
+ {
293
+ event: 'setEmail',
294
+ email: userEmail
295
+ },
296
+ {
297
+ event: 'setSiteType',
298
+ type: isTouchDevice() ? 'm' : 'd'
299
+ },
300
+ ]);
301
+ }
302
+ log('criteo partner id not set');
303
+ },
304
+ criteoViewHome: function criteoViewHome() {
305
+ console.log('criteoViewHome');
306
+ dispatchCriteoEvents({
307
+ event: 'viewHome'
308
+ });
309
+ },
310
+ //productData: [{ id: sku, price, quantity}]
311
+ criteoViewBasket: function criteoViewBasket(productsData) {
312
+ dispatchCriteoEvents({
313
+ event: 'viewBasket',
314
+ item: productsData
315
+ });
316
+ },
317
+ //productData: { sku }
318
+ criteoViewItem: function criteoViewItem(productData) {
319
+ dispatchCriteoEvents({
320
+ event: 'viewItem',
321
+ item: productData.sku
322
+ });
323
+ },
324
+ //products: [{ sku }]
325
+ criteoViewList: function criteoViewList(products) {
326
+ var items = products.map(function(product) {
327
+ return product.sku;
328
+ });
329
+ dispatchCriteoEvents({
330
+ event: 'viewList',
331
+ item: items
332
+ });
333
+ },
334
+ //orderId: Order ref number
335
+ //productData: [{ id: sku, price, quantity}]
336
+ criteoFinishOrder: function criteoFinishOrder(orderId, productsData) {
337
+ dispatchCriteoEvents({
338
+ event: 'trackTransaction',
339
+ id: orderId,
340
+ item: productsData
341
+ });
342
+ },
343
+ criteoChangeEmail: function criteoChangeEmail(email) {
344
+ dispatchCriteoEvents({
345
+ event: 'setEmail',
346
+ email: email
347
+ });
348
+ }
349
+ };
350
+ var rtbAPI = {
351
+ rtbViewHome: function rtbViewHome() {
352
+ sendRtbRequest("home");
353
+ },
354
+ //productData: [{ id: sku}]
355
+ rtbViewBasket: function rtbViewBasket(productsData) {
356
+ sendRtbRequest("basketstatus_".concat(productsData.map(function(product) {
357
+ return product.sku;
358
+ }).join(',')));
359
+ },
360
+ //productData: { sku }
361
+ rtbViewItem: function rtbViewItem(productData) {
362
+ sendRtbRequest("offer_".concat(productData.sku));
363
+ },
364
+ //products: [{ sku }]
365
+ rtbViewList: function rtbViewList(products) {
366
+ var items = products.map(function(product) {
367
+ return product.sku;
368
+ });
369
+ sendRtbRequest("listing_".concat(items[0], ",").concat(items[1], ",").concat(items[2], ",").concat(items[3], ",").concat(items[4]));
370
+ },
371
+ //categoryBreadcrumb: string
372
+ rtbViewCategory: function rtbViewCategory(categoryBreadcrumb) {
373
+ sendRtbRequest("category2_".concat(categoryBreadcrumb));
374
+ },
375
+ rtbStartOrder: function rtbStartOrder() {
376
+ sendRtbRequest("startorder");
377
+ },
378
+ //orderId: Order ref number
379
+ //productData: [{ id: sku, price, quantity}]
380
+ rtbFinishOrder: function rtbFinishOrder(orderId, productsData, orderPrice) {
381
+ var productIds = productsData.map(function(product) {
382
+ return product.sku;
383
+ }).join(',');
384
+ sendRtbRequest("orderstatus2_".concat(orderPrice, "_").concat(orderId, "_").concat(productIds));
385
+ }
386
+ };
239
387
  function buildProductPayload(productData) {
240
388
  var payload = {};
241
389
  ensureStringValuesExist(productData, [
@@ -279,9 +427,33 @@ function _objectSpread(target) {
279
427
  addEventToQueue('land', eventPayload);
280
428
  }
281
429
  },
430
+ viewHome: function viewHome() {
431
+ console.log('viewHome');
432
+ criteoAPI.criteoViewHome();
433
+ rtbAPI.rtbViewHome();
434
+ },
435
+ //productsData: [{ id: sku, price, quantity}]
436
+ viewBasket: function viewBasket(productDetails) {
437
+ criteoAPI.criteoViewBasket(productDetails);
438
+ rtbAPI.rtbViewBasket(productDetails);
439
+ },
440
+ //categoryBreadcrumb
441
+ viewCategory: function(categoryBreadcrumb) {
442
+ rtbAPI.rtbViewCategory(categoryBreadcrumb);
443
+ },
444
+ //orderId: Order ref number
445
+ //productsData: [{ id: sku, price, quantity}]
446
+ //orderPrice: total price of order
447
+ finishOrder: function finishOrder(orderId, productsData, orderPrice) {
448
+ criteoAPI.criteoFinishOrder(orderId, productsData);
449
+ rtbAPI.rtbFinishOrder(orderId, productsData, orderPrice);
450
+ },
282
451
  //used when user logs in or other occasion on which the id in cookie changes
283
452
  changeUser: function changeUser(newUserId) {
453
+ var newUserEmail = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '';
284
454
  userId = newUserId;
455
+ userEmail = newUserEmail;
456
+ criteoAPI.criteoChangeEmail(userEmail);
285
457
  },
286
458
  //Should be set on each app start/refresh. Marks if IP & other user data can be tracked
287
459
  agreeTracking: function agreeTracking() {
@@ -318,6 +490,8 @@ function _objectSpread(target) {
318
490
  var eventPayload = productLists.map(function(list) {
319
491
  var name = list.listName;
320
492
  var merchantKey = priceData.merchantKey;
493
+ criteoAPI.criteoViewList(list.products);
494
+ rtbAPI.rtbViewList(list.products);
321
495
  var products = list.products.map(function(product) {
322
496
  return buildProductPayload(product);
323
497
  });
@@ -334,6 +508,8 @@ function _objectSpread(target) {
334
508
  ensureStringValuesExist(priceData, [
335
509
  'merchantKey'
336
510
  ]);
511
+ criteoAPI.criteoViewItem(productData);
512
+ rtbAPI.rtbViewItem(productData);
337
513
  var product = buildProductPayload(productData);
338
514
  addEventToQueue('productDetails', _objectSpread({
339
515
  product: product
@@ -362,6 +538,9 @@ function _objectSpread(target) {
362
538
  }, priceData));
363
539
  },
364
540
  checkoutStep: function checkoutStep(orderId, stepNumber) {
541
+ if (stepNumber === 1) {
542
+ rtbAPI.rtbStartOrder(orderId);
543
+ }
365
544
  ensureIsStringValue('orderId', orderId);
366
545
  addEventToQueue('checkoutStep', {
367
546
  orderId: orderId,
@@ -377,7 +556,11 @@ function _objectSpread(target) {
377
556
  });
378
557
  }
379
558
  };
559
+ criteoAPI.loadCriteo();
380
560
  API.__system__.land();
381
561
  global.pixel = API;
562
+ function isTouchDevice() {
563
+ return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
564
+ }
382
565
  loop();
383
566
  })(window);
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", {
3
3
  });
4
4
  exports.PixelScript = void 0;
5
5
  var PixelScript = function() {
6
- return '!function(i){function o(e){t&&console.info(e)}function c(e){throw new Error(e)}function a(t={},e=[]){e.forEach(e=>{"string"!=typeof t[e]&&c(`${e} is empty or contains invalid string value`)})}function r(e="",t={}){"string"!=typeof t&&c(`${e} is empty or contains invalid string value`)}"object"!=typeof i.pixel_cfg?c("Pixel is missing config"):i.pixel_cfg.initialUserId&&i.pixel_cfg.appName||c("Missing required pixel config fields. Please check if appName and initialUserId are present.");const{appName:n,source:s="web-client",debug:t=!1,initialUserId:u}=i.pixel_cfg,l=[];let d=u,p=void 0,m=!1;function f(e,t={}){(t={name:e,data:t}).meta={userId:d,appName:n,allowTracking:m,source:s,userAgent:i.navigator.userAgent,location:i.location.href,language:i.navigator.language,charset:i.document.characterSet,title:p=p??i.document.title,referrer:i.document.referrer,screenResolution:`${i.screen.width}x${i.screen.height}`,viewportSize:`${i.innerWidth}x${i.innerHeight}`};o(`adding new event to queue ${JSON.stringify(t)}`),l.push(t)}function h(e){let t={};var n,i;return a(e,["id","sku"]),[n={},i]=[e,["quantity"]],i.forEach(e=>{n[e]&&Number.isNaN(Number(n[e]))&&c(`${e} is empty or contains invalid numeric value`)}),t.id=e.id,t.sku=e.sku,t.quantity&&(t.quantity=e.quantity),t}function g(e){let t={};var n,i;return a(e,["listName","merchantKey"]),[n={},i]=[e,["position"]],i.forEach(e=>{Number.isNaN(Number(n[e]))&&c(`${e} is empty or contains invalid numeric value`)}),t.listName=e.listName,t.position=e.position,t.merchantKey=e.merchantKey,t}var e={__system__:{land:function(){f("land",{originalQuery:i.location.search})}},changeUser:function(e){d=e},agreeTracking:function(){m=!0},changeRoute:function(e={}){let t={};a(e,["path","title","location"]),p=e.title,t.path=e.path,t.title=e.title,t.location=e.location,f("changeRoute",t)},productClick:function(e={},t={}){f("productClick",{product:h(e),click:g(t)})},productsImpression:function(e=[],t={}){a(t,["merchantKey"]),f("productsImpression",e.map(function(e){return{name:e.listName,merchantKey:t.merchantKey,products:e.products.map(h)}}))},productDetails:function(e={},t={}){a(t,["merchantKey"]),f("productDetails",{product:h(e),...t})},addLineItem:function(e={},t={}){a(t,["currencyCode","merchantKey"]),f("addLineItem",{product:h(e),...t})},removeLineItem:function(e={},t={}){a(t,["currencyCode","merchantKey"]),f("removeLineItem",{product:h(e),...t})},checkoutStep:function(e,t){r("orderId",e),f("checkoutStep",{orderId:e,stepNumber:t})},checkoutStepOption:function(e,t,n){r("orderId",e),f("checkoutStepOption",{orderId:e,stepNumber:t,optionName:n})}};e.__system__.land(),i.pixel=e,function t(){let n=i.setTimeout(async function(){if(o("loop"),u&&l.length){var e=l.shift();try{await async function(e){o(`sending.. payload=${JSON.stringify(e)}`);try{await fetch("/hub/analytics/collect",{method:"POST",cache:"no-cache",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}catch(e){console.error(`Failed to send event.. ${e.message}`)}}(e)}catch(e){o(`Failed to send event.. ${e.message}`)}}i.clearInterval(n),t()},500)}()}(window);';
6
+ return '!function(n){function a(e){t&&console.info(e)}function o(e){throw new Error(e)}function r(t={},e=[]){e.forEach(e=>{"string"!=typeof t[e]&&o(`${e} is empty or contains invalid string value`)})}function c(e="",t={}){"string"!=typeof t&&o(`${e} is empty or contains invalid string value`)}"object"!=typeof n.pixel_cfg?o("Pixel is missing config"):n.pixel_cfg.hubUrl&&n.pixel_cfg.initialUserId&&n.pixel_cfg.appName||o("Missing required pixel config fields. Please check if appName, hubUrl and initialUserId are present.");const{hubUrl:s,appName:i,source:u="web-client",debug:t=!1,criteoPartnerId:d=!1,rtbHouseHash:l=!1,initialUserId:m}=n.pixel_cfg,p=[];let f=m,h="",g=void 0,w=!1;function y(e,t={}){(t={name:e,data:t}).meta={userId:f,appName:i,allowTracking:w,source:u,userAgent:n.navigator.userAgent,location:n.location.href,language:n.navigator.language,charset:n.document.characterSet,title:g=g??n.document.title,referrer:n.document.referrer,screenResolution:`${n.screen.width}x${n.screen.height}`,viewportSize:`${n.innerWidth}x${n.innerHeight}`};a(`adding new event to queue ${JSON.stringify(t)}`),p.push(t)}function v(e){d&&(window.criteo_q=window.criteo_q||[],window.criteo_q.push(e))}function b(e){if(l)try{const i=[`pr_${l}_${e}`];i.push(`pr_${l}_lid_${function(){let e="__rtbhouse.lid",t=window.localStorage.getItem(e);if(!t){t="";var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(let e=0;e<20;e++)t+=i.charAt(Math.floor(Math.random()*i.length));window.localStorage.setItem(e,t)}return t}()}`);const n=document.createElement("iframe"),o=encodeURIComponent(document.referrer||""),r=encodeURIComponent(document.location.href||""),c=encodeURIComponent(""+Date.now());let t="https://creativecdn.com/tags?type=iframe";for(let e=0;e<i.length;e++)t+="&id="+encodeURIComponent(i[e]);t+=`&su=${r}&sr=${o}&ts=${c}`,n.setAttribute("src",t),n.setAttribute("width","1"),n.setAttribute("height","1"),n.setAttribute("scrolling","no"),n.setAttribute("frameBorder","0"),n.setAttribute("style","display:none"),n.setAttribute("referrerpolicy","no-referrer-when-downgrade"),document.body?document.body.appendChild(n):window.addEventListener("DOMContentLoaded",function(){document.body.appendChild(n)})}catch(e){a(e)}}const $={loadCriteo:function(){if(d){a("Loading criteo");let e=document.createElement("script");e.setAttribute("src",`//dynamic.criteo.com/js/ld/ld.js?a=${d}`),document.head.appendChild(e),v([{event:"setAccount",account:d},{event:"setEmail",email:h},{event:"setSiteType",type:"ontouchstart"in window||0<navigator.maxTouchPoints||0<navigator.msMaxTouchPoints?"m":"d"}])}a("criteo partner id not set")},criteoViewHome:function(){console.log("criteoViewHome"),v({event:"viewHome"})},criteoViewBasket:function(e){v({event:"viewBasket",item:e})},criteoViewItem:function(e){v({event:"viewItem",item:e.sku})},criteoViewList:function(e){v({event:"viewList",item:e.map(e=>e.sku)})},criteoFinishOrder:function(e,t){v({event:"trackTransaction",id:e,item:t})},criteoChangeEmail:function(e){v({event:"setEmail",email:e})}},_={rtbViewHome:function(){b("home")},rtbViewBasket:function(e){b(`basketstatus_${e.map(e=>e.sku).join(",")}`)},rtbViewItem:function(e){b(`offer_${e.sku}`)},rtbViewList:function(e){e=e.map(e=>e.sku);b(`listing_${e[0]},${e[1]},${e[2]},${e[3]},${e[4]}`)},rtbViewCategory:function(e){b(`category2_${e}`)},rtbStartOrder:function(){b("startorder")},rtbFinishOrder:function(e,t,i){b(`orderstatus2_${i}_${e}_${t.map(e=>e.sku).join(",")}`)}};function k(e){let t={};var i,n;return r(e,["id","sku"]),[i={},n]=[e,["quantity"]],n.forEach(e=>{i[e]&&Number.isNaN(Number(i[e]))&&o(`${e} is empty or contains invalid numeric value`)}),t.id=e.id,t.sku=e.sku,t.quantity&&(t.quantity=e.quantity),t}function I(e){let t={};var i,n;return r(e,["listName","merchantKey"]),[i={},n]=[e,["position"]],n.forEach(e=>{Number.isNaN(Number(i[e]))&&o(`${e} is empty or contains invalid numeric value`)}),t.listName=e.listName,t.position=e.position,t.merchantKey=e.merchantKey,t}var e={__system__:{land:function(){y("land",{originalQuery:n.location.search})}},viewHome:function(){console.log("viewHome"),$.criteoViewHome(),_.rtbViewHome()},viewBasket:function(e){$.criteoViewBasket(e),_.rtbViewBasket(e)},viewCategory(e){_.rtbViewCategory(e)},finishOrder:function(e,t,i){$.criteoFinishOrder(e,t),_.rtbFinishOrder(e,t,i)},changeUser:function(e,t=""){f=e,h=t,$.criteoChangeEmail(h)},agreeTracking:function(){w=!0},changeRoute:function(e={}){let t={};r(e,["path","title","location"]),g=e.title,t.path=e.path,t.title=e.title,t.location=e.location,y("changeRoute",t)},productClick:function(e={},t={}){y("productClick",{product:k(e),click:I(t)})},productsImpression:function(e=[],n={}){r(n,["merchantKey"]),y("productsImpression",e.map(function(e){var t=e.listName,i=n.merchantKey;return $.criteoViewList(e.products),_.rtbViewList(e.products),{name:t,merchantKey:i,products:e.products.map(k)}}))},productDetails:function(e={},t={}){r(t,["merchantKey"]),$.criteoViewItem(e),_.rtbViewItem(e),y("productDetails",{product:k(e),...t})},addLineItem:function(e={},t={}){r(t,["currencyCode","merchantKey"]),y("addLineItem",{product:k(e),...t})},removeLineItem:function(e={},t={}){r(t,["currencyCode","merchantKey"]),y("removeLineItem",{product:k(e),...t})},checkoutStep:function(e,t){1===t&&_.rtbStartOrder(e),c("orderId",e),y("checkoutStep",{orderId:e,stepNumber:t})},checkoutStepOption:function(e,t,i){c("orderId",e),y("checkoutStepOption",{orderId:e,stepNumber:t,optionName:i})}};$.loadCriteo(),e.__system__.land(),n.pixel=e,function t(){let i=n.setTimeout(async function(){if(a("loop"),m&&p.length){var e=p.shift();try{await async function(e){a(`sending.. payload=${JSON.stringify(e)}`);try{await fetch(`${s}/analytics/collect`,{method:"POST",mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}catch(e){console.error(`Failed to send event.. ${e.message}`)}}(e)}catch(e){a(`Failed to send event.. ${e.message}`)}}n.clearInterval(i),t()},500)}()}(window);';
7
7
  };
8
8
  exports.PixelScript = PixelScript;
@@ -26,6 +26,9 @@ var pixelChangeRoute = function() {
26
26
  }, 20);
27
27
  return;
28
28
  }
29
+ if (_router.default.router.asPath === '/') {
30
+ pixel === null || pixel === void 0 ? void 0 : pixel.viewHome();
31
+ }
29
32
  return pixel === null || pixel === void 0 ? void 0 : pixel.changeRoute({
30
33
  path: _router.default.router.asPath,
31
34
  title: title || 'Error',
@@ -0,0 +1,17 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.mapProducts = void 0;
5
+ var mapProducts = function(data) {
6
+ var mapped = data === null || data === void 0 ? void 0 : data.reduce(function(res, cur) {
7
+ var ref, ref1;
8
+ res.push({
9
+ id: cur.variant.sku,
10
+ price: (Number((ref = cur.totalPrice) === null || ref === void 0 ? void 0 : ref.centAmount) / Math.pow(10, Number((ref1 = cur.totalPrice) === null || ref1 === void 0 ? void 0 : ref1.fractionDigits))).toFixed(2),
11
+ quantity: cur.quantity + ''
12
+ });
13
+ return res;
14
+ }, []);
15
+ return mapped;
16
+ };
17
+ exports.mapProducts = mapProducts;
@@ -109,7 +109,6 @@ var useAccordion = function(param) {
109
109
  };
110
110
  }, [
111
111
  state.width,
112
- state.height,
113
112
  collapse,
114
113
  expand
115
114
  ]);
@@ -179,11 +179,11 @@ function processListingQuery(_) {
179
179
  }
180
180
  function _processListingQuery() {
181
181
  _processListingQuery = _asyncToGenerator(_regeneratorRuntime.default.mark(function _callee(param) {
182
- var predicate, router, limit, sort, postFilter, offset, config, slug, query, type, filter, _sort;
182
+ var predicate, router, limit, sort, postFilter, offset, config, slug, _includeVariants, includeVariants, query, type, filter, _sort;
183
183
  return _regeneratorRuntime.default.wrap(function _callee$(_ctx) {
184
184
  while(1)switch(_ctx.prev = _ctx.next){
185
185
  case 0:
186
- predicate = param.predicate, router = param.router, limit = param.limit, sort = param.sort, postFilter = param.postFilter, offset = param.offset, config = param.config, slug = param.slug;
186
+ predicate = param.predicate, router = param.router, limit = param.limit, sort = param.sort, postFilter = param.postFilter, offset = param.offset, config = param.config, slug = param.slug, _includeVariants = param.includeVariants, includeVariants = _includeVariants === void 0 ? false : _includeVariants;
187
187
  query = router.query;
188
188
  type = (0, _utils).getListingPageType(router, slug, config);
189
189
  filter = generateFilter(type, query, slug, predicate);
@@ -201,6 +201,8 @@ function _processListingQuery() {
201
201
  postFilter: postFilter
202
202
  }, (config === null || config === void 0 ? void 0 : config.collapseMode) && type !== _types.ListingTypesEnum.Collection && {
203
203
  collapseMode: config === null || config === void 0 ? void 0 : config.collapseMode
204
+ }, {
205
+ includeVariants: includeVariants
204
206
  })));
205
207
  case 6:
206
208
  case "end":
@@ -77,7 +77,8 @@ function _prefetchListing() {
77
77
  postFilter: postFilter,
78
78
  offset: offset,
79
79
  config: config,
80
- slug: aliasedSlug
80
+ slug: aliasedSlug,
81
+ includeVariants: Boolean(config.includeVariants)
81
82
  });
82
83
  case 12:
83
84
  data = _ctx.sent;
@@ -1,4 +1,7 @@
1
1
  export * from './usePixelProductDetails';
2
2
  export * from './usePixelProductsImpression';
3
3
  export * from './usePixelProductClick';
4
+ export * from './usePixelViewBasket';
5
+ export * from './usePixelViewCategory';
6
+ export * from './usePixelFinishOrder';
4
7
  export * from './useDistrictMeta';
@@ -0,0 +1,22 @@
1
+ import { mapProducts } from '../utils';
2
+ var _typeof = function(obj) {
3
+ "@swc/helpers - typeof";
4
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
5
+ };
6
+ export var usePixelFinishOrder = function() {
7
+ var sendFinishOrderEvent = function(order) {
8
+ var payload = {
9
+ orderId: order.orderRefNumber,
10
+ productsData: mapProducts(order.lineItems)
11
+ };
12
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
13
+ var pixel = window.pixel;
14
+ if (payload) {
15
+ pixel.finishOrder(payload);
16
+ }
17
+ }
18
+ };
19
+ return {
20
+ sendFinishOrderEvent: sendFinishOrderEvent
21
+ };
22
+ };
@@ -0,0 +1,19 @@
1
+ import { mapProducts } from '../utils';
2
+ var _typeof = function(obj) {
3
+ "@swc/helpers - typeof";
4
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
5
+ };
6
+ export var usePixelViewBasket = function() {
7
+ var sendViewBasketEvent = function(data) {
8
+ var payload = mapProducts(data);
9
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
10
+ var pixel = window.pixel;
11
+ if (payload) {
12
+ pixel.viewBasket(payload);
13
+ }
14
+ }
15
+ };
16
+ return {
17
+ sendViewBasketEvent: sendViewBasketEvent
18
+ };
19
+ };
@@ -0,0 +1,17 @@
1
+ var _typeof = function(obj) {
2
+ "@swc/helpers - typeof";
3
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
4
+ };
5
+ export var usePixelViewCategory = function() {
6
+ var sendViewCategoryEvent = function(categoryBreadcrumb) {
7
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
8
+ var pixel = window.pixel;
9
+ if (categoryBreadcrumb) {
10
+ pixel.viewCategory(categoryBreadcrumb);
11
+ }
12
+ }
13
+ };
14
+ return {
15
+ sendViewCategoryEvent: sendViewCategoryEvent
16
+ };
17
+ };
@@ -56,6 +56,8 @@ function _objectSpread(target) {
56
56
  }
57
57
  return target;
58
58
  }
59
+ // eslint-disable-next-line @typescript-eslint/no-extra-semi
60
+ ;
59
61
  (function(global) {
60
62
  var log = function log(message) {
61
63
  if (debug) {
@@ -83,16 +85,6 @@ function _objectSpread(target) {
83
85
  }
84
86
  });
85
87
  };
86
- var ensureStringValuesMayExist = function ensureStringValuesMayExist() {
87
- var params = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, keys = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
88
- keys.forEach(function(k) {
89
- if (params[k]) {
90
- if (typeof params[k] !== 'string') {
91
- err("".concat(k, " is empty or contains invalid string value"));
92
- }
93
- }
94
- });
95
- };
96
88
  var ensureStringValuesExist = function ensureStringValuesExist() {
97
89
  var params = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, keys = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
98
90
  keys.forEach(function(k) {
@@ -137,6 +129,54 @@ function _objectSpread(target) {
137
129
  log("adding new event to queue ".concat(JSON.stringify(enrichedPayload)));
138
130
  Q.push(enrichedPayload);
139
131
  };
132
+ var dispatchCriteoEvents = function dispatchCriteoEvents(events) {
133
+ if (criteoPartnerId) {
134
+ window.criteo_q = window.criteo_q || [];
135
+ window.criteo_q.push(events);
136
+ }
137
+ };
138
+ var sendRtbRequest = function sendRtbRequest(tag) {
139
+ if (rtbHouseHash) {
140
+ try {
141
+ var rtbTags = [
142
+ "pr_".concat(rtbHouseHash, "_").concat(tag)
143
+ ];
144
+ rtbTags.push("pr_".concat(rtbHouseHash, "_lid_").concat(getLid()));
145
+ var ifr = document.createElement('iframe'), sr = encodeURIComponent(document.referrer ? document.referrer : ''), su = encodeURIComponent(document.location.href ? document.location.href : ''), tmstmp = encodeURIComponent('' + Date.now());
146
+ var ifrSrc = 'https://creativecdn.com/tags?type=iframe';
147
+ for(var i = 0; i < rtbTags.length; i++){
148
+ ifrSrc += '&id=' + encodeURIComponent(rtbTags[i]);
149
+ }
150
+ ifrSrc += "&su=".concat(su, "&sr=").concat(sr, "&ts=").concat(tmstmp);
151
+ ifr.setAttribute('src', ifrSrc);
152
+ ifr.setAttribute('width', '1');
153
+ ifr.setAttribute('height', '1');
154
+ ifr.setAttribute('scrolling', 'no');
155
+ ifr.setAttribute('frameBorder', '0');
156
+ ifr.setAttribute('style', 'display:none');
157
+ ifr.setAttribute('referrerpolicy', 'no-referrer-when-downgrade');
158
+ if (document.body) {
159
+ document.body.appendChild(ifr);
160
+ } else {
161
+ window.addEventListener('DOMContentLoaded', function() {
162
+ document.body.appendChild(ifr);
163
+ });
164
+ }
165
+ } catch (e) {
166
+ log(e);
167
+ }
168
+ }
169
+ };
170
+ var getLid = function getLid() {
171
+ var key = '__rtbhouse.lid', lid = window.localStorage.getItem(key);
172
+ if (!lid) {
173
+ lid = '';
174
+ var pool = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
175
+ for(var i = 0; i < 20; i++)lid += pool.charAt(Math.floor(Math.random() * pool.length));
176
+ window.localStorage.setItem(key, lid);
177
+ }
178
+ return lid;
179
+ };
140
180
  var buildProductPayload = function buildProductPayload(productData) {
141
181
  var payload = {};
142
182
  ensureStringValuesExist(productData, [
@@ -167,21 +207,26 @@ function _objectSpread(target) {
167
207
  payload.merchantKey = clickData.merchantKey;
168
208
  return payload;
169
209
  };
210
+ var isTouchDevice = function isTouchDevice() {
211
+ return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
212
+ };
170
213
  //check the config
171
214
  if (typeof global.pixel_cfg !== 'object') {
172
215
  err('Pixel is missing config');
173
- } else if (!global.pixel_cfg.initialUserId || !global.pixel_cfg.appName) {
174
- err('Missing required pixel config fields. Please check if appName and initialUserId are present.');
216
+ } else if (!global.pixel_cfg.hubUrl || !global.pixel_cfg.initialUserId || !global.pixel_cfg.appName) {
217
+ err('Missing required pixel config fields. Please check if appName, hubUrl and initialUserId are present.');
175
218
  }
176
219
  /**
220
+ * hubUrl = the url of the integration hub
177
221
  * source = name of the client interface eg: app, website
178
222
  * debug = either or not to print logs
179
223
  * initialUserId = the initial id of the user/visitor
180
- */ var _pixel_cfg = global.pixel_cfg, appName = _pixel_cfg.appName, _source = _pixel_cfg.source, source = _source === void 0 ? 'web-client' : _source, _debug = _pixel_cfg.debug, debug = _debug === void 0 ? false : _debug, initialUserId = _pixel_cfg.initialUserId;
224
+ */ var _pixel_cfg = global.pixel_cfg, hubUrl = _pixel_cfg.hubUrl, appName = _pixel_cfg.appName, _source = _pixel_cfg.source, source = _source === void 0 ? 'web-client' : _source, _debug = _pixel_cfg.debug, debug = _debug === void 0 ? false : _debug, _criteoPartnerId = _pixel_cfg.criteoPartnerId, criteoPartnerId = _criteoPartnerId === void 0 ? false : _criteoPartnerId, _rtbHouseHash = _pixel_cfg.rtbHouseHash, rtbHouseHash = _rtbHouseHash === void 0 ? false : _rtbHouseHash, initialUserId = _pixel_cfg.initialUserId;
181
225
  var Q = [] //events queue
182
226
  ;
183
227
  var userId = initialUserId //is modified upon setUserId
184
228
  ;
229
+ var userEmail = '';
185
230
  var title = undefined;
186
231
  var allowTracking = false //should explicity state positive intention
187
232
  ;
@@ -196,8 +241,9 @@ function _objectSpread(target) {
196
241
  log("sending.. payload=".concat(JSON.stringify(payload)));
197
242
  _ctx.prev = 1;
198
243
  _ctx.next = 4;
199
- return fetch("/hub/analytics/collect", {
244
+ return fetch("".concat(hubUrl, "/analytics/collect"), {
200
245
  method: 'POST',
246
+ mode: 'cors',
201
247
  cache: 'no-cache',
202
248
  headers: {
203
249
  'Content-Type': 'application/json'
@@ -261,6 +307,113 @@ function _objectSpread(target) {
261
307
  ]);
262
308
  })), 500);
263
309
  }
310
+ var criteoAPI = {
311
+ loadCriteo: function loadCriteo() {
312
+ if (criteoPartnerId) {
313
+ log('Loading criteo');
314
+ var criteo = document.createElement('script');
315
+ criteo.setAttribute('src', "//dynamic.criteo.com/js/ld/ld.js?a=".concat(criteoPartnerId));
316
+ document.head.appendChild(criteo);
317
+ dispatchCriteoEvents([
318
+ {
319
+ event: 'setAccount',
320
+ account: criteoPartnerId
321
+ },
322
+ {
323
+ event: 'setEmail',
324
+ email: userEmail
325
+ },
326
+ {
327
+ event: 'setSiteType',
328
+ type: isTouchDevice() ? 'm' : 'd'
329
+ },
330
+ ]);
331
+ }
332
+ log('criteo partner id not set');
333
+ },
334
+ criteoViewHome: function criteoViewHome() {
335
+ console.log('criteoViewHome');
336
+ dispatchCriteoEvents({
337
+ event: 'viewHome'
338
+ });
339
+ },
340
+ //productData: [{ id: sku, price, quantity}]
341
+ criteoViewBasket: function criteoViewBasket(productsData) {
342
+ dispatchCriteoEvents({
343
+ event: 'viewBasket',
344
+ item: productsData
345
+ });
346
+ },
347
+ //productData: { sku }
348
+ criteoViewItem: function criteoViewItem(productData) {
349
+ dispatchCriteoEvents({
350
+ event: 'viewItem',
351
+ item: productData.sku
352
+ });
353
+ },
354
+ //products: [{ sku }]
355
+ criteoViewList: function criteoViewList(products) {
356
+ var items = products.map(function(product) {
357
+ return product.sku;
358
+ });
359
+ dispatchCriteoEvents({
360
+ event: 'viewList',
361
+ item: items
362
+ });
363
+ },
364
+ //orderId: Order ref number
365
+ //productData: [{ id: sku, price, quantity}]
366
+ criteoFinishOrder: function criteoFinishOrder(orderId, productsData) {
367
+ dispatchCriteoEvents({
368
+ event: 'trackTransaction',
369
+ id: orderId,
370
+ item: productsData
371
+ });
372
+ },
373
+ criteoChangeEmail: function criteoChangeEmail(email) {
374
+ dispatchCriteoEvents({
375
+ event: 'setEmail',
376
+ email: email
377
+ });
378
+ }
379
+ };
380
+ var rtbAPI = {
381
+ rtbViewHome: function rtbViewHome() {
382
+ sendRtbRequest("home");
383
+ },
384
+ //productData: [{ id: sku}]
385
+ rtbViewBasket: function rtbViewBasket(productsData) {
386
+ sendRtbRequest("basketstatus_".concat(productsData.map(function(product) {
387
+ return product.sku;
388
+ }).join(',')));
389
+ },
390
+ //productData: { sku }
391
+ rtbViewItem: function rtbViewItem(productData) {
392
+ sendRtbRequest("offer_".concat(productData.sku));
393
+ },
394
+ //products: [{ sku }]
395
+ rtbViewList: function rtbViewList(products) {
396
+ var items = products.map(function(product) {
397
+ return product.sku;
398
+ });
399
+ sendRtbRequest("listing_".concat(items[0], ",").concat(items[1], ",").concat(items[2], ",").concat(items[3], ",").concat(items[4]));
400
+ },
401
+ //categoryBreadcrumb: string
402
+ rtbViewCategory: function rtbViewCategory(categoryBreadcrumb) {
403
+ sendRtbRequest("category2_".concat(categoryBreadcrumb));
404
+ },
405
+ rtbStartOrder: function rtbStartOrder() {
406
+ sendRtbRequest("startorder");
407
+ },
408
+ //orderId: Order ref number
409
+ //productData: [{ id: sku, price, quantity}]
410
+ rtbFinishOrder: function rtbFinishOrder(orderId, productsData, orderPrice) {
411
+ var productIds = productsData.map(function(product) {
412
+ return product.sku;
413
+ }).join(',');
414
+ sendRtbRequest("orderstatus2_".concat(orderPrice, "_").concat(orderId, "_").concat(productIds));
415
+ }
416
+ };
264
417
  var API = {
265
418
  //internal only
266
419
  __system__: {
@@ -274,9 +427,33 @@ function _objectSpread(target) {
274
427
  addEventToQueue('land', eventPayload);
275
428
  }
276
429
  },
430
+ viewHome: function viewHome() {
431
+ console.log('viewHome');
432
+ criteoAPI.criteoViewHome();
433
+ rtbAPI.rtbViewHome();
434
+ },
435
+ //productsData: [{ id: sku, price, quantity}]
436
+ viewBasket: function viewBasket(productDetails) {
437
+ criteoAPI.criteoViewBasket(productDetails);
438
+ rtbAPI.rtbViewBasket(productDetails);
439
+ },
440
+ //categoryBreadcrumb
441
+ viewCategory: function viewCategory(categoryBreadcrumb) {
442
+ rtbAPI.rtbViewCategory(categoryBreadcrumb);
443
+ },
444
+ //orderId: Order ref number
445
+ //productsData: [{ id: sku, price, quantity}]
446
+ //orderPrice: total price of order
447
+ finishOrder: function finishOrder(orderId, productsData, orderPrice) {
448
+ criteoAPI.criteoFinishOrder(orderId, productsData);
449
+ rtbAPI.rtbFinishOrder(orderId, productsData, orderPrice);
450
+ },
277
451
  //used when user logs in or other occasion on which the id in cookie changes
278
452
  changeUser: function changeUser(newUserId) {
453
+ var newUserEmail = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '';
279
454
  userId = newUserId;
455
+ userEmail = newUserEmail;
456
+ criteoAPI.criteoChangeEmail(userEmail);
280
457
  },
281
458
  //Should be set on each app start/refresh. Marks if IP & other user data can be tracked
282
459
  agreeTracking: function agreeTracking() {
@@ -313,6 +490,8 @@ function _objectSpread(target) {
313
490
  var eventPayload = productLists.map(function(list) {
314
491
  var name = list.listName;
315
492
  var merchantKey = priceData.merchantKey;
493
+ criteoAPI.criteoViewList(list.products);
494
+ rtbAPI.rtbViewList(list.products);
316
495
  var products = list.products.map(function(product) {
317
496
  return buildProductPayload(product);
318
497
  });
@@ -329,6 +508,8 @@ function _objectSpread(target) {
329
508
  ensureStringValuesExist(priceData, [
330
509
  'merchantKey'
331
510
  ]);
511
+ criteoAPI.criteoViewItem(productData);
512
+ rtbAPI.rtbViewItem(productData);
332
513
  var product = buildProductPayload(productData);
333
514
  addEventToQueue('productDetails', _objectSpread({
334
515
  product: product
@@ -357,6 +538,9 @@ function _objectSpread(target) {
357
538
  }, priceData));
358
539
  },
359
540
  checkoutStep: function checkoutStep(orderId, stepNumber) {
541
+ if (stepNumber === 1) {
542
+ rtbAPI.rtbStartOrder(orderId);
543
+ }
360
544
  ensureIsStringValue('orderId', orderId);
361
545
  addEventToQueue('checkoutStep', {
362
546
  orderId: orderId,
@@ -372,6 +556,7 @@ function _objectSpread(target) {
372
556
  });
373
557
  }
374
558
  };
559
+ criteoAPI.loadCriteo();
375
560
  API.__system__.land();
376
561
  global.pixel = API;
377
562
  loop();
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable no-template-curly-in-string */ export var PixelScript = function() {
2
- return '!function(i){function o(e){t&&console.info(e)}function c(e){throw new Error(e)}function a(t={},e=[]){e.forEach(e=>{"string"!=typeof t[e]&&c(`${e} is empty or contains invalid string value`)})}function r(e="",t={}){"string"!=typeof t&&c(`${e} is empty or contains invalid string value`)}"object"!=typeof i.pixel_cfg?c("Pixel is missing config"):i.pixel_cfg.initialUserId&&i.pixel_cfg.appName||c("Missing required pixel config fields. Please check if appName and initialUserId are present.");const{appName:n,source:s="web-client",debug:t=!1,initialUserId:u}=i.pixel_cfg,l=[];let d=u,p=void 0,m=!1;function f(e,t={}){(t={name:e,data:t}).meta={userId:d,appName:n,allowTracking:m,source:s,userAgent:i.navigator.userAgent,location:i.location.href,language:i.navigator.language,charset:i.document.characterSet,title:p=p??i.document.title,referrer:i.document.referrer,screenResolution:`${i.screen.width}x${i.screen.height}`,viewportSize:`${i.innerWidth}x${i.innerHeight}`};o(`adding new event to queue ${JSON.stringify(t)}`),l.push(t)}function h(e){let t={};var n,i;return a(e,["id","sku"]),[n={},i]=[e,["quantity"]],i.forEach(e=>{n[e]&&Number.isNaN(Number(n[e]))&&c(`${e} is empty or contains invalid numeric value`)}),t.id=e.id,t.sku=e.sku,t.quantity&&(t.quantity=e.quantity),t}function g(e){let t={};var n,i;return a(e,["listName","merchantKey"]),[n={},i]=[e,["position"]],i.forEach(e=>{Number.isNaN(Number(n[e]))&&c(`${e} is empty or contains invalid numeric value`)}),t.listName=e.listName,t.position=e.position,t.merchantKey=e.merchantKey,t}var e={__system__:{land:function(){f("land",{originalQuery:i.location.search})}},changeUser:function(e){d=e},agreeTracking:function(){m=!0},changeRoute:function(e={}){let t={};a(e,["path","title","location"]),p=e.title,t.path=e.path,t.title=e.title,t.location=e.location,f("changeRoute",t)},productClick:function(e={},t={}){f("productClick",{product:h(e),click:g(t)})},productsImpression:function(e=[],t={}){a(t,["merchantKey"]),f("productsImpression",e.map(function(e){return{name:e.listName,merchantKey:t.merchantKey,products:e.products.map(h)}}))},productDetails:function(e={},t={}){a(t,["merchantKey"]),f("productDetails",{product:h(e),...t})},addLineItem:function(e={},t={}){a(t,["currencyCode","merchantKey"]),f("addLineItem",{product:h(e),...t})},removeLineItem:function(e={},t={}){a(t,["currencyCode","merchantKey"]),f("removeLineItem",{product:h(e),...t})},checkoutStep:function(e,t){r("orderId",e),f("checkoutStep",{orderId:e,stepNumber:t})},checkoutStepOption:function(e,t,n){r("orderId",e),f("checkoutStepOption",{orderId:e,stepNumber:t,optionName:n})}};e.__system__.land(),i.pixel=e,function t(){let n=i.setTimeout(async function(){if(o("loop"),u&&l.length){var e=l.shift();try{await async function(e){o(`sending.. payload=${JSON.stringify(e)}`);try{await fetch("/hub/analytics/collect",{method:"POST",cache:"no-cache",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}catch(e){console.error(`Failed to send event.. ${e.message}`)}}(e)}catch(e){o(`Failed to send event.. ${e.message}`)}}i.clearInterval(n),t()},500)}()}(window);';
2
+ return '!function(n){function a(e){t&&console.info(e)}function o(e){throw new Error(e)}function r(t={},e=[]){e.forEach(e=>{"string"!=typeof t[e]&&o(`${e} is empty or contains invalid string value`)})}function c(e="",t={}){"string"!=typeof t&&o(`${e} is empty or contains invalid string value`)}"object"!=typeof n.pixel_cfg?o("Pixel is missing config"):n.pixel_cfg.hubUrl&&n.pixel_cfg.initialUserId&&n.pixel_cfg.appName||o("Missing required pixel config fields. Please check if appName, hubUrl and initialUserId are present.");const{hubUrl:s,appName:i,source:u="web-client",debug:t=!1,criteoPartnerId:d=!1,rtbHouseHash:l=!1,initialUserId:m}=n.pixel_cfg,p=[];let f=m,h="",g=void 0,w=!1;function y(e,t={}){(t={name:e,data:t}).meta={userId:f,appName:i,allowTracking:w,source:u,userAgent:n.navigator.userAgent,location:n.location.href,language:n.navigator.language,charset:n.document.characterSet,title:g=g??n.document.title,referrer:n.document.referrer,screenResolution:`${n.screen.width}x${n.screen.height}`,viewportSize:`${n.innerWidth}x${n.innerHeight}`};a(`adding new event to queue ${JSON.stringify(t)}`),p.push(t)}function v(e){d&&(window.criteo_q=window.criteo_q||[],window.criteo_q.push(e))}function b(e){if(l)try{const i=[`pr_${l}_${e}`];i.push(`pr_${l}_lid_${function(){let e="__rtbhouse.lid",t=window.localStorage.getItem(e);if(!t){t="";var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";for(let e=0;e<20;e++)t+=i.charAt(Math.floor(Math.random()*i.length));window.localStorage.setItem(e,t)}return t}()}`);const n=document.createElement("iframe"),o=encodeURIComponent(document.referrer||""),r=encodeURIComponent(document.location.href||""),c=encodeURIComponent(""+Date.now());let t="https://creativecdn.com/tags?type=iframe";for(let e=0;e<i.length;e++)t+="&id="+encodeURIComponent(i[e]);t+=`&su=${r}&sr=${o}&ts=${c}`,n.setAttribute("src",t),n.setAttribute("width","1"),n.setAttribute("height","1"),n.setAttribute("scrolling","no"),n.setAttribute("frameBorder","0"),n.setAttribute("style","display:none"),n.setAttribute("referrerpolicy","no-referrer-when-downgrade"),document.body?document.body.appendChild(n):window.addEventListener("DOMContentLoaded",function(){document.body.appendChild(n)})}catch(e){a(e)}}const $={loadCriteo:function(){if(d){a("Loading criteo");let e=document.createElement("script");e.setAttribute("src",`//dynamic.criteo.com/js/ld/ld.js?a=${d}`),document.head.appendChild(e),v([{event:"setAccount",account:d},{event:"setEmail",email:h},{event:"setSiteType",type:"ontouchstart"in window||0<navigator.maxTouchPoints||0<navigator.msMaxTouchPoints?"m":"d"}])}a("criteo partner id not set")},criteoViewHome:function(){console.log("criteoViewHome"),v({event:"viewHome"})},criteoViewBasket:function(e){v({event:"viewBasket",item:e})},criteoViewItem:function(e){v({event:"viewItem",item:e.sku})},criteoViewList:function(e){v({event:"viewList",item:e.map(e=>e.sku)})},criteoFinishOrder:function(e,t){v({event:"trackTransaction",id:e,item:t})},criteoChangeEmail:function(e){v({event:"setEmail",email:e})}},_={rtbViewHome:function(){b("home")},rtbViewBasket:function(e){b(`basketstatus_${e.map(e=>e.sku).join(",")}`)},rtbViewItem:function(e){b(`offer_${e.sku}`)},rtbViewList:function(e){e=e.map(e=>e.sku);b(`listing_${e[0]},${e[1]},${e[2]},${e[3]},${e[4]}`)},rtbViewCategory:function(e){b(`category2_${e}`)},rtbStartOrder:function(){b("startorder")},rtbFinishOrder:function(e,t,i){b(`orderstatus2_${i}_${e}_${t.map(e=>e.sku).join(",")}`)}};function k(e){let t={};var i,n;return r(e,["id","sku"]),[i={},n]=[e,["quantity"]],n.forEach(e=>{i[e]&&Number.isNaN(Number(i[e]))&&o(`${e} is empty or contains invalid numeric value`)}),t.id=e.id,t.sku=e.sku,t.quantity&&(t.quantity=e.quantity),t}function I(e){let t={};var i,n;return r(e,["listName","merchantKey"]),[i={},n]=[e,["position"]],n.forEach(e=>{Number.isNaN(Number(i[e]))&&o(`${e} is empty or contains invalid numeric value`)}),t.listName=e.listName,t.position=e.position,t.merchantKey=e.merchantKey,t}var e={__system__:{land:function(){y("land",{originalQuery:n.location.search})}},viewHome:function(){console.log("viewHome"),$.criteoViewHome(),_.rtbViewHome()},viewBasket:function(e){$.criteoViewBasket(e),_.rtbViewBasket(e)},viewCategory(e){_.rtbViewCategory(e)},finishOrder:function(e,t,i){$.criteoFinishOrder(e,t),_.rtbFinishOrder(e,t,i)},changeUser:function(e,t=""){f=e,h=t,$.criteoChangeEmail(h)},agreeTracking:function(){w=!0},changeRoute:function(e={}){let t={};r(e,["path","title","location"]),g=e.title,t.path=e.path,t.title=e.title,t.location=e.location,y("changeRoute",t)},productClick:function(e={},t={}){y("productClick",{product:k(e),click:I(t)})},productsImpression:function(e=[],n={}){r(n,["merchantKey"]),y("productsImpression",e.map(function(e){var t=e.listName,i=n.merchantKey;return $.criteoViewList(e.products),_.rtbViewList(e.products),{name:t,merchantKey:i,products:e.products.map(k)}}))},productDetails:function(e={},t={}){r(t,["merchantKey"]),$.criteoViewItem(e),_.rtbViewItem(e),y("productDetails",{product:k(e),...t})},addLineItem:function(e={},t={}){r(t,["currencyCode","merchantKey"]),y("addLineItem",{product:k(e),...t})},removeLineItem:function(e={},t={}){r(t,["currencyCode","merchantKey"]),y("removeLineItem",{product:k(e),...t})},checkoutStep:function(e,t){1===t&&_.rtbStartOrder(e),c("orderId",e),y("checkoutStep",{orderId:e,stepNumber:t})},checkoutStepOption:function(e,t,i){c("orderId",e),y("checkoutStepOption",{orderId:e,stepNumber:t,optionName:i})}};$.loadCriteo(),e.__system__.land(),n.pixel=e,function t(){let i=n.setTimeout(async function(){if(a("loop"),m&&p.length){var e=p.shift();try{await async function(e){a(`sending.. payload=${JSON.stringify(e)}`);try{await fetch(`${s}/analytics/collect`,{method:"POST",mode:"cors",cache:"no-cache",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}catch(e){console.error(`Failed to send event.. ${e.message}`)}}(e)}catch(e){a(`Failed to send event.. ${e.message}`)}}n.clearInterval(i),t()},500)}()}(window);';
3
3
  };
@@ -17,6 +17,9 @@ export var pixelChangeRoute = function() {
17
17
  }, 20);
18
18
  return;
19
19
  }
20
+ if (Router.router.asPath === '/') {
21
+ pixel === null || pixel === void 0 ? void 0 : pixel.viewHome();
22
+ }
20
23
  return pixel === null || pixel === void 0 ? void 0 : pixel.changeRoute({
21
24
  path: Router.router.asPath,
22
25
  title: title || 'Error',
@@ -0,0 +1,12 @@
1
+ export var mapProducts = function(data) {
2
+ var mapped = data === null || data === void 0 ? void 0 : data.reduce(function(res, cur) {
3
+ var ref, ref1;
4
+ res.push({
5
+ id: cur.variant.sku,
6
+ price: (Number((ref = cur.totalPrice) === null || ref === void 0 ? void 0 : ref.centAmount) / Math.pow(10, Number((ref1 = cur.totalPrice) === null || ref1 === void 0 ? void 0 : ref1.fractionDigits))).toFixed(2),
7
+ quantity: cur.quantity + ''
8
+ });
9
+ return res;
10
+ }, []);
11
+ return mapped;
12
+ };
@@ -105,7 +105,6 @@ export var useAccordion = function(param) {
105
105
  };
106
106
  }, [
107
107
  state.width,
108
- state.height,
109
108
  collapse,
110
109
  expand
111
110
  ]);
@@ -167,11 +167,11 @@ export function processListingQuery(_) {
167
167
  }
168
168
  function _processListingQuery() {
169
169
  _processListingQuery = _asyncToGenerator(regeneratorRuntime.mark(function _callee(param) {
170
- var predicate, router, limit, sort, postFilter, offset, config, slug, query, type, filter, _sort;
170
+ var predicate, router, limit, sort, postFilter, offset, config, slug, _includeVariants, includeVariants, query, type, filter, _sort;
171
171
  return regeneratorRuntime.wrap(function _callee$(_ctx) {
172
172
  while(1)switch(_ctx.prev = _ctx.next){
173
173
  case 0:
174
- predicate = param.predicate, router = param.router, limit = param.limit, sort = param.sort, postFilter = param.postFilter, offset = param.offset, config = param.config, slug = param.slug;
174
+ predicate = param.predicate, router = param.router, limit = param.limit, sort = param.sort, postFilter = param.postFilter, offset = param.offset, config = param.config, slug = param.slug, _includeVariants = param.includeVariants, includeVariants = _includeVariants === void 0 ? false : _includeVariants;
175
175
  query = router.query;
176
176
  type = getListingPageType(router, slug, config);
177
177
  filter = generateFilter(type, query, slug, predicate);
@@ -189,6 +189,8 @@ function _processListingQuery() {
189
189
  postFilter: postFilter
190
190
  }, (config === null || config === void 0 ? void 0 : config.collapseMode) && type !== ListingTypesEnum.Collection && {
191
191
  collapseMode: config === null || config === void 0 ? void 0 : config.collapseMode
192
+ }, {
193
+ includeVariants: includeVariants
192
194
  })));
193
195
  case 6:
194
196
  case "end":
@@ -69,7 +69,8 @@ function _prefetchListing() {
69
69
  postFilter: postFilter,
70
70
  offset: offset,
71
71
  config: config,
72
- slug: aliasedSlug
72
+ slug: aliasedSlug,
73
+ includeVariants: Boolean(config.includeVariants)
73
74
  });
74
75
  case 12:
75
76
  data = _ctx.sent;
@@ -1,4 +1,7 @@
1
1
  export * from './usePixelProductDetails';
2
2
  export * from './usePixelProductsImpression';
3
3
  export * from './usePixelProductClick';
4
+ export * from './usePixelViewBasket';
5
+ export * from './usePixelViewCategory';
6
+ export * from './usePixelFinishOrder';
4
7
  export * from './useDistrictMeta';
@@ -0,0 +1,4 @@
1
+ import type { OrderDTO } from '@sentecacommerce/sdk';
2
+ export declare const usePixelFinishOrder: () => {
3
+ sendFinishOrderEvent: (order: OrderDTO) => void;
4
+ };
@@ -0,0 +1,4 @@
1
+ import { LineItemDTO } from '@sentecacommerce/sdk';
2
+ export declare const usePixelViewBasket: () => {
3
+ sendViewBasketEvent: (data: LineItemDTO[]) => void;
4
+ };
@@ -0,0 +1,3 @@
1
+ export declare const usePixelViewCategory: () => {
2
+ sendViewCategoryEvent: (categoryBreadcrumb: string) => void;
3
+ };
@@ -7,3 +7,12 @@ export interface ProductsImpressionType {
7
7
  name: string;
8
8
  products?: ProductType[] | SearchResultDTO[];
9
9
  }
10
+ export interface Products {
11
+ id: string;
12
+ price: string;
13
+ quantity: string;
14
+ }
15
+ export interface OrderType {
16
+ orderId: string;
17
+ productsData: Products[];
18
+ }
@@ -0,0 +1,3 @@
1
+ import type { LineItemDTO } from '@sentecacommerce/sdk';
2
+ import type { Products } from './types';
3
+ export declare const mapProducts: (data: LineItemDTO[]) => Products[];
@@ -5,7 +5,7 @@ import { PredicateType } from '..';
5
5
  import { ListingPageMeta } from '../..';
6
6
  import { StringField } from '@sentecacommerce-theme/cms';
7
7
  export declare const useListingQuery: () => QueryResult<CatalogFilterResultDTO, unknown>;
8
- export declare function processListingQuery({ predicate, router, limit, sort, postFilter, offset, config, slug, }: {
8
+ export declare function processListingQuery({ predicate, router, limit, sort, postFilter, offset, config, slug, includeVariants, }: {
9
9
  predicate?: PredicateType;
10
10
  router: NextRouter;
11
11
  limit: number;
@@ -14,5 +14,6 @@ export declare function processListingQuery({ predicate, router, limit, sort, po
14
14
  postFilter?: string;
15
15
  config?: ListingPageMeta;
16
16
  slug?: string;
17
+ includeVariants?: boolean;
17
18
  }): Promise<CatalogFilterResultDTO>;
18
19
  export declare function isListingQueryEnabled(type: StringField, predicate?: PredicateType): boolean;
@@ -80,7 +80,8 @@ export interface ListingPageMeta {
80
80
  titleAliases: {
81
81
  [key: string]: string;
82
82
  };
83
- filterExtension: StringField;
84
- collapseMode: StringField;
83
+ filterExtension?: StringField;
84
+ collapseMode?: StringField;
85
85
  limit: NumberField;
86
+ includeVariants?: BooleanField;
86
87
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentecacommerce-theme/lib",
3
3
  "sideEffects": false,
4
- "version": "0.12.89",
4
+ "version": "0.12.90",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -31,13 +31,13 @@
31
31
  "watch:cjs": "swc src --out-dir dist/cjs -w",
32
32
  "watch:esm": "swc src --out-dir dist/esm --no-swcrc -w"
33
33
  },
34
- "gitHead": "c33bd6a03d6f288f79cde744a489527bc0d48040",
34
+ "gitHead": "d28453063c2d598346b5663c6fa3530c2ce8bd62",
35
35
  "peerDependencies": {
36
36
  "react-query": "^2.26.2"
37
37
  },
38
38
  "dependencies": {
39
- "@sentecacommerce-theme/base": "^0.12.89",
40
- "@sentecacommerce-theme/cms": "^0.12.89",
39
+ "@sentecacommerce-theme/base": "^0.12.90",
40
+ "@sentecacommerce-theme/cms": "^0.12.90",
41
41
  "@sentecacommerce/sdk": "2.0.161",
42
42
  "body-scroll-lock": "^3.1.5",
43
43
  "copy-to-clipboard": "^3.3.1",