@searchspring/snap-tracker 0.20.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.
- package/LICENSE +21 -0
- package/README.md +474 -0
- package/dist/cjs/BeaconEvent.d.ts +12 -0
- package/dist/cjs/BeaconEvent.d.ts.map +1 -0
- package/dist/cjs/BeaconEvent.js +22 -0
- package/dist/cjs/PixelEvent.d.ts +9 -0
- package/dist/cjs/PixelEvent.d.ts.map +1 -0
- package/dist/cjs/PixelEvent.js +63 -0
- package/dist/cjs/TrackEvent.d.ts +11 -0
- package/dist/cjs/TrackEvent.d.ts.map +1 -0
- package/dist/cjs/TrackEvent.js +31 -0
- package/dist/cjs/Tracker.d.ts +31 -0
- package/dist/cjs/Tracker.d.ts.map +1 -0
- package/dist/cjs/Tracker.js +491 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +16 -0
- package/dist/cjs/types.d.ts +144 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +30 -0
- package/dist/esm/BeaconEvent.d.ts +12 -0
- package/dist/esm/BeaconEvent.d.ts.map +1 -0
- package/dist/esm/BeaconEvent.js +16 -0
- package/dist/esm/PixelEvent.d.ts +9 -0
- package/dist/esm/PixelEvent.d.ts.map +1 -0
- package/dist/esm/PixelEvent.js +57 -0
- package/dist/esm/TrackEvent.d.ts +11 -0
- package/dist/esm/TrackEvent.d.ts.map +1 -0
- package/dist/esm/TrackEvent.js +25 -0
- package/dist/esm/Tracker.d.ts +31 -0
- package/dist/esm/Tracker.d.ts.map +1 -0
- package/dist/esm/Tracker.js +462 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/types.d.ts +144 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +27 -0
- package/package.json +33 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { BeaconEvent } from './BeaconEvent';
|
|
2
|
+
export declare type TrackerGlobals = {
|
|
3
|
+
siteId: string;
|
|
4
|
+
};
|
|
5
|
+
export declare type TrackerConfig = {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
export interface BeaconPayload {
|
|
9
|
+
type: BeaconType;
|
|
10
|
+
category: BeaconCategory;
|
|
11
|
+
context?: BeaconContext;
|
|
12
|
+
meta?: BeaconMeta;
|
|
13
|
+
event: ProductViewEvent | CartViewEvent | OrderTransactionEvent | RecommendationsEvent | ProductClickEvent | CustomBeaconEvent | Record<string, never>;
|
|
14
|
+
id?: string;
|
|
15
|
+
pid?: string | null;
|
|
16
|
+
}
|
|
17
|
+
export declare enum BeaconType {
|
|
18
|
+
PRODUCT = "product",
|
|
19
|
+
CART = "cart",
|
|
20
|
+
ORDER = "transaction",
|
|
21
|
+
LOGIN = "login",
|
|
22
|
+
CLICK = "click",
|
|
23
|
+
CUSTOM = "custom",
|
|
24
|
+
/** For Profiles Recommendations */
|
|
25
|
+
PROFILE_RENDER = "profile.render",
|
|
26
|
+
PROFILE_IMPRESSION = "profile.impression",
|
|
27
|
+
PROFILE_CLICK = "profile.click",
|
|
28
|
+
/** For Recommended Products within a Profile */
|
|
29
|
+
PROFILE_PRODUCT_RENDER = "profile.product.render",
|
|
30
|
+
PROFILE_PRODUCT_IMPRESSION = "profile.product.impression",
|
|
31
|
+
PROFILE_PRODUCT_CLICK = "profile.product.click"
|
|
32
|
+
}
|
|
33
|
+
export declare enum BeaconCategory {
|
|
34
|
+
PAGEVIEW = "searchspring.page.view",
|
|
35
|
+
CARTVIEW = "searchspring.shop.cart",
|
|
36
|
+
ORDERVIEW = "searchspring.shop.transaction",
|
|
37
|
+
PERSONALIZATION = "searchspring.personalization",
|
|
38
|
+
RECOMMENDATIONS = "searchspring.recommendations.user-interactions",
|
|
39
|
+
INTERACTION = "searchspring.user-interactions",
|
|
40
|
+
CUSTOM = "custom"
|
|
41
|
+
}
|
|
42
|
+
export interface BeaconContext {
|
|
43
|
+
userId?: string;
|
|
44
|
+
pageLoadId?: string;
|
|
45
|
+
sessionId?: string;
|
|
46
|
+
shopperId?: string;
|
|
47
|
+
website: {
|
|
48
|
+
trackingCode: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface BeaconMeta {
|
|
52
|
+
initiator: {
|
|
53
|
+
lib: string;
|
|
54
|
+
'lib.version': string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface ShopperLoginEvent {
|
|
58
|
+
id: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ProductViewEvent {
|
|
61
|
+
sku?: string;
|
|
62
|
+
childSku?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface CartViewEvent {
|
|
65
|
+
items: Product[];
|
|
66
|
+
}
|
|
67
|
+
export interface Product extends ProductViewEvent {
|
|
68
|
+
qty: string | number;
|
|
69
|
+
price: string | number;
|
|
70
|
+
}
|
|
71
|
+
export interface OrderTransactionEvent {
|
|
72
|
+
orderId?: string | number;
|
|
73
|
+
total?: string | number;
|
|
74
|
+
city?: string;
|
|
75
|
+
state?: string;
|
|
76
|
+
country?: string;
|
|
77
|
+
items: Product[];
|
|
78
|
+
}
|
|
79
|
+
export interface OrderTransactionData {
|
|
80
|
+
order?: {
|
|
81
|
+
id?: string | number;
|
|
82
|
+
total?: string | number;
|
|
83
|
+
city?: string;
|
|
84
|
+
state?: string;
|
|
85
|
+
country?: string;
|
|
86
|
+
};
|
|
87
|
+
items: Product[];
|
|
88
|
+
}
|
|
89
|
+
export interface RecommendationsEvent {
|
|
90
|
+
profile?: {
|
|
91
|
+
tag?: string;
|
|
92
|
+
placement?: string;
|
|
93
|
+
seed?: ProductViewEvent[];
|
|
94
|
+
};
|
|
95
|
+
product?: {
|
|
96
|
+
id?: string;
|
|
97
|
+
mappings?: {
|
|
98
|
+
core?: {
|
|
99
|
+
sku?: string;
|
|
100
|
+
name?: string;
|
|
101
|
+
url?: string;
|
|
102
|
+
thumbnailImageUrl?: string;
|
|
103
|
+
price?: number;
|
|
104
|
+
msrp?: number;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
seed?: ProductViewEvent[];
|
|
108
|
+
};
|
|
109
|
+
context?: {
|
|
110
|
+
type?: string;
|
|
111
|
+
tag?: string;
|
|
112
|
+
placement?: string;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export interface ProductClickEvent {
|
|
116
|
+
intellisuggestData: string;
|
|
117
|
+
intellisuggestSignature: string;
|
|
118
|
+
href?: string;
|
|
119
|
+
}
|
|
120
|
+
export interface CustomBeaconEvent {
|
|
121
|
+
[key: string]: any;
|
|
122
|
+
}
|
|
123
|
+
export interface TrackMethods {
|
|
124
|
+
event: (payload: BeaconPayload) => BeaconEvent;
|
|
125
|
+
shopper: {
|
|
126
|
+
login: (data: ShopperLoginEvent, siteId?: string) => BeaconEvent;
|
|
127
|
+
};
|
|
128
|
+
product: {
|
|
129
|
+
view: (data: ProductViewEvent, siteId?: string) => BeaconEvent;
|
|
130
|
+
click: (data: ProductClickEvent, siteId?: string) => BeaconEvent;
|
|
131
|
+
};
|
|
132
|
+
cart: {
|
|
133
|
+
view: (data: CartViewEvent, siteId?: string) => BeaconEvent;
|
|
134
|
+
};
|
|
135
|
+
order: {
|
|
136
|
+
transaction: (data: OrderTransactionData, siteId?: string) => BeaconEvent;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
declare global {
|
|
140
|
+
interface Window {
|
|
141
|
+
searchspring?: any;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,oBAAY,cAAc,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;CACf,CA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AAK,EAAE;QACN,WAAW,EAAE,CAAC,IAAI,EAAE,oBAAoB,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,WAAW,CAAC;KAC1E,CAAC;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,YAAY,CAAC,EAAE,GAAG,CAAC;KACnB;CACD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BeaconCategory = exports.BeaconType = void 0;
|
|
4
|
+
var BeaconType;
|
|
5
|
+
(function (BeaconType) {
|
|
6
|
+
BeaconType["PRODUCT"] = "product";
|
|
7
|
+
BeaconType["CART"] = "cart";
|
|
8
|
+
BeaconType["ORDER"] = "transaction";
|
|
9
|
+
BeaconType["LOGIN"] = "login";
|
|
10
|
+
BeaconType["CLICK"] = "click";
|
|
11
|
+
BeaconType["CUSTOM"] = "custom";
|
|
12
|
+
/** For Profiles Recommendations */
|
|
13
|
+
BeaconType["PROFILE_RENDER"] = "profile.render";
|
|
14
|
+
BeaconType["PROFILE_IMPRESSION"] = "profile.impression";
|
|
15
|
+
BeaconType["PROFILE_CLICK"] = "profile.click";
|
|
16
|
+
/** For Recommended Products within a Profile */
|
|
17
|
+
BeaconType["PROFILE_PRODUCT_RENDER"] = "profile.product.render";
|
|
18
|
+
BeaconType["PROFILE_PRODUCT_IMPRESSION"] = "profile.product.impression";
|
|
19
|
+
BeaconType["PROFILE_PRODUCT_CLICK"] = "profile.product.click";
|
|
20
|
+
})(BeaconType = exports.BeaconType || (exports.BeaconType = {}));
|
|
21
|
+
var BeaconCategory;
|
|
22
|
+
(function (BeaconCategory) {
|
|
23
|
+
BeaconCategory["PAGEVIEW"] = "searchspring.page.view";
|
|
24
|
+
BeaconCategory["CARTVIEW"] = "searchspring.shop.cart";
|
|
25
|
+
BeaconCategory["ORDERVIEW"] = "searchspring.shop.transaction";
|
|
26
|
+
BeaconCategory["PERSONALIZATION"] = "searchspring.personalization";
|
|
27
|
+
BeaconCategory["RECOMMENDATIONS"] = "searchspring.recommendations.user-interactions";
|
|
28
|
+
BeaconCategory["INTERACTION"] = "searchspring.user-interactions";
|
|
29
|
+
BeaconCategory["CUSTOM"] = "custom";
|
|
30
|
+
})(BeaconCategory = exports.BeaconCategory || (exports.BeaconCategory = {}));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BeaconPayload } from './types';
|
|
2
|
+
export declare class BeaconEvent implements BeaconPayload {
|
|
3
|
+
type: any;
|
|
4
|
+
category: any;
|
|
5
|
+
context: any;
|
|
6
|
+
event: any;
|
|
7
|
+
meta: any;
|
|
8
|
+
id: any;
|
|
9
|
+
pid?: any;
|
|
10
|
+
constructor(payload: BeaconPayload);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=BeaconEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BeaconEvent.d.ts","sourceRoot":"","sources":["../../src/BeaconEvent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,WAAY,YAAW,aAAa;IAChD,IAAI,MAAC;IACL,QAAQ,MAAC;IACT,OAAO,MAAC;IACR,KAAK,MAAC;IACN,IAAI,MAAC;IACL,EAAE,MAAC;IACH,GAAG,CAAC,MAAC;gBAEO,OAAO,EAAE,aAAa;CAYlC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import { version } from '@searchspring/snap-toolbox';
|
|
3
|
+
export class BeaconEvent {
|
|
4
|
+
constructor(payload) {
|
|
5
|
+
Object.keys(payload).forEach((key) => {
|
|
6
|
+
this[key] = payload[key];
|
|
7
|
+
});
|
|
8
|
+
this.meta = {
|
|
9
|
+
initiator: {
|
|
10
|
+
lib: 'searchspring/snap',
|
|
11
|
+
'lib.version': version,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
this.id = uuidv4();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ProductViewEvent, OrderTransactionEvent, BeaconPayload, CartViewEvent } from './types';
|
|
2
|
+
export declare class PixelEvent {
|
|
3
|
+
endpoint: string;
|
|
4
|
+
src: string;
|
|
5
|
+
img: HTMLImageElement;
|
|
6
|
+
event: ProductViewEvent | CartViewEvent | OrderTransactionEvent;
|
|
7
|
+
constructor(payload: BeaconPayload);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=PixelEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PixelEvent.d.ts","sourceRoot":"","sources":["../../src/PixelEvent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,aAAa,EAAE,aAAa,EAAkB,MAAM,SAAS,CAAC;AAEhH,qBAAa,UAAU;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,gBAAgB,CAAC;IACtB,KAAK,EAAE,gBAAgB,GAAG,aAAa,GAAG,qBAAqB,CAAC;gBAEpD,OAAO,EAAE,aAAa;CAkDlC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { featureFlags } from '@searchspring/snap-toolbox';
|
|
2
|
+
import { BeaconCategory } from './types';
|
|
3
|
+
export class PixelEvent {
|
|
4
|
+
constructor(payload) {
|
|
5
|
+
this.endpoint = `https://d3cgm8py10hi0z.cloudfront.net/is.gif`;
|
|
6
|
+
this.src =
|
|
7
|
+
this.endpoint +
|
|
8
|
+
`?s=${encodeURIComponent(payload.context.website.trackingCode)}` +
|
|
9
|
+
`&u=${encodeURIComponent(payload.context.userId)}` +
|
|
10
|
+
`&ce=${featureFlags.cookies ? '1' : '0'}` +
|
|
11
|
+
`&pt=${encodeURIComponent(document.title)}` +
|
|
12
|
+
`&v=1` + // version always '1'? or set to snap package version?
|
|
13
|
+
`&x=${Math.floor(Math.random() * 2147483647)}` +
|
|
14
|
+
`${window.document.referrer ? `&r=${encodeURIComponent(window.document.referrer)}` : ''}`;
|
|
15
|
+
switch (payload.category) {
|
|
16
|
+
case BeaconCategory.PAGEVIEW:
|
|
17
|
+
this.event = payload.event;
|
|
18
|
+
this.src += '&a=viewItem';
|
|
19
|
+
if (this.event.sku) {
|
|
20
|
+
this.src += `&sku=${encodeURIComponent(this.event.sku)}`;
|
|
21
|
+
}
|
|
22
|
+
break;
|
|
23
|
+
case BeaconCategory.CARTVIEW:
|
|
24
|
+
this.event = payload.event;
|
|
25
|
+
this.src += '&a=basket';
|
|
26
|
+
this.event.items.forEach((item) => {
|
|
27
|
+
if (item.sku) {
|
|
28
|
+
this.src += `&item=${encodeURIComponent(item.sku)};${encodeURIComponent(item?.qty || '')};${encodeURIComponent(item?.price || '')};`;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
break;
|
|
32
|
+
case BeaconCategory.ORDERVIEW:
|
|
33
|
+
const { orderId, total, city, state, country, items } = (this.event = payload.event);
|
|
34
|
+
this.src += `&a=sale`;
|
|
35
|
+
if (orderId)
|
|
36
|
+
this.src += `&orderId=${encodeURIComponent(orderId)}`;
|
|
37
|
+
if (total)
|
|
38
|
+
this.src += `&total=${encodeURIComponent(total)}`;
|
|
39
|
+
if (city)
|
|
40
|
+
this.src += `&city=${encodeURIComponent(city)}`;
|
|
41
|
+
if (state)
|
|
42
|
+
this.src += `&state=${encodeURIComponent(state)}`;
|
|
43
|
+
if (country)
|
|
44
|
+
this.src += `&country=${encodeURIComponent(country)}`;
|
|
45
|
+
items.forEach((item) => {
|
|
46
|
+
if (item.sku) {
|
|
47
|
+
this.src += `&item=${encodeURIComponent(item.sku)};${encodeURIComponent(item?.qty || '')};${encodeURIComponent(item?.price || '')};`;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
if (this.src.includes('&a=')) {
|
|
53
|
+
this.img = new Image(1, 1);
|
|
54
|
+
this.img.src = this.src; // setting src immediately invokes a request
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BeaconPayload } from './types';
|
|
2
|
+
export declare class TrackEvent {
|
|
3
|
+
intellisuggestData: string;
|
|
4
|
+
intellisuggestSignature: string;
|
|
5
|
+
href?: string;
|
|
6
|
+
endpoint: string;
|
|
7
|
+
src: string;
|
|
8
|
+
img: HTMLImageElement;
|
|
9
|
+
constructor(payload: BeaconPayload);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=TrackEvent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrackEvent.d.ts","sourceRoot":"","sources":["../../src/TrackEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,MAAM,SAAS,CAAC;AAE3D,qBAAa,UAAU;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,uBAAuB,EAAE,MAAM,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,gBAAgB,CAAC;gBAEV,OAAO,EAAE,aAAa;CA6BlC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class TrackEvent {
|
|
2
|
+
constructor(payload) {
|
|
3
|
+
payload.event = payload.event;
|
|
4
|
+
if (!payload.context || !payload.event) {
|
|
5
|
+
throw 'TrackEvent: object parameter required a valid `context` BeaconContext and `event` ProductClickEvent objects';
|
|
6
|
+
}
|
|
7
|
+
if (!payload.event?.intellisuggestData || !payload.event?.intellisuggestSignature) {
|
|
8
|
+
throw 'TrackEvent: object parameter `event` ProductClickEvent object requires valid intellisuggestData and intellisuggestSignature values. These are the corresponding attributes in the Searchspring API response.';
|
|
9
|
+
}
|
|
10
|
+
this.intellisuggestData = payload.event.intellisuggestData;
|
|
11
|
+
this.intellisuggestSignature = payload.event.intellisuggestSignature;
|
|
12
|
+
this.href = payload.event?.href || '';
|
|
13
|
+
this.endpoint = `https://${payload.context.website.trackingCode}.a.searchspring.io/api/track/track.json`;
|
|
14
|
+
this.src =
|
|
15
|
+
this.endpoint +
|
|
16
|
+
`?d=${encodeURIComponent(this.intellisuggestData)}` +
|
|
17
|
+
`&s=${encodeURIComponent(this.intellisuggestSignature)}` +
|
|
18
|
+
`&u=${encodeURIComponent(this.href)}`;
|
|
19
|
+
if (window.document.referrer) {
|
|
20
|
+
this.src += `&r=${encodeURIComponent(window.document.referrer)}`;
|
|
21
|
+
}
|
|
22
|
+
this.img = new Image(1, 1);
|
|
23
|
+
this.img.src = this.src; // setting src immediately invokes a request
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StorageStore } from '@searchspring/snap-store-mobx';
|
|
2
|
+
import { BeaconEvent } from './BeaconEvent';
|
|
3
|
+
import { TrackerGlobals, TrackMethods, BeaconContext, TrackerConfig } from './types';
|
|
4
|
+
export declare class Tracker {
|
|
5
|
+
globals: TrackerGlobals;
|
|
6
|
+
localStorage: StorageStore;
|
|
7
|
+
context: BeaconContext;
|
|
8
|
+
isSending: number;
|
|
9
|
+
private config;
|
|
10
|
+
private targeters;
|
|
11
|
+
constructor(globals: TrackerGlobals, config?: TrackerConfig);
|
|
12
|
+
retarget(): void;
|
|
13
|
+
track: TrackMethods;
|
|
14
|
+
getUserId: () => string;
|
|
15
|
+
getSessionId: () => string;
|
|
16
|
+
getShopperId: () => string;
|
|
17
|
+
cookies: {
|
|
18
|
+
cart: {
|
|
19
|
+
get: () => string[];
|
|
20
|
+
set: (items: string[]) => void;
|
|
21
|
+
add: (items: string[]) => void;
|
|
22
|
+
remove: (items: string[]) => void;
|
|
23
|
+
clear: () => void;
|
|
24
|
+
};
|
|
25
|
+
viewed: {
|
|
26
|
+
get: () => string[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
sendEvents: (eventsToSend?: BeaconEvent[]) => void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=Tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tracker.d.ts","sourceRoot":"","sources":["../../src/Tracker.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAe,MAAM,+BAA+B,CAAC;AAK1E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACN,cAAc,EACd,YAAY,EAIZ,aAAa,EAOb,aAAa,EACb,MAAM,SAAS,CAAC;AAkBjB,qBAAa,OAAO;IACnB,OAAO,EAAE,cAAc,CAAC;IACxB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAElB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,SAAS,CAAqB;gBAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,aAAa;IAwGpD,QAAQ,IAAI,IAAI;IAMvB,KAAK,EAAE,YAAY,CA6PjB;IAEF,SAAS,QAAO,MAAM,CAiBpB;IAEF,YAAY,QAAO,MAAM,CAoBvB;IAEF,YAAY,QAAO,MAAM,CAOvB;IAEF,OAAO;;uBAEI,MAAM,EAAE;yBAOJ,MAAM,EAAE,KAAG,IAAI;yBAOf,MAAM,EAAE,KAAG,IAAI;4BAQZ,MAAM,EAAE,KAAG,IAAI;;;;uBAatB,MAAM,EAAE;;MAQjB;IAEF,UAAU,kBAAmB,WAAW,EAAE,KAAG,IAAI,CAoB/C;CACF"}
|