@surfside/surfside-events 2.1.0 → 3.6.1

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.
@@ -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
  *
package/dist/index.umd.js CHANGED
@@ -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.1 (https://surfside.io)
3
3
  * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
4
4
  */
5
5
 
@@ -73,7 +73,7 @@
73
73
  }
74
74
 
75
75
  /*!
76
- * Core functionality for Surfside JavaScript trackers v3.4.0 (https://www.surfside.io)
76
+ * Core functionality for Surfside JavaScript trackers v2.0.0 (https://www.surfside.io)
77
77
  * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
78
78
  */
79
79
 
@@ -300,7 +300,7 @@
300
300
  }
301
301
 
302
302
  /*!
303
- * Core functionality for Surfside Digital trackers v3.4.0 ()
303
+ * Core functionality for Surfside Digital trackers v2.0.0 ()
304
304
  * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
305
305
  */
306
306
  /**
@@ -385,6 +385,7 @@
385
385
  */
386
386
  var _trackers = {};
387
387
  var _context = {};
388
+ var _lastLocationByTracker = {};
388
389
  function SurfsideCommercePlugin() {
389
390
  return {
390
391
  activateBrowserPlugin: function (tracker) {
@@ -560,6 +561,7 @@
560
561
  * @param trackers - The tracker identifiers which the context will be stored against
561
562
  */
562
563
  function segment(context, trackers) {
564
+ var _a;
563
565
  if (context === void 0) { context = {}; }
564
566
  if (trackers === void 0) { trackers = Object.keys(_trackers); }
565
567
  var segmentId = context.segmentId, segmentVal = context.segmentVal;
@@ -567,7 +569,7 @@
567
569
  segmentId: segmentId,
568
570
  segmentVal: segmentVal
569
571
  };
570
- if (window.surf.surfSegment !== undefined) {
572
+ if (((_a = window.surf) === null || _a === void 0 ? void 0 : _a.surfSegment) !== undefined) {
571
573
  removeSegment(window.surf.surfSegment);
572
574
  }
573
575
  dispatchToTrackersInCollection(trackers, _trackers, function (t) {
@@ -618,10 +620,30 @@
618
620
  if (context === void 0) { context = {}; }
619
621
  if (trackers === void 0) { trackers = Object.keys(_trackers); }
620
622
  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;
621
- if (window.surf.currentLocation !== undefined) {
622
- removeLocation(window.surf.currentLocation);
623
- }
624
623
  dispatchToTrackersInCollection(trackers, _trackers, function (t) {
624
+ var previous = _lastLocationByTracker[t.id];
625
+ if (previous) {
626
+ t.core.removeGlobalContexts([
627
+ {
628
+ schema: 'iglu:io.surfside.local-business/location/jsonschema/1-0-0',
629
+ data: {
630
+ id: previous.id,
631
+ latitude: previous.latitude,
632
+ longitude: previous.longitude,
633
+ country_code: previous.country_code,
634
+ zip: previous.zip,
635
+ state_label: previous.state_label,
636
+ state: previous.state,
637
+ city: previous.city,
638
+ street: previous.street,
639
+ name: previous.name,
640
+ parent: previous.parent,
641
+ type: previous.type,
642
+ category: previous.category
643
+ }
644
+ },
645
+ ]);
646
+ }
625
647
  _context[t.id].length = 0;
626
648
  t.core.addGlobalContexts([
627
649
  {
@@ -643,8 +665,22 @@
643
665
  }
644
666
  },
645
667
  ]);
668
+ _lastLocationByTracker[t.id] = {
669
+ id: id,
670
+ latitude: latitude,
671
+ longitude: longitude,
672
+ country_code: country_code,
673
+ zip: zip,
674
+ state_label: state_label,
675
+ state: state,
676
+ city: city,
677
+ street: street,
678
+ name: name,
679
+ parent: parent,
680
+ type: type,
681
+ category: category
682
+ };
646
683
  });
647
- window.surf.currentLocation = context;
648
684
  }
649
685
  /**
650
686
  * Removes a Surfside Local Business Location Context
@@ -655,29 +691,38 @@
655
691
  function removeLocation(context, trackers) {
656
692
  if (context === void 0) { context = {}; }
657
693
  if (trackers === void 0) { trackers = Object.keys(_trackers); }
658
- 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;
659
694
  dispatchToTrackersInCollection(trackers, _trackers, function (t) {
695
+ var toRemove = Object.keys(context).length ? context : _lastLocationByTracker[t.id];
696
+ if (!toRemove)
697
+ return;
660
698
  _context[t.id].length = 0;
661
699
  t.core.removeGlobalContexts([
662
700
  {
663
701
  schema: 'iglu:io.surfside.local-business/location/jsonschema/1-0-0',
664
702
  data: {
665
- id: id,
666
- latitude: latitude,
667
- longitude: longitude,
668
- country_code: country_code,
669
- zip: zip,
670
- state_label: state_label,
671
- state: state,
672
- city: city,
673
- street: street,
674
- name: name,
675
- parent: parent,
676
- type: type,
677
- category: category
703
+ id: toRemove.id,
704
+ latitude: toRemove.latitude,
705
+ longitude: toRemove.longitude,
706
+ country_code: toRemove.country_code,
707
+ zip: toRemove.zip,
708
+ state_label: toRemove.state_label,
709
+ state: toRemove.state,
710
+ city: toRemove.city,
711
+ street: toRemove.street,
712
+ name: toRemove.name,
713
+ parent: toRemove.parent,
714
+ type: toRemove.type,
715
+ category: toRemove.category
678
716
  }
679
717
  },
680
718
  ]);
719
+ if (_lastLocationByTracker[t.id]) {
720
+ var last = _lastLocationByTracker[t.id];
721
+ var same = (last === null || last === void 0 ? void 0 : last.id) === toRemove.id;
722
+ if (same) {
723
+ _lastLocationByTracker[t.id] = undefined;
724
+ }
725
+ }
681
726
  });
682
727
  }
683
728
  /**