@searchspring/snap-tracker 0.65.2 → 0.66.0

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.
@@ -3,8 +3,6 @@ import { StorageStore } from '@searchspring/snap-store-mobx';
3
3
  import { version, DomTargeter, getContext } from '@searchspring/snap-toolbox';
4
4
  import { AppMode } from '@searchspring/snap-toolbox';
5
5
  import { Beacon } from '@searchspring/beacon';
6
- import { BeaconEvent } from './BeaconEvent';
7
- import { BeaconType, BeaconCategory, } from './types';
8
6
  const MAX_PARENT_LEVELS = 3;
9
7
  const defaultConfig = {
10
8
  id: 'track',
@@ -18,7 +16,6 @@ export class Tracker extends Beacon {
18
16
  super(globals, config);
19
17
  this.targeters = [];
20
18
  this.track = {
21
- // TODO: search where this is used and remove unwanted fields from type
22
19
  error: (data, siteId) => {
23
20
  if (this.doNotTrack?.includes('error') || this.mode === AppMode.development) {
24
21
  return;
@@ -27,7 +24,7 @@ export class Tracker extends Beacon {
27
24
  // no console log
28
25
  return;
29
26
  }
30
- const { stack, message, details } = data;
27
+ const { stack, message, ...details } = data;
31
28
  const { pageUrl } = this.getContext();
32
29
  // prevent sending of errors when on localhost or CDN
33
30
  if (message?.includes('Profile is currently paused') || pageUrl.includes('//localhost') || pageUrl.includes('//snapui.searchspring.io/')) {
@@ -67,61 +64,15 @@ export class Tracker extends Beacon {
67
64
  /**
68
65
  * @deprecated tracker.track.product.click() is deprecated and will be removed. Use tracker.events['search' | 'category'].clickThrough() instead
69
66
  */
70
- click: (data, siteId) => {
71
- // Controllers will send product click events through tracker.beacon
72
- // For legacy support if someone calls this, continute to 1.0 beacon just like is.js
73
- // TODO: remove after 1.0 deprecation period
74
- if (this.doNotTrack?.includes('product.click')) {
75
- return;
76
- }
77
- if (!data?.intellisuggestData || !data?.intellisuggestSignature) {
78
- console.error(`track.product.click event: object parameter requires a valid intellisuggestData and intellisuggestSignature. \nExample: track.click.product({ intellisuggestData: "eJwrTs4tNM9jYCjKTM8oYXDWdQ3TDTfUDbIwMDVjMARCYwMQSi_KTAEA9IQKWA", intellisuggestSignature: "9e46f9fd3253c267fefc298704e39084a6f8b8e47abefdee57277996b77d8e70" })`);
79
- return;
80
- }
81
- const beaconContext = this.getContext();
82
- const context = transformToLegacyContext(beaconContext, siteId || this.globals.siteId);
83
- const event = {
84
- type: BeaconType.CLICK,
85
- category: BeaconCategory.INTERACTION,
86
- context,
87
- event: {
88
- intellisuggestData: data.intellisuggestData,
89
- intellisuggestSignature: data.intellisuggestSignature,
90
- href: data?.href ? `${data.href}` : undefined,
91
- },
92
- };
93
- const beaconEvent = new BeaconEvent(event, this.config);
94
- const beaconEventData = beaconEvent.send();
95
- return beaconEventData;
67
+ click: () => {
68
+ console.warn(`tracker.track.product.click() is deprecated and is no longer functional. Use tracker.events['search' | 'category'].clickThrough() instead`);
69
+ this.events.error.snap({ data: { message: `tracker.track.product.click was called` } });
96
70
  },
97
71
  },
98
72
  cart: {
99
- view: (data, siteId) => {
100
- if (this.doNotTrack?.includes('cart.view')) {
101
- return;
102
- }
103
- // uid can be optional in legacy payload but required in 2.0 spec - use sku as fallback
104
- const results = data.items
105
- .map((item) => {
106
- if (!item.uid && item.sku) {
107
- return {
108
- ...item,
109
- uid: item.sku,
110
- };
111
- }
112
- else {
113
- return item;
114
- }
115
- })
116
- .map((item) => {
117
- // convert to Product[] - ensure qty and price are numbers
118
- return {
119
- ...item,
120
- qty: Number(item.qty),
121
- price: Number(item.price),
122
- };
123
- });
124
- this.events.cart.view({ data: { results: results }, siteId });
73
+ view: () => {
74
+ console.warn('tracker.cart.view is deprecated and no longer functional. Use tracker.events.cart.add() and tracker.events.cart.remove() instead');
75
+ this.events.error.snap({ data: { message: `tracker.track.cart.view was called` } });
125
76
  },
126
77
  },
127
78
  order: {
@@ -219,7 +170,7 @@ export class Tracker extends Beacon {
219
170
  this.track.product.view(item, siteId);
220
171
  break;
221
172
  case 'searchspring/track/cart/view':
222
- this.track.cart.view({ items }, siteId);
173
+ this.track.cart.view();
223
174
  break;
224
175
  case 'searchspring/track/order/transaction':
225
176
  this.track.order.transaction({ order, items }, siteId);
@@ -290,17 +241,114 @@ export class Tracker extends Beacon {
290
241
  updateRecsControllers();
291
242
  }
292
243
  else if (attributes[`ss-${this.config.id}-intellisuggest`] && attributes[`ss-${this.config.id}-intellisuggest-signature`]) {
293
- // product click
294
- const intellisuggestData = attributes[`ss-${this.config.id}-intellisuggest`];
295
- const intellisuggestSignature = attributes[`ss-${this.config.id}-intellisuggest-signature`];
296
- const href = attributes['href'];
297
- this.track.product.click({
298
- intellisuggestData,
299
- intellisuggestSignature,
300
- href,
301
- });
244
+ this.track.product.click();
302
245
  }
303
246
  });
247
+ const cart = this.globals.cart;
248
+ if (Array.isArray(cart)) {
249
+ if (cart.length === 0) {
250
+ // cart is empty, clear storage and send remove event if storage had items
251
+ const storedCart = this.storage.cart.get();
252
+ if (storedCart.length) {
253
+ this.events.cart.remove({
254
+ data: {
255
+ results: storedCart,
256
+ cart: [],
257
+ },
258
+ });
259
+ }
260
+ this.storage.cart.clear();
261
+ }
262
+ else if (cart.length) {
263
+ // length check here to be able to sent error event if invalid array of objects is provided
264
+ const currentCart = cart
265
+ .filter((item) => typeof item === 'object' &&
266
+ (item.uid || item.sku || item.childUid || item.childSku) &&
267
+ item.qty !== undefined &&
268
+ item.price !== undefined)
269
+ .map((item) => {
270
+ return {
271
+ uid: item.uid,
272
+ childUid: item.childUid,
273
+ sku: item.sku,
274
+ childSku: item.childSku,
275
+ price: item.price,
276
+ qty: item.qty,
277
+ };
278
+ });
279
+ // beacon 2.0 requires all parameters to be present
280
+ // send error to keep track of integrations to be updated
281
+ if (!currentCart.length) {
282
+ this.events.error.snap({
283
+ data: {
284
+ message: 'cart globals missing properties',
285
+ details: { cart },
286
+ },
287
+ });
288
+ }
289
+ const storedCart = this.storage.cart.get();
290
+ const toAdd = [];
291
+ const toRemove = [];
292
+ if (!storedCart?.length && currentCart.length) {
293
+ // no stored cart, add all items
294
+ toAdd.push(...currentCart);
295
+ }
296
+ else if (currentCart.length) {
297
+ currentCart.forEach((item) => {
298
+ const existingItem = storedCart.find((existingItem) => {
299
+ return (existingItem.uid === item.uid &&
300
+ existingItem.sku === item.sku &&
301
+ existingItem.childUid === item.childUid &&
302
+ existingItem.childSku === item.childSku);
303
+ });
304
+ if (!existingItem) {
305
+ // item does not exist in cart, add it
306
+ toAdd.push(item);
307
+ }
308
+ else if (existingItem) {
309
+ // item already exists in cart, check if qty has changed
310
+ if (item.qty > existingItem.qty) {
311
+ toAdd.push({
312
+ ...item,
313
+ qty: item.qty - existingItem.qty,
314
+ });
315
+ }
316
+ else if (item.qty < existingItem.qty) {
317
+ toRemove.push({
318
+ ...existingItem,
319
+ qty: existingItem.qty - item.qty,
320
+ });
321
+ }
322
+ // remove from existing cart
323
+ const index = storedCart.indexOf(existingItem);
324
+ if (index !== -1) {
325
+ storedCart.splice(index, 1);
326
+ }
327
+ }
328
+ });
329
+ // any remaining items in existing cart should be removed
330
+ if (storedCart.length) {
331
+ toRemove.push(...storedCart);
332
+ }
333
+ }
334
+ if (toAdd.length) {
335
+ this.events.cart.add({
336
+ data: {
337
+ results: toAdd,
338
+ cart: currentCart,
339
+ },
340
+ });
341
+ }
342
+ if (toRemove.length) {
343
+ this.events.cart.remove({
344
+ data: {
345
+ results: toRemove,
346
+ cart: currentCart,
347
+ },
348
+ });
349
+ }
350
+ }
351
+ }
304
352
  }
305
353
  getGlobals() {
306
354
  return JSON.parse(JSON.stringify(this.globals));
@@ -311,38 +359,3 @@ export class Tracker extends Beacon {
311
359
  });
312
360
  }
313
361
  }
314
- function transformToLegacyContext(_context, siteId) {
315
- const context = { ..._context };
316
- if (context.userAgent) {
317
- delete context.userAgent;
318
- }
319
- if (context.timestamp) {
320
- // @ts-ignore - property not optional
321
- delete context.timestamp;
322
- }
323
- if (context.initiator) {
324
- // @ts-ignore - property not optional
325
- delete context.initiator;
326
- }
327
- if (context.dev) {
328
- delete context.dev;
329
- }
330
- let attribution;
331
- if (context.attribution?.length) {
332
- attribution = {
333
- type: context.attribution[0].type,
334
- id: context.attribution[0].id,
335
- };
336
- delete context.attribution;
337
- }
338
- const beaconContext = {
339
- ...context,
340
- website: {
341
- trackingCode: siteId,
342
- },
343
- };
344
- if (attribution) {
345
- beaconContext.attribution = attribution;
346
- }
347
- return beaconContext;
348
- }
@@ -1,4 +1,3 @@
1
1
  export { Tracker } from './Tracker';
2
- export type { BeaconEvent } from './BeaconEvent';
3
2
  export * from './types';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,cAAc,SAAS,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import { AppMode } from '@searchspring/snap-toolbox';
2
- import { BeaconEvent } from './BeaconEvent';
3
- import type { ContextCurrency } from '@searchspring/beacon';
2
+ import type { ContextCurrency, Product } from '@searchspring/beacon';
4
3
  export type TrackerGlobals = {
5
4
  siteId: string;
6
5
  currency?: ContextCurrency;
6
+ cart?: Product[];
7
7
  };
8
8
  export type TrackerEvents = 'error' | 'shopper.login' | 'product.view' | 'product.click' | 'cart.view' | 'order.transaction';
9
9
  export type TrackerConfig = {
@@ -20,50 +20,6 @@ export type TrackerConfig = {
20
20
  };
21
21
  doNotTrack?: TrackerEvents[];
22
22
  };
23
- export type BeaconPayload = {
24
- type: BeaconType;
25
- category: BeaconCategory;
26
- context?: BeaconContext;
27
- meta?: BeaconMeta;
28
- event: ProductViewEvent | CartViewEvent | OrderTransactionEvent | RecommendationsEvent | ProductClickEvent | CustomBeaconEvent | Record<string, never>;
29
- id?: string;
30
- pid?: string | null;
31
- };
32
- export declare enum BeaconType {
33
- CLICK = "click"
34
- }
35
- export declare enum BeaconCategory {
36
- INTERACTION = "searchspring.user-interactions"
37
- }
38
- export declare enum ProfilePlacement {
39
- BASKETPAGE = "basket-page",
40
- CONFIRMATIONPAGE = "confirmation-page",
41
- PRODUCTPAGE = "product-page",
42
- NORESULTSPAGE = "no-results-page",
43
- HOMEPAGE = "home-page",
44
- OTHER = "other"
45
- }
46
- export interface BeaconContext {
47
- userId?: string;
48
- pageLoadId?: string;
49
- sessionId?: string;
50
- shopperId?: string;
51
- website: {
52
- trackingCode: string;
53
- };
54
- attribution?: {
55
- type?: string;
56
- id?: string;
57
- };
58
- currency?: ContextCurrency;
59
- }
60
- export interface BeaconMeta {
61
- initiator: {
62
- lib: string;
63
- 'lib.version': string;
64
- 'lib.framework': string;
65
- };
66
- }
67
23
  export interface ShopperLoginEvent {
68
24
  id: string;
69
25
  }
@@ -91,22 +47,10 @@ export interface ProductViewEvent {
91
47
  childUid?: string;
92
48
  childSku?: string;
93
49
  }
94
- export interface CartViewEvent {
95
- items: ProductData[];
96
- }
97
50
  export interface ProductData extends ProductViewEvent {
98
51
  qty: string | number;
99
52
  price: string | number;
100
53
  }
101
- export interface OrderTransactionEvent {
102
- orderId?: string | number;
103
- total?: string | number;
104
- transactionTotal?: string | number;
105
- city?: string;
106
- state?: string;
107
- country?: string;
108
- items: ProductData[];
109
- }
110
54
  export interface OrderTransactionData {
111
55
  order?: {
112
56
  id?: string | number;
@@ -118,47 +62,6 @@ export interface OrderTransactionData {
118
62
  };
119
63
  items: ProductData[];
120
64
  }
121
- export interface RecommendationsEvent {
122
- profile?: {
123
- tag?: string;
124
- placement?: ProfilePlacement;
125
- seed?: ProductViewEvent[];
126
- };
127
- product?: {
128
- id?: string;
129
- mappings?: {
130
- core?: {
131
- sku?: string;
132
- name?: string;
133
- url?: string;
134
- thumbnailImageUrl?: string;
135
- price?: number;
136
- msrp?: number;
137
- };
138
- };
139
- seed?: ProductViewEvent[];
140
- };
141
- context?: {
142
- type?: string;
143
- tag?: string;
144
- placement?: ProfilePlacement;
145
- };
146
- }
147
- export interface ProductClickEvent {
148
- intellisuggestData: string;
149
- intellisuggestSignature: string;
150
- href?: string;
151
- }
152
- export interface CustomBeaconEvent {
153
- [key: string]: any;
154
- }
155
- export type PreflightRequestModel = {
156
- userId: string;
157
- siteId: string;
158
- shopper?: string;
159
- cart?: string[];
160
- lastViewed?: string[];
161
- };
162
65
  export interface TrackMethods {
163
66
  error: (data: TrackErrorEvent) => undefined;
164
67
  shopper: {
@@ -166,10 +69,10 @@ export interface TrackMethods {
166
69
  };
167
70
  product: {
168
71
  view: (data: ProductViewEvent, siteId?: string) => undefined;
169
- click: (data: ProductClickEvent, siteId?: string) => BeaconEvent | undefined;
72
+ click: () => void;
170
73
  };
171
74
  cart: {
172
- view: (data: CartViewEvent, siteId?: string) => undefined;
75
+ view: () => void;
173
76
  };
174
77
  order: {
175
78
  transaction: (data: OrderTransactionData, siteId?: string) => undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,eAAe,GAAG,cAAc,GAAG,eAAe,GAAG,WAAW,GAAG,mBAAmB,CAAC;AAE7H,MAAM,MAAM,aAAa,GAAG;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,C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,CAAC;IACF,IAAI,EAAE;QACL,IAAI,EAAE,MAAM,IAAI,CAAC;KACjB,CAAC;IACF,KAAK,EAAE;QACN,WAAW,EAAE,CAAC,IAAI,EAAE,oBAAoB,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,SAAS,CAAC;KACxE,CAAC;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,YAAY,CAAC,EAAE,GAAG,CAAC;KACnB;CACD"}
package/dist/esm/types.js CHANGED
@@ -1,19 +1 @@
1
- // TODO: remove when 1.0 is sunset
2
- export var BeaconType;
3
- (function (BeaconType) {
4
- BeaconType["CLICK"] = "click";
5
- })(BeaconType || (BeaconType = {}));
6
- // TODO: remove when 1.0 is sunset
7
- export var BeaconCategory;
8
- (function (BeaconCategory) {
9
- BeaconCategory["INTERACTION"] = "searchspring.user-interactions";
10
- })(BeaconCategory || (BeaconCategory = {}));
11
- export var ProfilePlacement;
12
- (function (ProfilePlacement) {
13
- ProfilePlacement["BASKETPAGE"] = "basket-page";
14
- ProfilePlacement["CONFIRMATIONPAGE"] = "confirmation-page";
15
- ProfilePlacement["PRODUCTPAGE"] = "product-page";
16
- ProfilePlacement["NORESULTSPAGE"] = "no-results-page";
17
- ProfilePlacement["HOMEPAGE"] = "home-page";
18
- ProfilePlacement["OTHER"] = "other";
19
- })(ProfilePlacement || (ProfilePlacement = {}));
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searchspring/snap-tracker",
3
- "version": "0.65.2",
3
+ "version": "0.66.0",
4
4
  "description": "Snap Tracker",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -20,9 +20,9 @@
20
20
  "test:watch": "jest --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@searchspring/beacon": "0.0.24",
24
- "@searchspring/snap-store-mobx": "^0.65.2",
25
- "@searchspring/snap-toolbox": "^0.65.2",
23
+ "@searchspring/beacon": "0.0.28",
24
+ "@searchspring/snap-store-mobx": "^0.66.0",
25
+ "@searchspring/snap-toolbox": "^0.66.0",
26
26
  "@types/uuid": "^10.0.0",
27
27
  "deepmerge": "4.3.1",
28
28
  "uuid": "11.1.0"
@@ -31,5 +31,5 @@
31
31
  "files": [
32
32
  "dist/**/*"
33
33
  ],
34
- "gitHead": "3e80b62664af7e3104e578d6c2596c439d5dfd78"
34
+ "gitHead": "97d209ef85cfb63946bea8ce3737b7dcb2803b89"
35
35
  }
@@ -1,14 +0,0 @@
1
- import * as Types from './types';
2
- export declare class BeaconEvent {
3
- type: Types.BeaconType;
4
- category: Types.BeaconCategory;
5
- context?: Types.BeaconContext;
6
- meta?: Types.BeaconMeta;
7
- event?: Types.ProductViewEvent | Types.CartViewEvent | Types.OrderTransactionEvent | Types.RecommendationsEvent | Types.ProductClickEvent | Types.CustomBeaconEvent | Record<string, never>;
8
- id?: string;
9
- pid?: string | null;
10
- private origin?;
11
- constructor(payload: Types.BeaconPayload, config: Types.TrackerConfig);
12
- send(): BeaconEvent;
13
- }
14
- //# sourceMappingURL=BeaconEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BeaconEvent.d.ts","sourceRoot":"","sources":["../../src/BeaconEvent.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,qBAAa,WAAW;IACvB,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC;IACvB,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC;IAC/B,OAAO,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC9B,IAAI,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC;IACxB,KAAK,CAAC,EACH,KAAK,CAAC,gBAAgB,GACtB,KAAK,CAAC,aAAa,GACnB,KAAK,CAAC,qBAAqB,GAC3B,KAAK,CAAC,oBAAoB,GAC1B,KAAK,CAAC,iBAAiB,GACvB,KAAK,CAAC,iBAAiB,GACvB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,MAAM,CAAC,CAAS;gBAEZ,OAAO,EAAE,KAAK,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,aAAa;IAoBrE,IAAI,IAAI,WAAW;CAiBnB"}
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.BeaconEvent = void 0;
15
- var uuid_1 = require("uuid");
16
- var snap_toolbox_1 = require("@searchspring/snap-toolbox");
17
- var BeaconEvent = /** @class */ (function () {
18
- function BeaconEvent(payload, config) {
19
- var _a, _b;
20
- this.type = payload.type;
21
- this.category = payload.category;
22
- this.context = payload.context;
23
- this.meta = payload.meta;
24
- this.event = payload.event;
25
- this.id = payload.id;
26
- this.pid = payload.pid;
27
- this.origin = ((_b = (_a = config.requesters) === null || _a === void 0 ? void 0 : _a.beacon) === null || _b === void 0 ? void 0 : _b.origin) || 'https://beacon.searchspring.io';
28
- this.meta = {
29
- initiator: {
30
- lib: 'searchspring/snap',
31
- 'lib.version': snap_toolbox_1.version,
32
- 'lib.framework': config.framework,
33
- },
34
- };
35
- this.id = (0, uuid_1.v4)();
36
- }
37
- BeaconEvent.prototype.send = function () {
38
- var data = __assign({}, this);
39
- var origin = data.origin;
40
- delete data.origin;
41
- if (typeof fetch !== 'undefined') {
42
- fetch("".concat(origin, "/beacon"), {
43
- method: 'POST',
44
- headers: {
45
- 'Content-Type': 'application/json',
46
- },
47
- body: JSON.stringify(data),
48
- keepalive: true,
49
- });
50
- }
51
- return data;
52
- };
53
- return BeaconEvent;
54
- }());
55
- exports.BeaconEvent = BeaconEvent;
@@ -1,14 +0,0 @@
1
- import * as Types from './types';
2
- export declare class BeaconEvent {
3
- type: Types.BeaconType;
4
- category: Types.BeaconCategory;
5
- context?: Types.BeaconContext;
6
- meta?: Types.BeaconMeta;
7
- event?: Types.ProductViewEvent | Types.CartViewEvent | Types.OrderTransactionEvent | Types.RecommendationsEvent | Types.ProductClickEvent | Types.CustomBeaconEvent | Record<string, never>;
8
- id?: string;
9
- pid?: string | null;
10
- private origin?;
11
- constructor(payload: Types.BeaconPayload, config: Types.TrackerConfig);
12
- send(): BeaconEvent;
13
- }
14
- //# sourceMappingURL=BeaconEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BeaconEvent.d.ts","sourceRoot":"","sources":["../../src/BeaconEvent.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,qBAAa,WAAW;IACvB,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC;IACvB,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC;IAC/B,OAAO,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC9B,IAAI,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC;IACxB,KAAK,CAAC,EACH,KAAK,CAAC,gBAAgB,GACtB,KAAK,CAAC,aAAa,GACnB,KAAK,CAAC,qBAAqB,GAC3B,KAAK,CAAC,oBAAoB,GAC1B,KAAK,CAAC,iBAAiB,GACvB,KAAK,CAAC,iBAAiB,GACvB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,MAAM,CAAC,CAAS;gBAEZ,OAAO,EAAE,KAAK,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,aAAa;IAoBrE,IAAI,IAAI,WAAW;CAiBnB"}
@@ -1,38 +0,0 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- import { version } from '@searchspring/snap-toolbox';
3
- export class BeaconEvent {
4
- constructor(payload, config) {
5
- this.type = payload.type;
6
- this.category = payload.category;
7
- this.context = payload.context;
8
- this.meta = payload.meta;
9
- this.event = payload.event;
10
- this.id = payload.id;
11
- this.pid = payload.pid;
12
- this.origin = config.requesters?.beacon?.origin || 'https://beacon.searchspring.io';
13
- this.meta = {
14
- initiator: {
15
- lib: 'searchspring/snap',
16
- 'lib.version': version,
17
- 'lib.framework': config.framework,
18
- },
19
- };
20
- this.id = uuidv4();
21
- }
22
- send() {
23
- const data = { ...this };
24
- const origin = data.origin;
25
- delete data.origin;
26
- if (typeof fetch !== 'undefined') {
27
- fetch(`${origin}/beacon`, {
28
- method: 'POST',
29
- headers: {
30
- 'Content-Type': 'application/json',
31
- },
32
- body: JSON.stringify(data),
33
- keepalive: true,
34
- });
35
- }
36
- return data;
37
- }
38
- }