@surfside/surfside-events 3.6.0 → 3.6.2

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 CHANGED
@@ -18,10 +18,10 @@ npm install @surfside/surfside-events
18
18
 
19
19
  ## Usage
20
20
 
21
- Use the available functions from this package to track to all trackers which have been initialized with this plugin:
21
+ Use the available functions from this package to track to all trackers which have been initialized with the SurfsideEvent plugin:
22
22
 
23
23
  ```js
24
- import { addProduct, addPromo, setAction } from '@surfside/surfside-events';
24
+ import { SurfsideEvent, addProduct, addPromo, setCommerceAction } from '@surfside/surfside-events';
25
25
 
26
26
  addProduct({
27
27
  id: 'P12345',
@@ -40,6 +40,6 @@ addPromo({
40
40
  position: 'banner_slot1',
41
41
  });
42
42
 
43
- setAction({ action: 'purchase' });
43
+ setCommerceAction({ action: 'purchase' });
44
44
 
45
45
  ```
@@ -152,6 +152,11 @@ interface sourceContext {
152
152
  * @param trackers - The tracker identifiers which the context will be stored against
153
153
  */
154
154
  declare function source(context?: sourceContext, trackers?: Array<string>): void;
155
+ declare global {
156
+ interface Window {
157
+ surf: any;
158
+ }
159
+ }
155
160
  /**
156
161
  * A Surfside Segment Context
157
162
  */
@@ -206,11 +211,6 @@ interface localBusinessLocationContext {
206
211
  /** The Location Category */
207
212
  category?: string;
208
213
  }
209
- declare global {
210
- interface Window {
211
- surf: any;
212
- }
213
- }
214
214
  /**
215
215
  * Adds a Surfside Local Business Location Context
216
216
  *
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Surfside Digital Analytics > Custom Events v2.1.0 (https://surfside.io)
2
+ * Surfside Digital Analytics > Custom Events v3.6.2 (https://surfside.io)
3
3
  * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
4
4
  */
5
5
 
@@ -38,6 +38,7 @@ import { buildSelfDescribingEvent } from '@surfside/digital-core';
38
38
  */
39
39
  var _trackers = {};
40
40
  var _context = {};
41
+ var _lastLocationByTracker = {};
41
42
  function SurfsideCommercePlugin() {
42
43
  return {
43
44
  activateBrowserPlugin: function (tracker) {
@@ -213,6 +214,7 @@ function source(context, trackers) {
213
214
  * @param trackers - The tracker identifiers which the context will be stored against
214
215
  */
215
216
  function segment(context, trackers) {
217
+ var _a;
216
218
  if (context === void 0) { context = {}; }
217
219
  if (trackers === void 0) { trackers = Object.keys(_trackers); }
218
220
  var segmentId = context.segmentId, segmentVal = context.segmentVal;
@@ -220,7 +222,7 @@ function segment(context, trackers) {
220
222
  segmentId: segmentId,
221
223
  segmentVal: segmentVal
222
224
  };
223
- if (window.surf.surfSegment !== undefined) {
225
+ if (((_a = window.surf) === null || _a === void 0 ? void 0 : _a.surfSegment) !== undefined) {
224
226
  removeSegment(window.surf.surfSegment);
225
227
  }
226
228
  dispatchToTrackersInCollection(trackers, _trackers, function (t) {
@@ -271,10 +273,30 @@ function setLocation(context, trackers) {
271
273
  if (context === void 0) { context = {}; }
272
274
  if (trackers === void 0) { trackers = Object.keys(_trackers); }
273
275
  var id = context.id, latitude = context.latitude, longitude = context.longitude, country_code = context.country_code, zip = context.zip, state_label = context.state_label, state = context.state, city = context.city, street = context.street, name = context.name, parent = context.parent, type = context.type, category = context.category;
274
- if (window.surf.currentLocation !== undefined) {
275
- removeLocation(window.surf.currentLocation);
276
- }
277
276
  dispatchToTrackersInCollection(trackers, _trackers, function (t) {
277
+ var previous = _lastLocationByTracker[t.id];
278
+ if (previous) {
279
+ t.core.removeGlobalContexts([
280
+ {
281
+ schema: 'iglu:io.surfside.local-business/location/jsonschema/1-0-0',
282
+ data: {
283
+ id: previous.id,
284
+ latitude: previous.latitude,
285
+ longitude: previous.longitude,
286
+ country_code: previous.country_code,
287
+ zip: previous.zip,
288
+ state_label: previous.state_label,
289
+ state: previous.state,
290
+ city: previous.city,
291
+ street: previous.street,
292
+ name: previous.name,
293
+ parent: previous.parent,
294
+ type: previous.type,
295
+ category: previous.category
296
+ }
297
+ },
298
+ ]);
299
+ }
278
300
  _context[t.id].length = 0;
279
301
  t.core.addGlobalContexts([
280
302
  {
@@ -296,8 +318,22 @@ function setLocation(context, trackers) {
296
318
  }
297
319
  },
298
320
  ]);
321
+ _lastLocationByTracker[t.id] = {
322
+ id: id,
323
+ latitude: latitude,
324
+ longitude: longitude,
325
+ country_code: country_code,
326
+ zip: zip,
327
+ state_label: state_label,
328
+ state: state,
329
+ city: city,
330
+ street: street,
331
+ name: name,
332
+ parent: parent,
333
+ type: type,
334
+ category: category
335
+ };
299
336
  });
300
- window.surf.currentLocation = context;
301
337
  }
302
338
  /**
303
339
  * Removes a Surfside Local Business Location Context
@@ -308,29 +344,38 @@ function setLocation(context, trackers) {
308
344
  function removeLocation(context, trackers) {
309
345
  if (context === void 0) { context = {}; }
310
346
  if (trackers === void 0) { trackers = Object.keys(_trackers); }
311
- var id = context.id, latitude = context.latitude, longitude = context.longitude, country_code = context.country_code, zip = context.zip, state_label = context.state_label, state = context.state, city = context.city, street = context.street, name = context.name, parent = context.parent, type = context.type, category = context.category;
312
347
  dispatchToTrackersInCollection(trackers, _trackers, function (t) {
348
+ var toRemove = Object.keys(context).length ? context : _lastLocationByTracker[t.id];
349
+ if (!toRemove)
350
+ return;
313
351
  _context[t.id].length = 0;
314
352
  t.core.removeGlobalContexts([
315
353
  {
316
354
  schema: 'iglu:io.surfside.local-business/location/jsonschema/1-0-0',
317
355
  data: {
318
- id: id,
319
- latitude: latitude,
320
- longitude: longitude,
321
- country_code: country_code,
322
- zip: zip,
323
- state_label: state_label,
324
- state: state,
325
- city: city,
326
- street: street,
327
- name: name,
328
- parent: parent,
329
- type: type,
330
- category: category
356
+ id: toRemove.id,
357
+ latitude: toRemove.latitude,
358
+ longitude: toRemove.longitude,
359
+ country_code: toRemove.country_code,
360
+ zip: toRemove.zip,
361
+ state_label: toRemove.state_label,
362
+ state: toRemove.state,
363
+ city: toRemove.city,
364
+ street: toRemove.street,
365
+ name: toRemove.name,
366
+ parent: toRemove.parent,
367
+ type: toRemove.type,
368
+ category: toRemove.category
331
369
  }
332
370
  },
333
371
  ]);
372
+ if (_lastLocationByTracker[t.id]) {
373
+ var last = _lastLocationByTracker[t.id];
374
+ var same = (last === null || last === void 0 ? void 0 : last.id) === toRemove.id;
375
+ if (same) {
376
+ _lastLocationByTracker[t.id] = undefined;
377
+ }
378
+ }
334
379
  });
335
380
  }
336
381
  /**
@@ -403,7 +448,7 @@ function setSurfId(context, trackers) {
403
448
  _context[t.id].length = 0;
404
449
  t.core.addGlobalContexts([
405
450
  {
406
- schema: 'iglu:io.surfside/uid2_context/jsonschema/1-0-0',
451
+ schema: 'iglu:io.surfside/uid_context/jsonschema/1-0-0',
407
452
  data: {
408
453
  uid2: token
409
454
  }