@sentecacommerce-theme/lib 0.12.89 → 0.12.93

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 (41) 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/usePixelProductClick.js +3 -7
  4. package/dist/cjs/analytics/Pixel/hooks/usePixelProductsImpression.js +42 -32
  5. package/dist/cjs/analytics/Pixel/hooks/usePixelViewBasket.js +24 -0
  6. package/dist/cjs/analytics/Pixel/hooks/usePixelViewCategory.js +29 -0
  7. package/dist/cjs/analytics/Pixel/mainScript.js +197 -14
  8. package/dist/cjs/analytics/Pixel/minifiedPixel.js +1 -1
  9. package/dist/cjs/analytics/Pixel/usePixel.js +3 -0
  10. package/dist/cjs/analytics/Pixel/utils.js +17 -0
  11. package/dist/cjs/hooks/ui-hooks/useAccordion/index.js +0 -1
  12. package/dist/cjs/listing/api/queries/useListingQuery.js +4 -2
  13. package/dist/cjs/listing/ssr/prefetchListing.js +2 -1
  14. package/dist/cjs/ui/components/GridStyles.js +36 -0
  15. package/dist/cjs/ui/components/index.js +12 -0
  16. package/dist/esm/analytics/Pixel/hooks/index.js +3 -0
  17. package/dist/esm/analytics/Pixel/hooks/usePixelFinishOrder.js +22 -0
  18. package/dist/esm/analytics/Pixel/hooks/usePixelProductClick.js +4 -8
  19. package/dist/esm/analytics/Pixel/hooks/usePixelProductsImpression.js +42 -32
  20. package/dist/esm/analytics/Pixel/hooks/usePixelViewBasket.js +19 -0
  21. package/dist/esm/analytics/Pixel/hooks/usePixelViewCategory.js +24 -0
  22. package/dist/esm/analytics/Pixel/mainScript.js +199 -14
  23. package/dist/esm/analytics/Pixel/minifiedPixel.js +1 -1
  24. package/dist/esm/analytics/Pixel/usePixel.js +3 -0
  25. package/dist/esm/analytics/Pixel/utils.js +12 -0
  26. package/dist/esm/hooks/ui-hooks/useAccordion/index.js +0 -1
  27. package/dist/esm/listing/api/queries/useListingQuery.js +4 -2
  28. package/dist/esm/listing/ssr/prefetchListing.js +2 -1
  29. package/dist/esm/ui/components/GridStyles.js +26 -0
  30. package/dist/esm/ui/components/index.js +1 -0
  31. package/dist/types/analytics/Pixel/hooks/index.d.ts +3 -0
  32. package/dist/types/analytics/Pixel/hooks/usePixelFinishOrder.d.ts +4 -0
  33. package/dist/types/analytics/Pixel/hooks/usePixelViewBasket.d.ts +4 -0
  34. package/dist/types/analytics/Pixel/hooks/usePixelViewCategory.d.ts +7 -0
  35. package/dist/types/analytics/Pixel/types.d.ts +9 -0
  36. package/dist/types/analytics/Pixel/utils.d.ts +3 -0
  37. package/dist/types/listing/api/queries/useListingQuery.d.ts +2 -1
  38. package/dist/types/listing/types.d.ts +3 -2
  39. package/dist/types/ui/components/GridStyles.d.ts +10 -0
  40. package/dist/types/ui/components/index.d.ts +1 -0
  41. package/package.json +4 -4
