@surfside/surfside-events 1.0.0 → 2.0.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/dist/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Surfside Digital Analytics v0.0.1 (https://surfside.io)
2
+ * Surfside Digital Analytics > Custom Events v2.0.0 (https://surfside.io)
3
3
  * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
4
4
  */
5
5
 
@@ -24,6 +24,44 @@
24
24
  PERFORMANCE OF THIS SOFTWARE.
25
25
  ***************************************************************************** */
26
26
 
27
+ function __awaiter(thisArg, _arguments, P, generator) {
28
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
+ return new (P || (P = Promise))(function (resolve, reject) {
30
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34
+ });
35
+ }
36
+
37
+ function __generator(thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ }
64
+
27
65
  function __spreadArray(to, from, pack) {
28
66
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
29
67
  if (ar || !(i in from)) {
@@ -35,7 +73,7 @@
35
73
  }
36
74
 
37
75
  /*!
38
- * Core functionality for Surfside JavaScript trackers v0.0.1 (https://www.surfside.io)
76
+ * Core functionality for Surfside JavaScript trackers v3.4.0 (https://www.surfside.io)
39
77
  * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
40
78
  */
41
79
 
@@ -248,7 +286,7 @@
248
286
  * and a data object which conforms to the supplied schema
249
287
  *
250
288
  * @param event - Contains the properties and schema location for the event
251
- * @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
289
+ * @returns PayloadBuilder to be sent to {@link @surfside/digital-core#TrackerCore.track}
252
290
  */
253
291
  function buildSelfDescribingEvent(event) {
254
292
  var _a = event.event, schema = _a.schema, data = _a.data, pb = payloadBuilder();
@@ -262,7 +300,7 @@
262
300
  }
263
301
 
264
302
  /*!
265
- * Core functionality for Surfside Digital trackers v0.0.1 ()
303
+ * Core functionality for Surfside Digital trackers v3.4.0 ()
266
304
  * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
267
305
  */
268
306
  /**
@@ -525,6 +563,13 @@
525
563
  if (context === void 0) { context = {}; }
526
564
  if (trackers === void 0) { trackers = Object.keys(_trackers); }
527
565
  var segmentId = context.segmentId, segmentVal = context.segmentVal;
566
+ var currentSegment = {
567
+ segmentId: segmentId,
568
+ segmentVal: segmentVal
569
+ };
570
+ if (window.surf.surfSegment !== undefined) {
571
+ removeSegment(window.surf.surfSegment);
572
+ }
528
573
  dispatchToTrackersInCollection(trackers, _trackers, function (t) {
529
574
  _context[t.id].length = 0;
530
575
  t.core.addGlobalContexts([
@@ -537,6 +582,103 @@
537
582
  },
538
583
  ]);
539
584
  });
585
+ window.surf.surfSegment = currentSegment;
586
+ }
587
+ /**
588
+ * Removes a Surfside Segment Context
589
+ *
590
+ * @param context - The context to be stored
591
+ * @param trackers - The tracker identifiers which the context will be stored against
592
+ */
593
+ function removeSegment(context, trackers) {
594
+ if (context === void 0) { context = {}; }
595
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
596
+ var segmentId = context.segmentId, segmentVal = context.segmentVal;
597
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
598
+ _context[t.id].length = 0;
599
+ t.core.removeGlobalContexts([
600
+ {
601
+ schema: 'iglu:io.surfside/segment/jsonschema/1-0-0',
602
+ data: {
603
+ segmentId: segmentId,
604
+ segmentVal: segmentVal
605
+ }
606
+ },
607
+ ]);
608
+ });
609
+ }
610
+ /**
611
+ * Adds a Surfside Local Business Location Context
612
+ *
613
+ * @param context - The context to be stored
614
+ * @param trackers - The tracker identifiers which the context will be stored against
615
+ */
616
+ //check if location is already set, so check if window surf exists, if it's the same, if it isn't remove and update
617
+ function setLocation(context, trackers) {
618
+ if (context === void 0) { context = {}; }
619
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
620
+ 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
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
625
+ _context[t.id].length = 0;
626
+ t.core.addGlobalContexts([
627
+ {
628
+ schema: 'iglu:io.surfside.local-business/location/jsonschema/1-0-0',
629
+ data: {
630
+ id: id,
631
+ latitude: latitude,
632
+ longitude: longitude,
633
+ country_code: country_code,
634
+ zip: zip,
635
+ state_label: state_label,
636
+ state: state,
637
+ city: city,
638
+ street: street,
639
+ name: name,
640
+ parent: parent,
641
+ type: type,
642
+ category: category
643
+ }
644
+ },
645
+ ]);
646
+ });
647
+ window.surf.currentLocation = context;
648
+ }
649
+ /**
650
+ * Removes a Surfside Local Business Location Context
651
+ *
652
+ * @param context - The context to be stored
653
+ * @param trackers - The tracker identifiers which the context will be stored against
654
+ */
655
+ function removeLocation(context, trackers) {
656
+ if (context === void 0) { context = {}; }
657
+ 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
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
660
+ _context[t.id].length = 0;
661
+ t.core.removeGlobalContexts([
662
+ {
663
+ schema: 'iglu:io.surfside.local-business/location/jsonschema/1-0-0',
664
+ 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
678
+ }
679
+ },
680
+ ]);
681
+ });
540
682
  }
