@surfside/surfside-events 0.0.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.
@@ -0,0 +1,621 @@
1
+ /*!
2
+ * Surfside Digital Analytics v0.0.1 (https://surfside.io)
3
+ * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
4
+ */
5
+
6
+ (function (global, factory) {
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
8
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.snowplowEnhancedEcommerce = {}));
10
+ })(this, (function (exports) { 'use strict';
11
+
12
+ /******************************************************************************
13
+ Copyright (c) Microsoft Corporation.
14
+
15
+ Permission to use, copy, modify, and/or distribute this software for any
16
+ purpose with or without fee is hereby granted.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
+ PERFORMANCE OF THIS SOFTWARE.
25
+ ***************************************************************************** */
26
+
27
+ function __spreadArray(to, from, pack) {
28
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
29
+ if (ar || !(i in from)) {
30
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
31
+ ar[i] = from[i];
32
+ }
33
+ }
34
+ return to.concat(ar || Array.prototype.slice.call(from));
35
+ }
36
+
37
+ /*!
38
+ * Core functionality for Surfside JavaScript trackers v0.0.1 (https://www.surfside.io)
39
+ * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
40
+ */
41
+
42
+ /*
43
+ * Copyright (c) 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
44
+ * All rights reserved.
45
+ *
46
+ * Redistribution and use in source and binary forms, with or without
47
+ * modification, are permitted provided that the following conditions are met:
48
+ *
49
+ * 1. Redistributions of source code must retain the above copyright notice, this
50
+ * list of conditions and the following disclaimer.
51
+ *
52
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
53
+ * this list of conditions and the following disclaimer in the documentation
54
+ * and/or other materials provided with the distribution.
55
+ *
56
+ * 3. Neither the name of the copyright holder nor the names of its
57
+ * contributors may be used to endorse or promote products derived from
58
+ * this software without specific prior written permission.
59
+ *
60
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
61
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
63
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
64
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
66
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
67
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
68
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
69
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70
+ */
71
+ function payloadBuilder() {
72
+ var dict = {}, allJson = [], jsonForProcessing = [];
73
+ var processor;
74
+ var add = function (key, value) {
75
+ if (value != null && value !== '') {
76
+ // null also checks undefined
77
+ dict[key] = value;
78
+ }
79
+ };
80
+ var addDict = function (dict) {
81
+ for (var key in dict) {
82
+ if (Object.prototype.hasOwnProperty.call(dict, key)) {
83
+ add(key, dict[key]);
84
+ }
85
+ }
86
+ };
87
+ var addJson = function (keyIfEncoded, keyIfNotEncoded, json) {
88
+ if (json && isNonEmptyJson(json)) {
89
+ var jsonWithKeys = { keyIfEncoded: keyIfEncoded, keyIfNotEncoded: keyIfNotEncoded, json: json };
90
+ jsonForProcessing.push(jsonWithKeys);
91
+ allJson.push(jsonWithKeys);
92
+ }
93
+ };
94
+ return {
95
+ add: add,
96
+ addDict: addDict,
97
+ addJson: addJson,
98
+ getPayload: function () { return dict; },
99
+ getJson: function () { return allJson; },
100
+ withJsonProcessor: function (jsonProcessor) {
101
+ processor = jsonProcessor;
102
+ },
103
+ build: function () {
104
+ processor === null || processor === void 0 ? void 0 : processor(this, jsonForProcessing);
105
+ return dict;
106
+ }
107
+ };
108
+ }
109
+ /**
110
+ * Is property a non-empty JSON?
111
+ * @param property - Checks if object is non-empty json
112
+ */
113
+ function isNonEmptyJson(property) {
114
+ if (!isJson(property)) {
115
+ return false;
116
+ }
117
+ for (var key in property) {
118
+ if (Object.prototype.hasOwnProperty.call(property, key)) {
119
+ return true;
120
+ }
121
+ }
122
+ return false;
123
+ }
124
+ /**
125
+ * Is property a JSON?
126
+ * @param property - Checks if object is json
127
+ */
128
+ function isJson(property) {
129
+ return (typeof property !== 'undefined' &&
130
+ property !== null &&
131
+ (property.constructor === {}.constructor || property.constructor === [].constructor));
132
+ }
133
+
134
+ /*
135
+ * Copyright (c) 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
136
+ * All rights reserved.
137
+ *
138
+ * Redistribution and use in source and binary forms, with or without
139
+ * modification, are permitted provided that the following conditions are met:
140
+ *
141
+ * 1. Redistributions of source code must retain the above copyright notice, this
142
+ * list of conditions and the following disclaimer.
143
+ *
144
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
145
+ * this list of conditions and the following disclaimer in the documentation
146
+ * and/or other materials provided with the distribution.
147
+ *
148
+ * 3. Neither the name of the copyright holder nor the names of its
149
+ * contributors may be used to endorse or promote products derived from
150
+ * this software without specific prior written permission.
151
+ *
152
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
153
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
154
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
155
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
156
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
157
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
158
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
159
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
160
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
161
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
162
+ */
163
+ var label = 'Snowplow: ';
164
+ var LOG_LEVEL;
165
+ (function (LOG_LEVEL) {
166
+ LOG_LEVEL[LOG_LEVEL["none"] = 0] = "none";
167
+ LOG_LEVEL[LOG_LEVEL["error"] = 1] = "error";
168
+ LOG_LEVEL[LOG_LEVEL["warn"] = 2] = "warn";
169
+ LOG_LEVEL[LOG_LEVEL["debug"] = 3] = "debug";
170
+ LOG_LEVEL[LOG_LEVEL["info"] = 4] = "info";
171
+ })(LOG_LEVEL || (LOG_LEVEL = {}));
172
+ var LOG = logger();
173
+ function logger(logLevel) {
174
+ if (logLevel === void 0) { logLevel = LOG_LEVEL.warn; }
175
+ function setLogLevel(level) {
176
+ if (LOG_LEVEL[level]) {
177
+ logLevel = level;
178
+ }
179
+ else {
180
+ logLevel = LOG_LEVEL.warn;
181
+ }
182
+ }
183
+ /**
184
+ * Log errors, with or without error object
185
+ */
186
+ function error(message, error) {
187
+ var extraParams = [];
188
+ for (var _i = 2; _i < arguments.length; _i++) {
189
+ extraParams[_i - 2] = arguments[_i];
190
+ }
191
+ if (logLevel >= LOG_LEVEL.error && typeof console !== 'undefined') {
192
+ var logMsg = label + message + '\n';
193
+ if (error) {
194
+ console.error.apply(console, __spreadArray([logMsg + '\n', error], extraParams, false));
195
+ }
196
+ else {
197
+ console.error.apply(console, __spreadArray([logMsg], extraParams, false));
198
+ }
199
+ }
200
+ }
201
+ /**
202
+ * Log warnings, with or without error object
203
+ */
204
+ function warn(message, error) {
205
+ var extraParams = [];
206
+ for (var _i = 2; _i < arguments.length; _i++) {
207
+ extraParams[_i - 2] = arguments[_i];
208
+ }
209
+ if (logLevel >= LOG_LEVEL.warn && typeof console !== 'undefined') {
210
+ var logMsg = label + message;
211
+ if (error) {
212
+ console.warn.apply(console, __spreadArray([logMsg + '\n', error], extraParams, false));
213
+ }
214
+ else {
215
+ console.warn.apply(console, __spreadArray([logMsg], extraParams, false));
216
+ }
217
+ }
218
+ }
219
+ /**
220
+ * Log debug messages
221
+ */
222
+ function debug(message) {
223
+ var extraParams = [];
224
+ for (var _i = 1; _i < arguments.length; _i++) {
225
+ extraParams[_i - 1] = arguments[_i];
226
+ }
227
+ if (logLevel >= LOG_LEVEL.debug && typeof console !== 'undefined') {
228
+ console.debug.apply(console, __spreadArray([label + message], extraParams, false));
229
+ }
230
+ }
231
+ /**
232
+ * Log info messages
233
+ */
234
+ function info(message) {
235
+ var extraParams = [];
236
+ for (var _i = 1; _i < arguments.length; _i++) {
237
+ extraParams[_i - 1] = arguments[_i];
238
+ }
239
+ if (logLevel >= LOG_LEVEL.info && typeof console !== 'undefined') {
240
+ console.info.apply(console, __spreadArray([label + message], extraParams, false));
241
+ }
242
+ }
243
+ return { setLogLevel: setLogLevel, warn: warn, error: error, debug: debug, info: info };
244
+ }
245
+ /**
246
+ * Build a self-describing event
247
+ * A custom event type, allowing for an event to be tracked using your own custom schema
248
+ * and a data object which conforms to the supplied schema
249
+ *
250
+ * @param event - Contains the properties and schema location for the event
251
+ * @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
252
+ */
253
+ function buildSelfDescribingEvent(event) {
254
+ var _a = event.event, schema = _a.schema, data = _a.data, pb = payloadBuilder();
255
+ var ueJson = {
256
+ schema: 'iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0',
257
+ data: { schema: schema, data: data }
258
+ };
259
+ pb.add('e', 'ue');
260
+ pb.addJson('ue_px', 'ue_pr', ueJson);
261
+ return pb;
262
+ }
263
+
264
+ /*!
265
+ * Core functionality for Surfside Digital trackers v0.0.1 ()
266
+ * Copyright 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
267
+ */
268
+ /**
269
+ * Parses an object and returns either the
270
+ * integer or undefined.
271
+ *
272
+ * @param obj - The object to parse
273
+ * @returns the result of the parse operation
274
+ */
275
+ function parseAndValidateInt(obj) {
276
+ var result = parseInt(obj);
277
+ return isNaN(result) ? undefined : result;
278
+ }
279
+ /**
280
+ * Parses an object and returns either the
281
+ * number or undefined.
282
+ *
283
+ * @param obj - The object to parse
284
+ * @returns the result of the parse operation
285
+ */
286
+ function parseAndValidateFloat(obj) {
287
+ var result = parseFloat(obj);
288
+ return isNaN(result) ? undefined : result;
289
+ }
290
+ /**
291
+ * Dispatch function to all specified trackers from the supplied collection
292
+ *
293
+ * @param trackers - An optional list of trackers to send the event to, or will send to all trackers
294
+ * @param trackerCollection - The collection which the trackers will be selected from
295
+ * @param fn - The function which will run against each tracker
296
+ */
297
+ function dispatchToTrackersInCollection(trackers, trackerCollection, fn) {
298
+ try {
299
+ getTrackersFromCollection(trackers !== null && trackers !== void 0 ? trackers : Object.keys(trackerCollection), trackerCollection).forEach(fn);
300
+ }
301
+ catch (ex) {
302
+ LOG.error('Function failed', ex);
303
+ }
304
+ }
305
+ function getTrackersFromCollection(trackerIds, trackerCollection) {
306
+ var trackers = [];
307
+ for (var _i = 0, trackerIds_1 = trackerIds; _i < trackerIds_1.length; _i++) {
308
+ var id = trackerIds_1[_i];
309
+ if (trackerCollection.hasOwnProperty(id)) {
310
+ trackers.push(trackerCollection[id]);
311
+ }
312
+ else {
313
+ LOG.warn(id + ' not configured');
314
+ }
315
+ }
316
+ return trackers;
317
+ }
318
+
319
+ /*
320
+ * Copyright (c) 2022 Surfside Solutions Inc, Snowplow Analytics Ltd, 2010 Anthon Pang
321
+ * All rights reserved.
322
+ *
323
+ * Redistribution and use in source and binary forms, with or without
324
+ * modification, are permitted provided that the following conditions are met:
325
+ *
326
+ * 1. Redistributions of source code must retain the above copyright notice, this
327
+ * list of conditions and the following disclaimer.
328
+ *
329
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
330
+ * this list of conditions and the following disclaimer in the documentation
331
+ * and/or other materials provided with the distribution.
332
+ *
333
+ * 3. Neither the name of the copyright holder nor the names of its
334
+ * contributors may be used to endorse or promote products derived from
335
+ * this software without specific prior written permission.
336
+ *
337
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
338
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
339
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
340
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
341
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
342
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
343
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
344
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
345
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
346
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
347
+ */
348
+ var _trackers = {};
349
+ var _context = {};
350
+ function SurfsideCommercePlugin() {
351
+ return {
352
+ activateBrowserPlugin: function (tracker) {
353
+ _trackers[tracker.id] = tracker;
354
+ _context[tracker.id] = [];
355
+ }
356
+ };
357
+ }
358
+ /**
359
+ * Track a Commerce Action with all stored Commerce contexts
360
+ *
361
+ * @param event
362
+ * @param trackers
363
+ */
364
+ function setCommerceAction(event, trackers) {
365
+ if (event === void 0) { event = {}; }
366
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
367
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
368
+ var combinedContexts = _context[t.id].concat(event.context || []);
369
+ _context[t.id].length = 0;
370
+ t.core.track(buildSelfDescribingEvent({
371
+ event: {
372
+ schema: 'iglu:io.surfside.commerce/action/jsonschema/1-0-0',
373
+ data: {
374
+ action: event
375
+ }
376
+ }
377
+ }), combinedContexts, event.timestamp);
378
+ });
379
+ }
380
+ /**
381
+ * Adds a Commerce Transaction Context to an Action
382
+ *
383
+ * @param context - The context to be stored
384
+ * @param trackers - The tracker identifiers which the context will be stored against
385
+ */
386
+ function addTransaction(context, trackers) {
387
+ if (context === void 0) { context = {}; }
388
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
389
+ var id = context.id, affiliation = context.affiliation, revenue = context.revenue, tax = context.tax, shipping = context.shipping, coupon = context.coupon, list = context.list, step = context.step, option = context.option, currency = context.currency;
390
+ trackers.forEach(function (trackerId) {
391
+ if (_context[trackerId]) {
392
+ _context[trackerId].push({
393
+ schema: 'iglu:io.surfside.commerce/transaction/jsonschema/1-0-0',
394
+ data: {
395
+ id: id,
396
+ affiliation: affiliation,
397
+ revenue: parseAndValidateFloat(revenue),
398
+ tax: parseAndValidateFloat(tax),
399
+ shipping: parseAndValidateFloat(shipping),
400
+ coupon: coupon,
401
+ list: list,
402
+ step: parseAndValidateInt(step),
403
+ option: option,
404
+ currency: currency
405
+ }
406
+ });
407
+ }
408
+ });
409
+ }
410
+ /**
411
+ * Adds a Commerce Impression Context
412
+ *
413
+ * @param context - The context to be stored
414
+ * @param trackers - The tracker identifiers which the context will be stored against
415
+ */
416
+ function addImpression(context, trackers) {
417
+ if (context === void 0) { context = {}; }
418
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
419
+ var id = context.id, name = context.name, list = context.list, brand = context.brand, category = context.category, variant = context.variant, position = context.position, price = context.price, currency = context.currency;
420
+ trackers.forEach(function (trackerId) {
421
+ if (_context[trackerId]) {
422
+ _context[trackerId].push({
423
+ schema: 'iglu:io.surfside.commerce/impression/jsonschema/1-0-0',
424
+ data: {
425
+ id: id,
426
+ name: name,
427
+ list: list,
428
+ brand: brand,
429
+ category: category,
430
+ variant: variant,
431
+ position: parseAndValidateInt(position),
432
+ price: parseAndValidateFloat(price),
433
+ currency: currency
434
+ }
435
+ });
436
+ }
437
+ });
438
+ }
439
+ /**
440
+ * Adds a Commerce Product Context
441
+ *
442
+ * @param context - The context to be stored
443
+ * @param trackers - The tracker identifiers which the context will be stored against
444
+ */
445
+ function addProduct(context, trackers) {
446
+ if (context === void 0) { context = {}; }
447
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
448
+ var id = context.id, name = context.name, list = context.list, brand = context.brand, category = context.category, variant = context.variant, price = context.price, quantity = context.quantity, coupon = context.coupon, position = context.position, currency = context.currency;
449
+ trackers.forEach(function (trackerId) {
450
+ if (_context[trackerId]) {
451
+ _context[trackerId].push({
452
+ schema: 'iglu:io.surfside.commerce/product/jsonschema/1-0-0',
453
+ data: {
454
+ id: id,
455
+ name: name,
456
+ list: list,
457
+ brand: brand,
458
+ category: category,
459
+ variant: variant,
460
+ price: parseAndValidateFloat(price),
461
+ quantity: parseAndValidateInt(quantity),
462
+ coupon: coupon,
463
+ position: parseAndValidateInt(position),
464
+ currency: currency
465
+ }
466
+ });
467
+ }
468
+ });
469
+ }
470
+ /**
471
+ * Adds a Commerce Promotion Context
472
+ *
473
+ * @param context - The context to be stored
474
+ * @param trackers - The tracker identifiers which the context will be stored against
475
+ */
476
+ function addPromotion(context, trackers) {
477
+ if (context === void 0) { context = {}; }
478
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
479
+ var id = context.id, name = context.name, creative = context.creative, position = context.position, currency = context.currency;
480
+ trackers.forEach(function (trackerId) {
481
+ if (_context[trackerId]) {
482
+ _context[trackerId].push({
483
+ schema: 'iglu:io.surfside.commerce/promotion/jsonschema/1-0-0',
484
+ data: {
485
+ id: id,
486
+ name: name,
487
+ creative: creative,
488
+ position: position,
489
+ currency: currency
490
+ }
491
+ });
492
+ }
493
+ });
494
+ }
495
+ /**
496
+ * Adds a Surfside Source Context
497
+ *
498
+ * @param context - The context to be stored
499
+ * @param trackers - The tracker identifiers which the context will be stored against
500
+ */
501
+ function source(context, trackers) {
502
+ if (context === void 0) { context = {}; }
503
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
504
+ var accountId = context.accountId, sourceId = context.sourceId;
505
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
506
+ _context[t.id].length = 0;
507
+ t.core.addGlobalContexts([
508
+ {
509
+ schema: 'iglu:io.surfside/context/jsonschema/1-0-0',
510
+ data: {
511
+ accountId: accountId,
512
+ sourceId: sourceId
513
+ }
514
+ },
515
+ ]);
516
+ });
517
+ }
518
+ /**
519
+ * Adds a Surfside Segment Context
520
+ *
521
+ * @param context - The context to be stored
522
+ * @param trackers - The tracker identifiers which the context will be stored against
523
+ */
524
+ function segment(context, trackers) {
525
+ if (context === void 0) { context = {}; }
526
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
527
+ var segmentId = context.segmentId, segmentVal = context.segmentVal;
528
+ dispatchToTrackersInCollection(trackers, _trackers, function (t) {
529
+ _context[t.id].length = 0;
530
+ t.core.addGlobalContexts([
531
+ {
532
+ schema: 'iglu:io.surfside/segment/jsonschema/1-0-0',
533
+ data: {
534
+ segmentId: segmentId,
535
+ segmentVal: segmentVal
536
+ }
537
+ },
538
+ ]);
539
+ });
540
+ }
541
+ /**
542
+ * Adds a Surfside User Context
543
+ *
544
+ * @param context - The context to be stored
545
+ * @param trackers - The tracker identifiers which the context will be stored against
546
+ */
547
+ function setUser(context, trackers) {
548
+ if (context === void 0) { context = {}; }
549
+ 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;
551
+ trackers.forEach(function (trackerId) {
552
+ if (_context[trackerId]) {
553
+ _context[trackerId].push({
554
+ schema: 'iglu:io.surfside.identity/user/jsonschema/1-0-0',
555
+ data: {
556
+ address: address,
557
+ age: age,
558
+ company: company,
559
+ createdAt: createdAt,
560
+ dateOfBirth: dateOfBirth,
561
+ email: email,
562
+ firstName: firstName,
563
+ gender: gender,
564
+ userId: userId,
565
+ lastName: lastName
566
+ }
567
+ });
568
+ }
569
+ });
570
+ }
571
+ /**
572
+ * Adds a Surfside Context
573
+ *
574
+ * @param context - The context to be stored
575
+ * @param trackers - The tracker identifiers which the context will be stored against
576
+ */
577
+ function identifyUser(context, trackers) {
578
+ if (context === void 0) { context = {}; }
579
+ if (trackers === void 0) { trackers = Object.keys(_trackers); }
580
+ var id = context.id, 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, name = context.name, phone = context.phone, title = context.title, username = context.username;
581
+ trackers.forEach(function (trackerId) {
582
+ if (_context[trackerId]) {
583
+ _context[trackerId].push({
584
+ schema: 'iglu:io.surfside.identity/user/jsonschema/1-0-0',
585
+ data: {
586
+ id: id,
587
+ address: address,
588
+ age: age,
589
+ company: company,
590
+ createdAt: createdAt,
591
+ dateOfBirth: dateOfBirth,
592
+ email: email,
593
+ firstName: firstName,
594
+ gender: gender,
595
+ userId: userId,
596
+ lastName: lastName,
597
+ name: name,
598
+ phone: phone,
599
+ title: title,
600
+ username: username
601
+ }
602
+ });
603
+ }
604
+ });
605
+ }
606
+
607
+ exports.SurfsideCommercePlugin = SurfsideCommercePlugin;
608
+ exports.addImpression = addImpression;
609
+ exports.addProduct = addProduct;
610
+ exports.addPromotion = addPromotion;
611
+ exports.addTransaction = addTransaction;
612
+ exports.identifyUser = identifyUser;
613
+ exports.segment = segment;
614
+ exports.setCommerceAction = setCommerceAction;
615
+ exports.setUser = setUser;
616
+ exports.source = source;
617
+
618
+ Object.defineProperty(exports, '__esModule', { value: true });
619
+
620
+ }));
621
+ //# sourceMappingURL=index.umd.js.map