@@ -0,0 +1,36 @@
1
+ Object.defineProperty(exports, "__esModule", {
2
+ value: true
3
+ });
4
+ exports.GridStyles = void 0;
5
+ var _react = _interopRequireDefault(require("react"));
6
+ function _interopRequireDefault(obj) {
7
+ return obj && obj.__esModule ? obj : {
8
+ default: obj
9
+ };
10
+ }
11
+ var GridStyles = function(param) {
12
+ var spaceX = param.spaceX, breakpoints = param.breakpoints, _remSize = param.remSize, remSize = _remSize === void 0 ? 10 : _remSize;
13
+ function getSize(width) {
14
+ return "min-width: calc(".concat(width, "% - ").concat(spaceX / remSize, "rem);") + "max-width: calc(".concat(width, "% - ").concat(spaceX / remSize, "rem);") + "margin: 0 ".concat(spaceX / 2 / remSize, "rem;");
15
+ }
16
+ var keys = Object.keys(breakpoints || {
17
+ xs: {
18
+ min: null
19
+ }
20
+ });
21
+ var transforms = {
22
+ xs: 'default'
23
+ };
24
+ var queries = keys.reduce(function(str, key, index) {
25
+ var min = ((breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints[key]) || {}).min;
26
+ var k = transforms[key] || key;
27
+ if (index && !min) return str;
28
+ return str += "\n @media(min-width: ".concat(min || '1px', ") {\n .size-").concat(k, "-full-bleed {\n width: 100%;\n }\n\n .size-").concat(k, "-full-bleed .Section--inner {\n width: 100vw;\n position: relative;\n left: 50%;\n right: 50%;\n margin-left: -50vw;\n margin-right: -50vw;\n }\n\n .size-").concat(k, "-100 {\n ").concat(getSize(100), "\n }\n\n .size-").concat(k, "-90 {\n ").concat(getSize(90), "\n }\n\n .size-").concat(k, "-80 {\n ").concat(getSize(80), "\n }\n\n .size-").concat(k, "-75 {\n ").concat(getSize(75), "\n }\n\n .size-").concat(k, "-70 {\n ").concat(getSize(70), "\n }\n \n .size-").concat(k, "-66 {\n ").concat(getSize(66.666666), "\n }\n\n .size-").concat(k, "-60 {\n ").concat(getSize(60), "\n }\n\n .size-").concat(k, "-50 {\n ").concat(getSize(50), "\n }\n\n .size-").concat(k, "-40 {\n ").concat(getSize(40), "\n }\n\n .size-").concat(k, "-33 {\n ").concat(getSize(33.333333), "\n }\n\n .size-").concat(k, "-30 {\n ").concat(getSize(30), "\n }\n\n .size-").concat(k, "-25 {\n ").concat(getSize(25), "\n }\n\n .size-").concat(k, "-20 {\n ").concat(getSize(20), "\n }\n\n .size-").concat(k, "-10 {\n ").concat(getSize(10), "\n }\n }\n");
29
+ }, '');
30
+ return(/*#__PURE__*/ _react.default.createElement("style", {
31
+ dangerouslySetInnerHTML: {
32
+ __html: "\n .Page--row {\n display: flex;\n display: -webkit-flex;\n flex-wrap: wrap;\n -webkit-flex-wrap: wrap;\n margin: 0 -".concat(spaceX / remSize / 2, "rem;\n }\n\n .Page__section {\n padding-bottom: 8rem;\n }\n\n .Page--col {\n display: block;\n width: 100%;\n }\n \n .size-default-inherit {\n width: 100%;\n }\n ").concat(queries, "\n ")
33
+ }
34
+ }));
35
+ };
36
+ exports.GridStyles = GridStyles;
@@ -26,6 +26,18 @@ Object.keys(_lazyImage).forEach(function(key) {
26
26
  }
27
27
  });
28
28
  });
