@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.
- package/README.md +12 -500
- package/dist/cjs/Tracker.d.ts.map +1 -1
- package/dist/cjs/Tracker.js +121 -94
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/types.d.ts +4 -101
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +0 -20
- package/dist/esm/Tracker.d.ts.map +1 -1
- package/dist/esm/Tracker.js +114 -101
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/types.d.ts +4 -101
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +1 -19
- package/package.json +5 -5
- package/dist/cjs/BeaconEvent.d.ts +0 -14
- package/dist/cjs/BeaconEvent.d.ts.map +0 -1
- package/dist/cjs/BeaconEvent.js +0 -55
- package/dist/esm/BeaconEvent.d.ts +0 -14
- package/dist/esm/BeaconEvent.d.ts.map +0 -1
- package/dist/esm/BeaconEvent.js +0 -38
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<a href="https://www.npmjs.com/package/@searchspring/snap-tracker"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-tracker.svg?style=flat"></a>
|
|
4
4
|
|
|
5
|
-
The Snap Tracker service is responsible for sending beacon events.
|
|
5
|
+
The Snap Tracker service is responsible for sending beacon events. Its class directly extends the [beacon.js](https://github.com/searchspring/beacon.js) `Beacon` class, therefore all methods and properties of the Beacon class are available on the Tracker class and are not documented below.
|
|
6
6
|
|
|
7
7
|
## Dependencies
|
|
8
8
|
|
|
@@ -27,6 +27,13 @@ import { Tracker } from '@searchspring/snap-tracker';
|
|
|
27
27
|
| framework | unique identifier for the framework utilizing the tracker | snap | |
|
|
28
28
|
| mode | application mode (production, development) | production | |
|
|
29
29
|
| doNotTrack | array of TrackerEvents, used to block specific types of tracking | ➖ | |
|
|
30
|
+
| initiator | unique identifier for the beacon | beaconjs/{version} | |
|
|
31
|
+
| apis | configure various api options | | |
|
|
32
|
+
| apis.fetch | FetchAPI reference to use | window.fetch | |
|
|
33
|
+
| requesters.personalization.origin | alternative endpoint for personalization preflight api | https://{siteId}.a.searchspring.io | |
|
|
34
|
+
| requesters.beacon.origin | alternative endpoint for beacon api | https://beacon.searchspring.io/beacon/v2 | |
|
|
35
|
+
| href | set href | window.location.href | |
|
|
36
|
+
| userAgent | set userAgent | navigator.userAgent | |
|
|
30
37
|
|
|
31
38
|
|
|
32
39
|
## Controller usage
|
|
@@ -45,505 +52,10 @@ console.log(tracker.track.product.click === controller.tracker.track.product.cli
|
|
|
45
52
|
console.log(tracker.track.product.click === window.searchspring.tracker.track.product.click) // true
|
|
46
53
|
```
|
|
47
54
|
|
|
48
|
-
##
|
|
49
|
-
|
|
55
|
+
## Snap Integration Usage
|
|
56
|
+
See [Integration Tracking](https://github.com/searchspring/snap/blob/main/docs/INTEGRATION_TRACKING.md) for how and where to implement tracking events.
|
|
50
57
|
|
|
51
|
-
```typescript
|
|
52
|
-
const tracker = new Tracker();
|
|
53
|
-
const payload = {
|
|
54
|
-
type: BeaconType.CLICK,
|
|
55
|
-
category: BeaconCategory.INTERACTION,
|
|
56
|
-
event: {
|
|
57
|
-
intellisuggestData: '37d5578e1d1646ac97701a063ba84777',
|
|
58
|
-
intellisuggestSignature: '5739a2596d3b4161b041ce1764ffa04d',
|
|
59
|
-
href: '/product123'
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
tracker.track.event(payload)
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Tracking Events with DomTargeter
|
|
66
|
-
As an alternative method for tracking events, the Tracker utilizes the `DomTargeter` to look for script tags on the current page. These script tags must have a specific `type` attribute and data contents for the tracking to be used. These tracking script blocks ensure tracking events are sent when using asynchronous script execution and must be on the page prior to the `DOMContentLoaded` event to be picked up by initial targeting. If the script blocks are added after this event, the `retarget` method must be invoked.
|
|
67
|
-
|
|
68
|
-
### `retarget` method
|
|
69
|
-
This method will call the `retarget` method on all `DomTargeters` set in the Tracker. Typically this would be used when new tracking script blocks have been added to the page after initial targeting.
|
|
70
|
-
|
|
71
|
-
### Shopper Login Script Block
|
|
72
|
-
|
|
73
|
-
```html
|
|
74
|
-
<script type="searchspring/track/shopper/login">
|
|
75
|
-
shopper = {
|
|
76
|
-
id: 'snapdev',
|
|
77
|
-
};
|
|
78
|
-
</script>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Product View Script Block
|
|
82
|
-
|
|
83
|
-
```html
|
|
84
|
-
<script type="searchspring/track/product/view">
|
|
85
|
-
item = {
|
|
86
|
-
uid: '123',
|
|
87
|
-
sku: 'product123',
|
|
88
|
-
childUid: '123_a',
|
|
89
|
-
childSku: 'product123_a',
|
|
90
|
-
};
|
|
91
|
-
</script>
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Cart View Script Block
|
|
95
|
-
|
|
96
|
-
```html
|
|
97
|
-
<script type="searchspring/track/cart/view">
|
|
98
|
-
items = [
|
|
99
|
-
{
|
|
100
|
-
uid: '123',
|
|
101
|
-
sku: 'product123',
|
|
102
|
-
childUid: '123_a',
|
|
103
|
-
childSku: 'product123_a',
|
|
104
|
-
qty: '1',
|
|
105
|
-
price: '9.99',
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
uid: '456',
|
|
109
|
-
sku: 'product456',
|
|
110
|
-
childUid: '456_a',
|
|
111
|
-
childSku: 'product456_a',
|
|
112
|
-
qty: '2',
|
|
113
|
-
price: '10.99',
|
|
114
|
-
},
|
|
115
|
-
];
|
|
116
|
-
</script>
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Order Transaction Script Block
|
|
120
|
-
|
|
121
|
-
```html
|
|
122
|
-
<script type="searchspring/track/order/transaction">
|
|
123
|
-
order = {
|
|
124
|
-
id: '123456',
|
|
125
|
-
total: '34.29',
|
|
126
|
-
transactionTotal: '31.97',
|
|
127
|
-
city: 'Los Angeles',
|
|
128
|
-
state: 'CA',
|
|
129
|
-
country: 'US',
|
|
130
|
-
};
|
|
131
|
-
items = [
|
|
132
|
-
{
|
|
133
|
-
uid: '123',
|
|
134
|
-
sku: 'product123',
|
|
135
|
-
childUid: '123_a',
|
|
136
|
-
childSku: 'product123_a',
|
|
137
|
-
qty: '1',
|
|
138
|
-
price: '9.99'
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
uid: '456',
|
|
142
|
-
sku: 'product456',
|
|
143
|
-
childUid: '456_a',
|
|
144
|
-
childSku: 'product456_a',
|
|
145
|
-
qty: '2',
|
|
146
|
-
price: '10.99'
|
|
147
|
-
},
|
|
148
|
-
];
|
|
149
|
-
</script>
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## `track` methods
|
|
153
|
-
The Tracker object is exposed to the browser's `window` via the first Snap Controller that has been instantiated. This will use the `siteId` that has been provided to the Snap Tracker instance of the respective Controller Services. The Tracker contains various tracking methods available on the `track` object within it.
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
window.searchspring.tracker.track
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Each tracking method expects a data object which contains different attributes depending on the method.
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
tracker.track.product.view({
|
|
163
|
-
uid: '123',
|
|
164
|
-
sku: 'product123',
|
|
165
|
-
childUid: '123_a',
|
|
166
|
-
childSku: 'product123_a',
|
|
167
|
-
});
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
If a bundle is using multiple Snap Controllers with different `siteId`, an optional `siteId` parameter can be specified to overwrite any event `siteId`
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
tracker.track.product.view({
|
|
174
|
-
uid: '123',
|
|
175
|
-
sku: 'product123',
|
|
176
|
-
childUid: '123_a',
|
|
177
|
-
childSku: 'product123_a',
|
|
178
|
-
}, 'abc123');
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Generic Event `track.event`
|
|
182
|
-
Creates and sends a generic beacon event. Parameter expects an Event Payload object.
|
|
183
|
-
If a `type` or `category` is not provided, a value of `'custom'` will be used.
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
const payload = {
|
|
187
|
-
type: BeaconType.CLICK,
|
|
188
|
-
category: BeaconCategory.INTERACTION,
|
|
189
|
-
event: {
|
|
190
|
-
intellisuggestData: '37d5578e1d1646ac97701a063ba84777',
|
|
191
|
-
intellisuggestSignature: '5739a2596d3b4161b041ce1764ffa04d',
|
|
192
|
-
href: '/product123'
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
tracker.track.event(payload)
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
#### Event Payload
|
|
199
|
-
|
|
200
|
-
A beacon event payload object provided to the `track.event` method may contain the following:
|
|
201
|
-
|
|
202
|
-
`type` - BeaconType enum value or custom event type value. If not specified, `'custom'` will be used.
|
|
203
|
-
|
|
204
|
-
`category` - BeaconCategory enum value or custom event type value. If not specified, `'custom'` will be used.
|
|
205
|
-
|
|
206
|
-
`event` - object containing event data
|
|
207
|
-
|
|
208
|
-
`context.website.trackingCode` - optional `context` object that will be merged with constructed context object. Can be used to specify a different `siteId` value.
|
|
209
|
-
|
|
210
|
-
`context.currency.code` - optional `context` object that will be merged with constructed context object. Can be used to specify a different `currency` value.
|
|
211
|
-
|
|
212
|
-
```typescript
|
|
213
|
-
const payload = {
|
|
214
|
-
type: BeaconType.CLICK,
|
|
215
|
-
category: BeaconCategory.INTERACTION,
|
|
216
|
-
event: {
|
|
217
|
-
intellisuggestData: '37d5578e1d1646ac97701a063ba84777',
|
|
218
|
-
intellisuggestSignature: '5739a2596d3b4161b041ce1764ffa04d',
|
|
219
|
-
href: '/product123',
|
|
220
|
-
},
|
|
221
|
-
context: {
|
|
222
|
-
website: {
|
|
223
|
-
trackingCode: 'abc123',
|
|
224
|
-
},
|
|
225
|
-
currency: {
|
|
226
|
-
code: 'USD',
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### Error Event `track.error`
|
|
234
|
-
Tracks error events. Parameter expects a payload with various properties derived from an `ErrorEvent` object.
|
|
235
|
-
Requires at least a `stack` or `message` to be provided.
|
|
236
|
-
|
|
237
|
-
```typescript
|
|
238
|
-
const handleErrorTracking = (event: ErrorEvent) :void => {
|
|
239
|
-
const { filename, colno, lineno, error: { stack }, message, timeStamp } = event;
|
|
240
|
-
const userAgent = navigator.userAgent;
|
|
241
|
-
const href = window.location.href;
|
|
242
|
-
|
|
243
|
-
const beaconPayload: TrackErrorEvent = {
|
|
244
|
-
userAgent,
|
|
245
|
-
href,
|
|
246
|
-
filename,
|
|
247
|
-
stack,
|
|
248
|
-
message,
|
|
249
|
-
colno,
|
|
250
|
-
lineno,
|
|
251
|
-
errortimestamp: timeStamp,
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
tracker.track.error(beaconPayload);
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
### Product Click `track.product.click`
|
|
259
|
-
Tracks product click events. It is reccomended to invoke on each product `onmousedown` event via the `result.track.click()` method. Various Snap controllers will expose these tracking events differently, see the controller documentation for details.
|
|
260
|
-
|
|
261
|
-
```jsx
|
|
262
|
-
searchController.store.results.map(result)=>{(
|
|
263
|
-
<a href={core.url} onMouseDown={(e)=>{searchController.track.product.click(e, result)}}>
|
|
264
|
-
)}
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
If invoking directly, the `intellisuggestData` and `intellisuggestSignature` values are returned from SearchSpring's Search API on each `result.attributes` object. An optional `href` value can also be provided.
|
|
268
|
-
|
|
269
|
-
```typescript
|
|
270
|
-
import { SearchController } from '@searchspring/snap-controller';
|
|
271
|
-
import { Tracker } from '@searchspring/snap-tracker';
|
|
272
|
-
const searchController = new SearchController({
|
|
273
|
-
...
|
|
274
|
-
tracker: new Tracker(),
|
|
275
|
-
...
|
|
276
|
-
}):
|
|
277
|
-
|
|
278
|
-
tracker.track.product.click({
|
|
279
|
-
intellisuggestData: '37d5578e1d1646ac97701a063ba84777',
|
|
280
|
-
intellisuggestSignature: '5739a2596d3b4161b041ce1764ffa04d',
|
|
281
|
-
href: '/product123',
|
|
282
|
-
});
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
### Product View `track.product.view`
|
|
286
|
-
Tracks product page views. Should be invoked from a product detail page. A `uid` and/or `sku` and/or `childUid` and/or `childSku` are required.
|
|
287
|
-
|
|
288
|
-
```typescript
|
|
289
|
-
tracker.track.product.view({
|
|
290
|
-
ud: '123',
|
|
291
|
-
sku: 'product123',
|
|
292
|
-
childUid: '123_a',
|
|
293
|
-
childSku: 'product123_a',
|
|
294
|
-
});
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### Shopper Login `track.shopper.login`
|
|
298
|
-
Tracks user login and sets `context.shopperId` value. Should be invoked when a user has logged into their account.
|
|
299
|
-
|
|
300
|
-
```typescript
|
|
301
|
-
const shopperId = "snapdev"
|
|
302
|
-
tracker.track.shopper.login({
|
|
303
|
-
id: shopperId
|
|
304
|
-
});
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### Cart View `track.cart.view`
|
|
308
|
-
Tracks cart contents. Should be invoked from a cart page. Each item object must contain a `qty`, `price`, (`uid` and/or `sku` and/or `childUid` and/or `childSku`)
|
|
309
|
-
|
|
310
|
-
```typescript
|
|
311
|
-
tracker.track.cart.view({
|
|
312
|
-
items: [
|
|
313
|
-
{
|
|
314
|
-
uid: '123',
|
|
315
|
-
sku: 'product123',
|
|
316
|
-
childUid: '123_a',
|
|
317
|
-
childSku: 'product123_a',
|
|
318
|
-
qty: '1',
|
|
319
|
-
price: '9.99',
|
|
320
|
-
},
|
|
321
|
-
{
|
|
322
|
-
uid: '456',
|
|
323
|
-
sku: 'product456',
|
|
324
|
-
childUid: '456_a',
|
|
325
|
-
childSku: 'product456_a',
|
|
326
|
-
qty: '2',
|
|
327
|
-
price: '10.99',
|
|
328
|
-
},
|
|
329
|
-
]
|
|
330
|
-
});
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### Order Transaction `track.order.transaction`
|
|
334
|
-
Tracks order transaction. Should be invoked from an order confirmation page. Expects an object with the following:
|
|
335
|
-
|
|
336
|
-
`order` - (optional) object containing the following
|
|
337
|
-
|
|
338
|
-
`order.id` - (optional) order id
|
|
339
|
-
|
|
340
|
-
`order.total` - (optional) transaction total of all items after tax and shipping
|
|
341
|
-
|
|
342
|
-
`order.transactionTotal` - (optional) transaction total of all items before tax and shipping
|
|
343
|
-
|
|
344
|
-
`order.city` - (optional) city name
|
|
345
58
|
|
|
346
|
-
`
|
|
59
|
+
## `events` methods
|
|
60
|
+
See [beacon.js Tracking Events](https://github.com/searchspring/beacon.js) for a list of available events.
|
|
347
61
|
|
|
348
|
-
`order.country` - (optional) 2 digit country abbreviation (ie. 'US', 'CA', 'MX', 'PL', 'JP')
|
|
349
|
-
|
|
350
|
-
`order.items` - required array of items - same object provided to `track.cart.view` event
|
|
351
|
-
|
|
352
|
-
```typescript
|
|
353
|
-
tracker.track.order.transaction({
|
|
354
|
-
order: {
|
|
355
|
-
id: '123456',
|
|
356
|
-
total: '34.29',
|
|
357
|
-
transactionTotal: '31.97',
|
|
358
|
-
city: 'Los Angeles',
|
|
359
|
-
state: 'CA',
|
|
360
|
-
country: 'US',
|
|
361
|
-
},
|
|
362
|
-
items: [
|
|
363
|
-
{
|
|
364
|
-
uid: '123',
|
|
365
|
-
sku: 'product123',
|
|
366
|
-
childUid: '123_a',
|
|
367
|
-
childSku: 'product123_a',
|
|
368
|
-
qty: '1',
|
|
369
|
-
price: '9.99'
|
|
370
|
-
},
|
|
371
|
-
{
|
|
372
|
-
uid: '456',
|
|
373
|
-
sku: 'product456',
|
|
374
|
-
childUid: '456_a',
|
|
375
|
-
childSku: 'product456_a',
|
|
376
|
-
qty: '2',
|
|
377
|
-
price: '10.99'
|
|
378
|
-
},
|
|
379
|
-
]
|
|
380
|
-
});
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
## Tracker properties
|
|
384
|
-
|
|
385
|
-
### `globals` property
|
|
386
|
-
When constructing an instance of `Tracker`, a globals object is required to be constructed. This object contains a `siteId` key and value. An optional `currency` object with a `code` property containing a string can be provided.
|
|
387
|
-
|
|
388
|
-
```typescript
|
|
389
|
-
const globals = { siteId: 'abc123', currency: { code: 'EUR' } };
|
|
390
|
-
const tracker = new Tracker(globals);
|
|
391
|
-
console.log(tracker.globals === globals) // true
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
### `localStorage` property
|
|
395
|
-
A reference to the StorageStore object for accessing Tracker local storage.
|
|
396
|
-
|
|
397
|
-
```typescript
|
|
398
|
-
const tracker = new Tracker();
|
|
399
|
-
tracker.localStorage.set('key', 'value')
|
|
400
|
-
tracker.localStorage.get('key') // 'value'
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
### `context` property
|
|
405
|
-
The `context` property is generated at the time of instantiating Tracker. It is part of each event payload and provides context of the event.
|
|
406
|
-
|
|
407
|
-
`userId` - unique ID to identify the user, persisted in a cookie/local storage fallback
|
|
408
|
-
|
|
409
|
-
`pageLoadId` - unique ID generated at the time of instantiating Tracker
|
|
410
|
-
|
|
411
|
-
`sessionId` - unique ID generated at the start of a new browser session, persisted in session storage/cookie fallback
|
|
412
|
-
|
|
413
|
-
`shopperId` - unique ID provided set via the SearchController `SearchController.tracker.track.shopper.login` event and then persisted in a cookie
|
|
414
|
-
|
|
415
|
-
`website.trackingCode` - the `siteId` specified in the globals object
|
|
416
|
-
|
|
417
|
-
`currency.code` - the optional `currency` specified in the globals object
|
|
418
|
-
|
|
419
|
-
```typescript
|
|
420
|
-
context: {
|
|
421
|
-
userId: '0560d7e7-148a-4b1d-b12c-924f164d3d00',
|
|
422
|
-
pageLoadId: 'cfb75606-c15b-4f25-a711-9de2c5d22660',
|
|
423
|
-
sessionId: 'f4b25c96-9ca1-4ac6-ad04-f5ce933f8b61',
|
|
424
|
-
shopperId: 'shopper0001',
|
|
425
|
-
website: {
|
|
426
|
-
trackingCode: 'abc123',
|
|
427
|
-
},
|
|
428
|
-
currency: {
|
|
429
|
-
code: 'USD',
|
|
430
|
-
},
|
|
431
|
-
}
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
### `isSending` property
|
|
435
|
-
The `isSending` property contains the return value from `setTimeout` and when defined, signifys that an event is being sent to the beacon endpoint. If subsequent events are invoked and `isSending` is still defined, the incoming event will be added to the event queue to be sent at a later time.
|
|
436
|
-
|
|
437
|
-
### `namespace` property
|
|
438
|
-
The `namespace` property contains the Tracker namespace. Invoking this method is only required if a bundle contains multiple Tracker instances.
|
|
439
|
-
|
|
440
|
-
### `track` property
|
|
441
|
-
The `track` property contains various tracking events. See `track` methods section above.
|
|
442
|
-
|
|
443
|
-
### `setCurrency` method
|
|
444
|
-
Sets the currency code on the tracker context.
|
|
445
|
-
|
|
446
|
-
```typescript
|
|
447
|
-
const tracker = new Tracker();
|
|
448
|
-
|
|
449
|
-
tracker.setCurrency({ code: 'EUR' })
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
### `getUserId` method
|
|
454
|
-
Returns an object containing the `userId` stored in the `ssUserId` cookie (with a fallback to localstorage.) If key doesn't exist, a new ID will be generated, saved to cookie/localstorage, and returned.
|
|
455
|
-
|
|
456
|
-
```typescript
|
|
457
|
-
const tracker = new Tracker();
|
|
458
|
-
|
|
459
|
-
console.log(tracker.getUserId())
|
|
460
|
-
// { userId: '0560d7e7-148a-4b1d-b12c-924f164d3d00' }
|
|
461
|
-
```
|
|
462
|
-
|
|
463
|
-
### `getSessionId` method
|
|
464
|
-
Returns an object containing the `sessionId` stored in the `ssSessionIdNamespace` session storage (with a fallback to cookies.) If key doesn't exist, a new ID will be generated, saved to session storage/cookie, and returned.
|
|
465
|
-
|
|
466
|
-
```typescript
|
|
467
|
-
const tracker = new Tracker();
|
|
468
|
-
|
|
469
|
-
console.log(tracker.getSessionId())
|
|
470
|
-
// { sessionId: 'f4b25c96-9ca1-4ac6-ad04-f5ce933f8b61' }
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
### `getShopperId` method
|
|
474
|
-
Returns an object containing the `shopperId` stored in the `ssShopperId` cookie. This value is set via the SearchController `SearchController.tracker.track.shopper.login` event
|
|
475
|
-
|
|
476
|
-
```typescript
|
|
477
|
-
const tracker = new Tracker();
|
|
478
|
-
|
|
479
|
-
console.log(tracker.getShopperId())
|
|
480
|
-
// { shopperId: 'shopper0001' }
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
### `cookies` property
|
|
484
|
-
The `cookies` property provides access to the `cart` and `viewed` tracking cookies.
|
|
485
|
-
|
|
486
|
-
#### `cookies.cart.get` method
|
|
487
|
-
Returns an array of strings containing the `uids` and/or `skus` of each item last registered as being in the shopping cart. This value is stored in the `ssCartProducts` cookie and is set via the calls to the `tracker.track.cart.view` event.
|
|
488
|
-
|
|
489
|
-
```typescript
|
|
490
|
-
const tracker = new Tracker();
|
|
491
|
-
|
|
492
|
-
console.log(tracker.cookies.cart.get())
|
|
493
|
-
// ['sku1', 'sku2']
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
#### `cookies.cart.add` method
|
|
497
|
-
Provides a means of adding cart products to the `ssCartProducts` cookie.
|
|
498
|
-
|
|
499
|
-
```typescript
|
|
500
|
-
const tracker = new Tracker();
|
|
501
|
-
|
|
502
|
-
console.log(tracker.cookies.cart.get());
|
|
503
|
-
// ['sku1', 'sku2']
|
|
504
|
-
|
|
505
|
-
console.log(tracker.cookies.cart.add(['sku3']));
|
|
506
|
-
// ['sku1', 'sku2', 'sku3']
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
#### `cookies.cart.remove` method
|
|
510
|
-
Provides a means for removing `skus` from the `ssCartProducts` cookie.
|
|
511
|
-
|
|
512
|
-
```typescript
|
|
513
|
-
const tracker = new Tracker();
|
|
514
|
-
|
|
515
|
-
console.log(tracker.cookies.cart.get());
|
|
516
|
-
// ['sku1', 'sku2']
|
|
517
|
-
|
|
518
|
-
tracker.cookies.cart.remove(['sku1']);
|
|
519
|
-
// ['sku2']
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
#### `cookies.cart.set` method
|
|
523
|
-
Provides a means of setting the `ssCartProducts` cookie via an array of product `skus`.
|
|
524
|
-
|
|
525
|
-
```typescript
|
|
526
|
-
const tracker = new Tracker();
|
|
527
|
-
|
|
528
|
-
tracker.cookies.cart.set(['sku1', 'sku2']);
|
|
529
|
-
// ['sku1', 'sku2']
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
#### `cookies.cart.clear` method
|
|
533
|
-
Empties the `ssCartProducts` cookie.
|
|
534
|
-
|
|
535
|
-
```typescript
|
|
536
|
-
const tracker = new Tracker();
|
|
537
|
-
|
|
538
|
-
tracker.cookies.cart.clear();
|
|
539
|
-
```
|
|
540
|
-
|
|
541
|
-
#### `cookies.viewed.get` method
|
|
542
|
-
Returns an array of strings containing the `uids` and/or `skus` of items which have been viewed. This value is stored in the `ssViewedProducts` cookie and is set via the calls to the `tracker.track.product.view` event.
|
|
543
|
-
|
|
544
|
-
```typescript
|
|
545
|
-
const tracker = new Tracker();
|
|
546
|
-
|
|
547
|
-
console.log(tracker.cookies.viewed.get());
|
|
548
|
-
// ['sku1', 'sku2']
|
|
549
|
-
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tracker.d.ts","sourceRoot":"","sources":["../../src/Tracker.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Tracker.d.ts","sourceRoot":"","sources":["../../src/Tracker.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,KAAK,EAA6C,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpG,OAAO,EACN,cAAc,EACd,YAAY,EAKZ,aAAa,EAEb,MAAM,SAAS,CAAC;AAUjB,qBAAa,OAAQ,SAAQ,MAAM;IAClC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,UAAU,CAAkB;IAE7B,MAAM,EAAE,aAAa,GAAG,YAAY,CAAC;IAC5C,OAAO,CAAC,SAAS,CAAqB;gBAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,YAAY;IAgPnE,UAAU,IAAI,cAAc;IAI5B,QAAQ,IAAI,IAAI;IAMvB,KAAK,EAAE,YAAY,CAkGjB;IAEF,OAAO;;uBAEI,MAAM,EAAE;yBAIJ,MAAM,EAAE,KAAG,IAAI;yBAKf,MAAM,EAAE,KAAG,IAAI;4BAMZ,MAAM,EAAE,KAAG,IAAI;;;;uBAWtB,MAAM,EAAE;;MAKjB;CACF"}
|