541
683
  /**
542
684
  * Adds a Surfside User Context
@@ -547,7 +689,7 @@
547
689
  function setUser(context, trackers) {
548
690
  if (context === void 0) { context = {}; }
549
691
  if (trackers === void 0) { trackers = Object.keys(_trackers); }
550
- var address = context.address, age = context.age, company = context.company, createdAt = context.createdAt, dateOfBirth = context.dateOfBirth, email = context.email, firstName = context.firstName, gender = context.gender, userId = context.userId, lastName = context.lastName;
692
+ var address = context.address, age = context.age, company = context.company, createdAt = context.createdAt, dateOfBirth = context.dateOfBirth, email = context.email, firstName = context.firstName, gender = context.gender, userId = context.userId, lastName = context.lastName, phone = context.phone;
551
693
  trackers.forEach(function (trackerId) {
552
694
  if (_context[trackerId]) {
553
695
  _context[trackerId].push({
@@ -562,12 +704,64 @@
562
704
  firstName: firstName,
563
705
  gender: gender,
564
706
  userId: userId,
565
- lastName: lastName
707
+ lastName: lastName,
708
+ phone: phone
566
709
  }
567
710
  });
568
711
  }
569
712
  });
570
713
  }
714
+ function setSurfId(context, trackers) {
715
+ var _this = this;
716
+ if (context === void 0) { context = {}; }
717
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
718
+ var query;
719
+ if (context.email) {
720
+ query = "email=".concat(context.email);
721
+ }
722
+ else if (context.phone) {
723
+ query = "phone=".concat(context.phone);
724
+ }
725
+ else {
726
+ return;
727
+ }
728
+ fetch("//i.surfside.io/id?".concat(query)).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
729
+ var data, status, body, token;
730
+ var _a;
731
+ return __generator(this, function (_b) {
732
+ switch (_b.label) {
733
+ case 0: return [4 /*yield*/, response.json()];
734
+ case 1:
735
+ data = _b.sent();
736
+ status = data === null || data === void 0 ? void 0 : data.status;
737
+ if (status !== 'success') {
738
+ return [2 /*return*/];
739
+ }
740
+ body = data === null || data === void 0 ? void 0 : data.body;
741
+ if (!body || body.length === 0) {
742
+ return [2 /*return*/];
743
+ }
744
+ token = (_a = body[0]) === null || _a === void 0 ? void 0 : _a.advertisingToken;
745
+ if (!token) {
746
+ return [2 /*return*/];
747
+ }
748
+ localStorage.setItem('surf_uid2', token);
749
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
750
+ _context[t.id].length = 0;
751
+ t.core.addGlobalContexts([
752
+ {
753
+ schema: 'iglu:io.surfside/uid2_context/jsonschema/1-0-0',
754
+ data: {
755
+ uid2: token
756
+ }
757
+ },
758
+ ]);
759
+ });
760
+ return [2 /*return*/];
761
+ }
762
+ });
763
+ }); });
764
+ }
571
765
  /**
572
766
  * Adds a Surfside Context
573
767
  *
@@ -603,15 +797,258 @@
603
797
  }
604
798
  });
605
799
  }
800
+ function auctionInit(e, trackers) {
801
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
802
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
803
+ var combinedContexts = _context[t.id].concat(e.context || []);
804
+ _context[t.id].length = 0;
805
+ t.core.track(buildSelfDescribingEvent({
806
+ event: {
807
+ schema: 'iglu:io.surfside.advertising/auction_init/jsonschema/1-0-0',
808
+ data: {
809
+ auctionId: e.auctionId,
810
+ timestamp: e.timestamp,
811
+ auctionStatus: e.auctionStatus,
812
+ adUnits: e.adUnits.map(function (unit) {
813
+ return {
814
+ requestId: unit.requestId,
815
+ mediaTypes: unit.mediaTypes,
816
+ bids: unit.bids.map(function (bid) {
817
+ return {
818
+ params: bid.params,
819
+ user: bid.user
820
+ };
821
+ }),
822
+ timeout: unit.timeout,
823
+ sizes: unit.sizes,
824
+ transactionId: unit.transactionId
825
+ };
826
+ }),
827
+ bidderRequests: e.bidderRequests.map(function (req) {
828
+ return {
829
+ bidderRequestId: req.bidderRequestId,
830
+ bids: req.bids.map(function (bid) {
831
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
832
+ return {
833
+ ortb2: {
834
+ site: {
835
+ page: (_b = (_a = bid.ortb2) === null || _a === void 0 ? void 0 : _a.site) === null || _b === void 0 ? void 0 : _b.page,
836
+ domain: (_d = (_c = bid.ortb2) === null || _c === void 0 ? void 0 : _c.site) === null || _d === void 0 ? void 0 : _d.domain
837
+ },
838
+ device: {
839
+ w: (_f = (_e = bid.ortb2) === null || _e === void 0 ? void 0 : _e.device) === null || _f === void 0 ? void 0 : _f.w,
840
+ h: (_h = (_g = bid.ortb2) === null || _g === void 0 ? void 0 : _g.device) === null || _h === void 0 ? void 0 : _h.h,
841
+ dnt: (_k = (_j = bid.ortb2) === null || _j === void 0 ? void 0 : _j.device) === null || _k === void 0 ? void 0 : _k.dnt,
842
+ ua: (_m = (_l = bid.ortb2) === null || _l === void 0 ? void 0 : _l.device) === null || _m === void 0 ? void 0 : _m.ua,
843
+ language: (_p = (_o = bid.ortb2) === null || _o === void 0 ? void 0 : _o.device) === null || _p === void 0 ? void 0 : _p.language
844
+ }
845
+ }
846
+ };
847
+ }),
848
+ auctionStart: req.auctionStart,
849
+ timeout: req.timeout,
850
+ refererInfo: {
851
+ stack: req.refererInfo.stack,
852
+ location: req.refererInfo.location,
853
+ page: req.refererInfo.page,
854
+ domain: req.refererInfo.domain
855
+ }
856
+ };
857
+ })
858
+ }
859
+ }
860
+ }), combinedContexts, e.timestamp);
861
+ });
862
+ }
863
+ function bidRequested(e, trackers) {
864
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
865
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
866
+ t.core.track(buildSelfDescribingEvent({
867
+ event: {
868
+ schema: 'iglu:io.surfside.advertising/bid_requested/jsonschema/1-0-0',
869
+ data: {
870
+ auctionId: e.auctionId,
871
+ bidderRequestId: e.bidderRequestId,
872
+ bids: e.bids.map(function (bid) {
873
+ return {
874
+ params: bid.params,
875
+ user: bid.user,
876
+ ortb2Imp: bid.ortb2Imp,
877
+ mediaTypes: bid.mediaTypes,
878
+ transactionId: bid.transactionId,
879
+ sizes: bid.sizes,
880
+ bidId: bid.bidId,
881
+ ortb2: {
882
+ site: {
883
+ page: bid.ortb2.site.page,
884
+ domain: bid.ortb2.site.domain
885
+ },
886
+ device: bid.ortb2.device
887
+ }
888
+ };
889
+ }),
890
+ auctionStart: e.auctionStart,
891
+ timeout: e.timeout,
892
+ refererInfo: e.refererInfo,
893
+ start: e.start
894
+ }
895
+ }
896
+ }));
897
+ });
898
+ }
899
+ function bidResponse(e, trackers) {
900
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
901
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
902
+ var _a, _b;
903
+ t.core.track(buildSelfDescribingEvent({
904
+ event: {
905
+ schema: 'iglu:io.surfside.advertising/bid_response/jsonschema/1-0-0',
906
+ data: {
907
+ width: e.width,
908
+ height: e.height,
909
+ statusMessage: e.statusMessage,
910
+ adId: e.adId,
911
+ requestId: e.requestId,
912
+ transactionId: e.transactionId,
913
+ auctionId: e.auctionId,
914
+ mediaType: e.mediaType,
915
+ ad: e.ad,
916
+ seatBidId: e.seatBidId,
917
+ cpm: e.cpm,
918
+ currency: e.currency,
919
+ creative_id: e.creative_id,
920
+ creativeId: e.creativeId,
921
+ ttl: e.ttl,
922
+ netRevenue: e.netRevenue,
923
+ meta: {
924
+ advertiserDomains: (_a = e === null || e === void 0 ? void 0 : e.meta) === null || _a === void 0 ? void 0 : _a.advertiserDomains
925
+ },
926
+ originalRequest: {
927
+ ext: e.originalRequest.ext,
928
+ id: e.originalRequest.id,
929
+ banner: (_b = e.originalRequest) === null || _b === void 0 ? void 0 : _b.banner
930
+ },
931
+ originalCpm: e.originalCpm,
932
+ originalCurrency: e.originalCurrency,
933
+ responseTimestamp: e.responseTimestamp,
934
+ requestTimestamp: e.requestTimestamp,
935
+ timeToRespond: e.timeToRespond,
936
+ size: e.size
937
+ }
938
+ }
939
+ }));
940
+ });
941
+ }
942
+ function bidderDone(e, trackers) {
943
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
944
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
945
+ t.core.track(buildSelfDescribingEvent({
946
+ event: {
947
+ schema: 'iglu:io.surfside.advertising/bidder_done/jsonschema/1-0-0',
948
+ data: {
949
+ auctionId: e.auctionId,
950
+ bidderRequestId: e.bidderRequestId,
951
+ bids: e.bids.map(function (bid) {
952
+ return {
953
+ params: bid.params,
954
+ user: bid.user,
955
+ ortb2Imp: bid.ortb2Imp,
956
+ mediaTypes: bid.mediaTypes,
957
+ transactionId: bid.transactionId,
958
+ sizes: bid.sizes,
959
+ bidId: bid.bidId,
960
+ ortb2: {
961
+ site: {
962
+ page: bid.ortb2.site.page,
963
+ domain: bid.ortb2.site.domain
964
+ },
965
+ device: bid.ortb2.device
966
+ }
967
+ };
968
+ }),
969
+ auctionStart: e.auctionStart,
970
+ timeout: e.timeout,
971
+ refererInfo: e.refererInfo,
972
+ start: e.start
973
+ }
974
+ }
975
+ }));
976
+ });
977
+ }
978
+ function bidderError(e, trackers) {
979
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
980
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
981
+ t.core.track(buildSelfDescribingEvent({
982
+ event: {
983
+ schema: 'iglu:io.surfside.advertising/bidder_error/jsonschema/1-0-0',
984
+ data: {
985
+ error: e.error,
986
+ auctionId: e.bidderRequest.auctionId,
987
+ bidderRequestId: e.bidderRequest.bidderRequestId,
988
+ bids: e.bidderRequest.bids.map(function (bid) {
989
+ return {
990
+ params: bid.params,
991
+ user: bid.user,
992
+ ortb2Imp: bid.ortb2Imp,
993
+ mediaTypes: bid.mediaTypes,
994
+ transactionId: bid.transactionId,
995
+ sizes: bid.sizes,
996
+ bidId: bid.bidId,
997
+ ortb2: {
998
+ site: {
999
+ page: bid.ortb2.site.page,
1000
+ domain: bid.ortb2.site.domain
1001
+ },
1002
+ device: bid.ortb2.device
1003
+ }
1004
+ };
1005
+ }),
1006
+ auctionStart: e.bidderRequest.auctionStart,
1007
+ timeout: e.bidderRequest.timeout,
1008
+ refererInfo: e.bidderRequest.refererInfo,
1009
+ start: e.bidderRequest.start
1010
+ }
1011
+ }
1012
+ }));
1013
+ });
1014
+ }
1015
+ function noBid(e, trackers) {
1016
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
1017
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
1018
+ t.core.track(buildSelfDescribingEvent({
1019
+ event: {
1020
+ schema: 'iglu:io.surfside.advertising/no_bid/jsonschema/1-0-0',
1021
+ data: {
1022
+ auctionId: e.auctionId,
1023
+ bidderRequestId: e.bidderRequestId,
1024
+ auctionStart: e.auctionStart,
1025
+ timeout: e.timeout,
1026
+ refererInfo: e.refererInfo,
1027
+ start: e.start
1028
+ }
1029
+ }
1030
+ }));
1031
+ });
1032
+ }
606
1033
 
607
1034
  exports.SurfsideCommercePlugin = SurfsideCommercePlugin;
608
1035
  exports.addImpression = addImpression;
609
1036
  exports.addProduct = addProduct;
610
1037
  exports.addPromotion = addPromotion;
611
1038
  exports.addTransaction = addTransaction;
1039
+ exports.auctionInit = auctionInit;
1040
+ exports.bidRequested = bidRequested;
1041
+ exports.bidResponse = bidResponse;
1042
+ exports.bidderDone = bidderDone;
1043
+ exports.bidderError = bidderError;
612
1044
  exports.identifyUser = identifyUser;
1045
+ exports.noBid = noBid;
1046
+ exports.removeLocation = removeLocation;
1047
+ exports.removeSegment = removeSegment;
613
1048
  exports.segment = segment;
614
1049
  exports.setCommerceAction = setCommerceAction;
1050
+ exports.setLocation = setLocation;
1051
+ exports.setSurfId = setSurfId;
615
1052
  exports.setUser = setUser;
616
1053
  exports.source = source;
617
1054