29
+ var _gridStyles = _interopRequireWildcard(require("./GridStyles"));
30
+ Object.keys(_gridStyles).forEach(function(key) {
31
+ if (key === "default" || key === "__esModule") return;
32
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
33
+ if (key in exports && exports[key] === _gridStyles[key]) return;
34
+ Object.defineProperty(exports, key, {
35
+ enumerable: true,
36
+ get: function() {
37
+ return _gridStyles[key];
38
+ }
39
+ });
40
+ });
29
41
  function _interopRequireWildcard(obj) {
30
42
  if (obj && obj.__esModule) {
31
43
  return obj;
@@ -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 === null || pixel === void 0 ? void 0 : pixel.finishOrder(payload);
16
+ }
17
+ }
18
+ };
19
+ return {
20
+ sendFinishOrderEvent: sendFinishOrderEvent
21
+ };
22
+ };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { useConfigState } from '../../../index';
2
+ import { useConfigState, canUseDOM } from '../../../index';
3
3
  function _defineProperty(obj, key, value) {
4
4
  if (key in obj) {
5
5
  Object.defineProperty(obj, key, {
@@ -28,18 +28,14 @@ function _objectSpread(target) {
28
28
  }
29
29
  return target;
30
30
  }
31
- var _typeof = function(obj) {
32
- "@swc/helpers - typeof";
33
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
34
- };
35
31
  export var usePixelProductClick = function() {
36
32
  var defaultMerchant = useConfigState().defaultMerchant;
37
33
  var sendClickEvent = function(param) {
38
34
  var product = param.product, info = param.info;
39
- if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
35
+ if (canUseDOM() && defaultMerchant) {
40
36
  var pixel = window.pixel;
41
- pixel.productClick(product, _objectSpread({}, info, {
42
- merchantKey: defaultMerchant || ''
37
+ pixel === null || pixel === void 0 ? void 0 : pixel.productClick(product, _objectSpread({}, info, {
38
+ merchantKey: defaultMerchant
43
39
  }));
44
40
  }
45
41
  };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { useRouter } from 'next/router';
3
3
  import { useConfigState, useBoolean } from '../../../index';
4
4
  import { createMappedProducts } from '../../Releva';
5
+ import { canUseDOM } from '../../../utils';
5
6
  function _arrayLikeToArray(arr, len) {
6
7
  if (len == null || len > arr.length) len = arr.length;
7
8
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -40,10 +41,6 @@ function _nonIterableRest() {
40
41
  function _slicedToArray(arr, i) {
41
42
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
42
43
  }
43
- var _typeof = function(obj) {
44
- "@swc/helpers - typeof";
45
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
46
- };
47
44
  function _unsupportedIterableToArray(o, minLen) {
48
45
  if (!o) return;
49
46
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -54,42 +51,55 @@ function _unsupportedIterableToArray(o, minLen) {
54
51
  }
55
52
  export var usePixelProductsImpression = function(param) {
56
53
  var productsData = param.productsData, isCarousel = param.isCarousel;
57
- var ref3 = _slicedToArray(useBoolean(false), 2), sentAlready = ref3[0], setSentAlready = ref3[1];
54
+ var ref5;
55
+ var ref1 = _slicedToArray(useBoolean(false), 2), sentAlready = ref1[0], setSentAlready = ref1[1];
58
56
  var defaultMerchant = useConfigState().defaultMerchant;
59
57
  var router = useRouter();
60
58
  var products = [];
61
59
  if (!isCarousel) {
62
- products = createMappedProducts(productsData.products);
60
+ products = createMappedProducts(productsData === null || productsData === void 0 ? void 0 : productsData.products);
63
61
  }
64
62
  React.useEffect(function() {
65
- if (sentAlready || !products.length) return;
66
- router.events.on('routeChangeComplete', function() {
67
- var ref, ref1;
68
- if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined && !((ref = productsData.products) === null || ref === void 0 ? void 0 : (ref1 = ref[0]) === null || ref1 === void 0 ? void 0 : ref1.isPlaceholder) && (productsData === null || productsData === void 0 ? void 0 : productsData.length) > 0) {
69
- var ref2;
70
- var pixel = window.pixel;
71
- var title = window === null || window === void 0 ? void 0 : (ref2 = window.document) === null || ref2 === void 0 ? void 0 : ref2.title;
72
- var sendImpressions = function() {
73
- if (!title || title === 'за') {
74
- setTimeout(function() {
75
- return sendImpressions();
76
- }, 20);
77
- return;
63
+ setSentAlready.off();
64
+ }, [
65
+ router.asPath,
66
+ productsData === null || productsData === void 0 ? void 0 : (ref5 = productsData.products) === null || ref5 === void 0 ? void 0 : ref5.length,
67
+ setSentAlready
68
+ ]);
69
+ React.useEffect(function() {
70
+ var ref, ref2, ref3;
71
+ if (sentAlready || !(products === null || products === void 0 ? void 0 : products.length)) return;
72
+ if (canUseDOM() && !((ref = productsData.products) === null || ref === void 0 ? void 0 : (ref2 = ref[0]) === null || ref2 === void 0 ? void 0 : ref2.isPlaceholder) && (productsData === null || productsData === void 0 ? void 0 : (ref3 = productsData.products) === null || ref3 === void 0 ? void 0 : ref3.length) > 0) {
73
+ var ref4;
74
+ var pixel = window.pixel;
75
+ var title = window === null || window === void 0 ? void 0 : (ref4 = window.document) === null || ref4 === void 0 ? void 0 : ref4.title;
76
+ var sendImpressions = function() {
77
+ if (!title || title === 'за') {
78
+ setTimeout(function() {
79
+ return sendImpressions();
80
+ }, 20);
81
+ return;
82
+ }
83
+ pixel === null || pixel === void 0 ? void 0 : pixel.productsImpression(!isCarousel ? [
84
+ {
85
+ listName: title,
86
+ products: products
78
87
  }
79
- pixel === null || pixel === void 0 ? void 0 : pixel.productsImpression(!isCarousel ? [
80
- {
81
- listName: title,
82
- products: products
83
- }
84
- ] : productsData, {
85
- merchantKey: defaultMerchant || ''
86
- });
87
- };
88
- sendImpressions();
88
+ ] : productsData, {
89
+ merchantKey: defaultMerchant || ''
90
+ });
89
91
  setSentAlready.on();
90
- }
91
- });
92
+ };
93
+ sendImpressions();
94
+ }
92
95
  }, [
93
- router.route
96
+ router.route,
97
+ defaultMerchant,
98
+ sentAlready,
99
+ products,
100
+ router.events,
101
+ productsData,
102
+ setSentAlready,
103
+ isCarousel,
94
104
  ]);
95
105
  };
@@ -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 === null || pixel === void 0 ? void 0 : pixel.viewBasket(payload);
13
+ }
14
+ }
15
+ };
16
+ return {
17
+ sendViewBasketEvent: sendViewBasketEvent
18
+ };
19
+ };
@@ -0,0 +1,24 @@
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(breadcrumbData) {
7
+ var breadcrumbString = breadcrumbData.reduce(function(res, curr, index) {
8
+ res += curr.name;
9
+ if (index !== breadcrumbData.length - 1) {
10
+ res += '/';
11
+ }
12
+ return res;
13
+ }, '');
14
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) !== undefined) {
15
+ var pixel = window.pixel;
16
+ if (breadcrumbString) {
17
+ pixel === null || pixel === void 0 ? void 0 : pixel.viewCategory(breadcrumbString);
18
+ }
19
+ }
20
+ };
21
+ return {
22
+ sendViewCategoryEvent: sendViewCategoryEvent
23
+ };
24
+ };
@@ -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
  ]);