@aws-amplify/analytics 7.0.1-api-v6-models.9351bcf.0 → 7.0.1-api-v6-models.891fe0d.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.
Files changed (87) hide show
  1. package/lib/apis/disable.js +1 -1
  2. package/lib/apis/enable.js +1 -1
  3. package/lib/errors/AnalyticsError.js +7 -11
  4. package/lib/errors/assertValidationError.js +6 -6
  5. package/lib/errors/validation.js +10 -11
  6. package/lib/providers/kinesis/apis/flushEvents.js +20 -23
  7. package/lib/providers/kinesis/apis/record.js +24 -26
  8. package/lib/providers/kinesis/utils/getEventBuffer.js +39 -70
  9. package/lib/providers/kinesis/utils/resolveConfig.js +14 -13
  10. package/lib/providers/kinesis-firehose/apis/flushEvents.js +19 -22
  11. package/lib/providers/kinesis-firehose/apis/record.js +22 -24
  12. package/lib/providers/kinesis-firehose/utils/getEventBuffer.js +39 -68
  13. package/lib/providers/kinesis-firehose/utils/resolveConfig.js +14 -13
  14. package/lib/providers/personalize/apis/flushEvents.js +18 -21
  15. package/lib/providers/personalize/apis/record.js +55 -71
  16. package/lib/providers/personalize/utils/autoTrackMedia.js +96 -98
  17. package/lib/providers/personalize/utils/cachedSession.js +30 -42
  18. package/lib/providers/personalize/utils/getEventBuffer.js +35 -62
  19. package/lib/providers/personalize/utils/resolveConfig.js +14 -13
  20. package/lib/providers/pinpoint/apis/configureAutoTrack.js +6 -6
  21. package/lib/providers/pinpoint/apis/flushEvents.js +10 -13
  22. package/lib/providers/pinpoint/apis/identifyUser.js +18 -30
  23. package/lib/providers/pinpoint/apis/record.js +15 -16
  24. package/lib/providers/pinpoint/utils/resolveConfig.js +5 -6
  25. package/lib/providers/pinpoint/utils/resolveCredentials.js +7 -15
  26. package/lib/setupTests.js +1 -1
  27. package/lib/trackers/EventTracker.js +39 -45
  28. package/lib/trackers/PageViewTracker.js +41 -45
  29. package/lib/trackers/SessionTracker.js +25 -31
  30. package/lib/trackers/SessionTracker.native.js +25 -31
  31. package/lib/tsconfig.tsbuildinfo +1 -1
  32. package/lib/utils/eventBuffer/EventBuffer.js +34 -62
  33. package/lib/utils/groupBy.js +4 -7
  34. package/lib/utils/resolveCredentials.js +7 -15
  35. package/lib/utils/statusHelpers.js +4 -4
  36. package/lib/utils/trackerConfigHelpers.js +2 -2
  37. package/lib/utils/trackerConfigHelpers.native.js +2 -2
  38. package/lib/utils/trackerHelpers.js +5 -5
  39. package/lib/utils/userAgent.js +3 -3
  40. package/lib-esm/apis/disable.js +1 -1
  41. package/lib-esm/apis/enable.js +1 -1
  42. package/lib-esm/errors/AnalyticsError.js +6 -11
  43. package/lib-esm/errors/assertValidationError.js +4 -4
  44. package/lib-esm/errors/validation.js +10 -11
  45. package/lib-esm/providers/kinesis/apis/flushEvents.js +15 -18
  46. package/lib-esm/providers/kinesis/apis/record.js +18 -20
  47. package/lib-esm/providers/kinesis/utils/constants.js +1 -1
  48. package/lib-esm/providers/kinesis/utils/getEventBuffer.js +37 -68
  49. package/lib-esm/providers/kinesis/utils/resolveConfig.js +11 -10
  50. package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +15 -18
  51. package/lib-esm/providers/kinesis-firehose/apis/record.js +17 -19
  52. package/lib-esm/providers/kinesis-firehose/utils/constants.js +1 -1
  53. package/lib-esm/providers/kinesis-firehose/utils/getEventBuffer.js +37 -66
  54. package/lib-esm/providers/kinesis-firehose/utils/resolveConfig.js +11 -10
  55. package/lib-esm/providers/personalize/apis/flushEvents.js +14 -17
  56. package/lib-esm/providers/personalize/apis/record.js +50 -66
  57. package/lib-esm/providers/personalize/utils/autoTrackMedia.js +94 -96
  58. package/lib-esm/providers/personalize/utils/cachedSession.js +28 -40
  59. package/lib-esm/providers/personalize/utils/constants.js +4 -4
  60. package/lib-esm/providers/personalize/utils/getEventBuffer.js +33 -60
  61. package/lib-esm/providers/personalize/utils/resolveConfig.js +11 -10
  62. package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +4 -4
  63. package/lib-esm/providers/pinpoint/apis/flushEvents.js +5 -8
  64. package/lib-esm/providers/pinpoint/apis/identifyUser.js +14 -26
  65. package/lib-esm/providers/pinpoint/apis/record.js +9 -10
  66. package/lib-esm/providers/pinpoint/utils/resolveConfig.js +3 -4
  67. package/lib-esm/providers/pinpoint/utils/resolveCredentials.js +5 -13
  68. package/lib-esm/setupTests.js +1 -1
  69. package/lib-esm/trackers/EventTracker.js +37 -44
  70. package/lib-esm/trackers/PageViewTracker.js +39 -44
  71. package/lib-esm/trackers/SessionTracker.js +22 -29
  72. package/lib-esm/trackers/SessionTracker.native.js +22 -29
  73. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  74. package/lib-esm/utils/eventBuffer/EventBuffer.js +33 -62
  75. package/lib-esm/utils/groupBy.js +4 -7
  76. package/lib-esm/utils/resolveCredentials.js +5 -13
  77. package/lib-esm/utils/statusHelpers.js +4 -4
  78. package/lib-esm/utils/trackerConfigHelpers.js +1 -1
  79. package/lib-esm/utils/trackerConfigHelpers.native.js +1 -1
  80. package/lib-esm/utils/trackerHelpers.js +4 -4
  81. package/lib-esm/utils/userAgent.js +2 -2
  82. package/package.json +6 -9
  83. package/src/providers/kinesis/utils/getEventBuffer.ts +6 -7
  84. package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +6 -7
  85. package/src/providers/personalize/utils/getEventBuffer.ts +6 -7
  86. package/src/trackers/SessionTracker.native.ts +2 -3
  87. package/src/trackers/SessionTracker.ts +2 -3
@@ -3,58 +3,53 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.EventTracker = void 0;
6
- var core_1 = require("@aws-amplify/core");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var DEFAULT_EVENTS = ['click'];
9
- var DEFAULT_SELECTOR_PREFIX = 'data-amplify-analytics-';
10
- var DEFAULT_EVENT_NAME = 'event'; // Default event name as sent to the analytics provider
11
- var logger = new core_1.ConsoleLogger('EventTracker');
12
- var EventTracker = /** @class */ (function () {
13
- function EventTracker(eventRecorder, options) {
6
+ const core_1 = require("@aws-amplify/core");
7
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
+ const DEFAULT_EVENTS = ['click'];
9
+ const DEFAULT_SELECTOR_PREFIX = 'data-amplify-analytics-';
10
+ const DEFAULT_EVENT_NAME = 'event'; // Default event name as sent to the analytics provider
11
+ const logger = new core_1.ConsoleLogger('EventTracker');
12
+ class EventTracker {
13
+ constructor(eventRecorder, options) {
14
14
  this.options = {};
15
15
  this.trackerActive = false;
16
16
  this.eventRecorder = eventRecorder;
17
17
  this.handleDocEvent = this.handleDocEvent.bind(this);
18
18
  this.configure(eventRecorder, options);
19
19
  }
20
- EventTracker.prototype.configure = function (eventRecorder, options) {
21
- var _this = this;
22
- var _a, _b, _c, _d;
20
+ configure(eventRecorder, options) {
23
21
  this.eventRecorder = eventRecorder;
24
22
  // Clean up any existing listeners
25
23
  this.cleanup();
26
24
  // Apply defaults
27
25
  this.options = {
28
- attributes: (_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : undefined,
29
- events: (_b = options === null || options === void 0 ? void 0 : options.events) !== null && _b !== void 0 ? _b : DEFAULT_EVENTS,
30
- selectorPrefix: (_c = options === null || options === void 0 ? void 0 : options.selectorPrefix) !== null && _c !== void 0 ? _c : DEFAULT_SELECTOR_PREFIX,
26
+ attributes: options?.attributes ?? undefined,
27
+ events: options?.events ?? DEFAULT_EVENTS,
28
+ selectorPrefix: options?.selectorPrefix ?? DEFAULT_SELECTOR_PREFIX,
31
29
  };
32
30
  // Register event listeners
33
31
  if ((0, utils_1.isBrowser)()) {
34
- (_d = this.options.events) === null || _d === void 0 ? void 0 : _d.forEach(function (targetEvent) {
35
- document.addEventListener(targetEvent, _this.handleDocEvent, {
32
+ this.options.events?.forEach(targetEvent => {
33
+ document.addEventListener(targetEvent, this.handleDocEvent, {
36
34
  capture: true,
37
35
  });
38
36
  });
39
37
  this.trackerActive = true;
40
38
  }
41
- };
42
- EventTracker.prototype.cleanup = function () {
43
- var _this = this;
44
- var _a;
39
+ }
40
+ cleanup() {
45
41
  // No-op if document listener is not active
46
42
  if (!this.trackerActive) {
47
43
  return;
48
44
  }
49
45
  // Clean up event listeners
50
- (_a = this.options.events) === null || _a === void 0 ? void 0 : _a.forEach(function (targetEvent) {
51
- document.removeEventListener(targetEvent, _this.handleDocEvent, {
46
+ this.options.events?.forEach(targetEvent => {
47
+ document.removeEventListener(targetEvent, this.handleDocEvent, {
52
48
  capture: true,
53
49
  });
54
50
  });
55
- };
56
- EventTracker.prototype.handleDocEvent = function (event) {
57
- var _a;
51
+ }
52
+ handleDocEvent(event) {
58
53
  /**
59
54
  * Example DOM element:
60
55
  *
@@ -66,39 +61,38 @@ var EventTracker = /** @class */ (function () {
66
61
  * />
67
62
  * ```
68
63
  */
69
- var triggerSelector = "[".concat(this.options.selectorPrefix, "on]");
70
- var attrSelector = "".concat(this.options.selectorPrefix, "attrs");
71
- var eventNameSelector = "".concat(this.options.selectorPrefix, "name");
72
- var eventSource = event.target;
64
+ const triggerSelector = `[${this.options.selectorPrefix}on]`;
65
+ const attrSelector = `${this.options.selectorPrefix}attrs`;
66
+ const eventNameSelector = `${this.options.selectorPrefix}name`;
67
+ const eventSource = event.target;
73
68
  // Validate that the triggering event type is being tracked
74
- if (!((_a = this.options.events) === null || _a === void 0 ? void 0 : _a.includes(event.type))) {
69
+ if (!this.options.events?.includes(event.type)) {
75
70
  return;
76
71
  }
77
72
  if (eventSource instanceof HTMLElement) {
78
- var target = eventSource.closest(triggerSelector);
73
+ const target = eventSource.closest(triggerSelector);
79
74
  if (target) {
80
75
  // Parse event name from the element
81
- var eventName = target.getAttribute(eventNameSelector) || DEFAULT_EVENT_NAME;
76
+ const eventName = target.getAttribute(eventNameSelector) || DEFAULT_EVENT_NAME;
82
77
  // Parse attributes from the element
83
- var elementAttributes_1 = {};
84
- var rawElementAttributes = target.getAttribute(attrSelector);
85
- rawElementAttributes === null || rawElementAttributes === void 0 ? void 0 : rawElementAttributes.split(/\s*,\s*/).forEach(function (attr) {
86
- var tmp = attr.trim().split(/\s*:\s*/);
87
- elementAttributes_1[tmp[0]] = tmp[1];
78
+ const elementAttributes = {};
79
+ const rawElementAttributes = target.getAttribute(attrSelector);
80
+ rawElementAttributes?.split(/\s*,\s*/).forEach(attr => {
81
+ const tmp = attr.trim().split(/\s*:\s*/);
82
+ elementAttributes[tmp[0]] = tmp[1];
88
83
  });
89
84
  // Assemble final list of attributes
90
- var attributes = Object.assign({
85
+ const attributes = Object.assign({
91
86
  type: event.type,
92
- target: "".concat(target.localName, " with id ").concat(target.id),
93
- }, this.options.attributes, elementAttributes_1);
87
+ target: `${target.localName} with id ${target.id}`,
88
+ }, this.options.attributes, elementAttributes);
94
89
  logger.debug('Recording automatically tracked DOM event', {
95
- eventName: eventName,
96
- attributes: attributes,
90
+ eventName,
91
+ attributes,
97
92
  });
98
93
  this.eventRecorder(eventName, attributes);
99
94
  }
100
95
  }
101
- };
102
- return EventTracker;
103
- }());
96
+ }
97
+ }
104
98
  exports.EventTracker = EventTracker;
@@ -3,17 +3,17 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.PageViewTracker = void 0;
6
- var core_1 = require("@aws-amplify/core");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var logger = new core_1.ConsoleLogger('PageViewTracker');
9
- var DEFAULT_EVENT_NAME = 'pageView';
10
- var DEFAULT_APP_TYPE = 'singlePage';
11
- var DEFAULT_URL_PROVIDER = function () {
6
+ const core_1 = require("@aws-amplify/core");
7
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
+ const logger = new core_1.ConsoleLogger('PageViewTracker');
9
+ const DEFAULT_EVENT_NAME = 'pageView';
10
+ const DEFAULT_APP_TYPE = 'singlePage';
11
+ const DEFAULT_URL_PROVIDER = () => {
12
12
  return window.location.origin + window.location.pathname;
13
13
  };
14
- var PREV_URL_STORAGE_KEY = 'aws-amplify-analytics-prevUrl';
15
- var PageViewTracker = /** @class */ (function () {
16
- function PageViewTracker(eventRecorder, options) {
14
+ const PREV_URL_STORAGE_KEY = 'aws-amplify-analytics-prevUrl';
15
+ class PageViewTracker {
16
+ constructor(eventRecorder, options) {
17
17
  this.options = {};
18
18
  this.trackerActive = true;
19
19
  this.eventRecorder = eventRecorder;
@@ -21,17 +21,16 @@ var PageViewTracker = /** @class */ (function () {
21
21
  this.handleLocationChange = this.handleLocationChange.bind(this);
22
22
  this.configure(eventRecorder, options);
23
23
  }
24
- PageViewTracker.prototype.configure = function (eventRecorder, options) {
25
- var _a, _b, _c, _d, _e, _f;
24
+ configure(eventRecorder, options) {
26
25
  this.eventRecorder = eventRecorder;
27
26
  // Clean up any existing listeners
28
27
  this.cleanup();
29
28
  // Apply defaults
30
29
  this.options = {
31
- appType: (_a = options === null || options === void 0 ? void 0 : options.appType) !== null && _a !== void 0 ? _a : DEFAULT_APP_TYPE,
32
- attributes: (_b = options === null || options === void 0 ? void 0 : options.attributes) !== null && _b !== void 0 ? _b : undefined,
33
- eventName: (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.eventName) !== null && _d !== void 0 ? _d : DEFAULT_EVENT_NAME,
34
- urlProvider: (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.urlProvider) !== null && _f !== void 0 ? _f : DEFAULT_URL_PROVIDER,
30
+ appType: options?.appType ?? DEFAULT_APP_TYPE,
31
+ attributes: options?.attributes ?? undefined,
32
+ eventName: this.options?.eventName ?? DEFAULT_EVENT_NAME,
33
+ urlProvider: this.options?.urlProvider ?? DEFAULT_URL_PROVIDER,
35
34
  };
36
35
  // Configure SPA or MPA page view tracking
37
36
  if ((0, utils_1.isBrowser)()) {
@@ -43,9 +42,8 @@ var PageViewTracker = /** @class */ (function () {
43
42
  }
44
43
  this.trackerActive = true;
45
44
  }
46
- };
47
- PageViewTracker.prototype.cleanup = function () {
48
- var _a, _b;
45
+ }
46
+ cleanup() {
49
47
  // No-op if document listener is not active
50
48
  if (!this.trackerActive) {
51
49
  return;
@@ -54,27 +52,26 @@ var PageViewTracker = /** @class */ (function () {
54
52
  if (this.spaTrackingActive) {
55
53
  window.history.pushState = this.originalPushState;
56
54
  window.history.replaceState = this.originalReplaceState;
57
- (_a = this.pushStateProxy) === null || _a === void 0 ? void 0 : _a.revoke();
58
- (_b = this.replaceStateProxy) === null || _b === void 0 ? void 0 : _b.revoke();
55
+ this.pushStateProxy?.revoke();
56
+ this.replaceStateProxy?.revoke();
59
57
  window.removeEventListener('popstate', this.handleLocationChange);
60
58
  this.spaTrackingActive = false;
61
59
  }
62
- };
63
- PageViewTracker.prototype.setupSPATracking = function () {
64
- var _this = this;
60
+ }
61
+ setupSPATracking() {
65
62
  if (!this.spaTrackingActive) {
66
63
  // Configure proxies on History APIs
67
64
  this.pushStateProxy = Proxy.revocable(window.history.pushState, {
68
- apply: function (target, thisArg, args) {
69
- var proxiedResult = target.apply(thisArg, args);
70
- _this.handleLocationChange();
65
+ apply: (target, thisArg, args) => {
66
+ const proxiedResult = target.apply(thisArg, args);
67
+ this.handleLocationChange();
71
68
  return proxiedResult;
72
69
  },
73
70
  });
74
71
  this.replaceStateProxy = Proxy.revocable(window.history.replaceState, {
75
- apply: function (target, thisArg, args) {
76
- var proxiedResult = target.apply(thisArg, args);
77
- _this.handleLocationChange();
72
+ apply: (target, thisArg, args) => {
73
+ const proxiedResult = target.apply(thisArg, args);
74
+ this.handleLocationChange();
78
75
  return proxiedResult;
79
76
  },
80
77
  });
@@ -86,31 +83,30 @@ var PageViewTracker = /** @class */ (function () {
86
83
  sessionStorage.removeItem(PREV_URL_STORAGE_KEY);
87
84
  this.spaTrackingActive = true;
88
85
  }
89
- };
90
- PageViewTracker.prototype.setupMPATracking = function () {
86
+ }
87
+ setupMPATracking() {
91
88
  this.handleLocationChange();
92
- };
93
- PageViewTracker.prototype.handleLocationChange = function () {
94
- var currentUrl = this.options.urlProvider();
95
- var eventName = this.options.eventName || DEFAULT_EVENT_NAME;
89
+ }
90
+ handleLocationChange() {
91
+ const currentUrl = this.options.urlProvider();
92
+ const eventName = this.options.eventName || DEFAULT_EVENT_NAME;
96
93
  if (this.urlHasChanged()) {
97
94
  sessionStorage.setItem(PREV_URL_STORAGE_KEY, currentUrl);
98
95
  // Assemble attribute list
99
- var attributes = Object.assign({
96
+ const attributes = Object.assign({
100
97
  url: currentUrl,
101
98
  }, this.options.attributes);
102
99
  logger.debug('Recording automatically tracked page view event', {
103
- eventName: eventName,
104
- attributes: attributes,
100
+ eventName,
101
+ attributes,
105
102
  });
106
103
  this.eventRecorder(eventName, attributes);
107
104
  }
108
- };
109
- PageViewTracker.prototype.urlHasChanged = function () {
110
- var prevUrl = sessionStorage.getItem(PREV_URL_STORAGE_KEY);
111
- var currUrl = this.options.urlProvider();
105
+ }
106
+ urlHasChanged() {
107
+ const prevUrl = sessionStorage.getItem(PREV_URL_STORAGE_KEY);
108
+ const currUrl = this.options.urlProvider();
112
109
  return currUrl !== prevUrl;
113
- };
114
- return PageViewTracker;
115
- }());
110
+ }
111
+ }
116
112
  exports.PageViewTracker = PageViewTracker;
@@ -3,13 +3,11 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.SessionTracker = void 0;
6
- var utils_1 = require("@aws-amplify/core/internals/utils");
7
- var core_1 = require("@aws-amplify/core");
8
- var SESSION_START_EVENT = '_session.start';
9
- var SESSION_STOP_EVENT = '_session.stop';
10
- var logger = new core_1.ConsoleLogger('SessionTracker');
11
- var SessionTracker = /** @class */ (function () {
12
- function SessionTracker(eventRecorder, options) {
6
+ const utils_1 = require("@aws-amplify/core/internals/utils");
7
+ const core_1 = require("@aws-amplify/core");
8
+ const logger = new core_1.ConsoleLogger('SessionTracker');
9
+ class SessionTracker {
10
+ constructor(eventRecorder, options) {
13
11
  this.options = {};
14
12
  this.eventRecorder = eventRecorder;
15
13
  this.sessionTrackingActive = false;
@@ -17,57 +15,53 @@ var SessionTracker = /** @class */ (function () {
17
15
  this.handleStateChange = this.handleStateChange.bind(this);
18
16
  this.configure(eventRecorder, options);
19
17
  }
20
- SessionTracker.prototype.configure = function (eventRecorder, options) {
21
- var _a;
18
+ configure(eventRecorder, options) {
22
19
  this.eventRecorder = eventRecorder;
23
20
  // Clean up any existing listeners
24
21
  this.cleanup();
25
22
  // Apply defaults
26
23
  this.options = {
27
- attributes: (_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : {},
24
+ attributes: options?.attributes ?? {},
28
25
  };
29
26
  // Setup state listeners
30
27
  if (!this.sessionTrackingActive) {
31
28
  utils_1.sessionListener.addStateChangeListener(this.handleStateChange, !this.initialEventSent);
32
29
  this.sessionTrackingActive = true;
33
30
  }
34
- };
35
- SessionTracker.prototype.cleanup = function () {
31
+ }
32
+ cleanup() {
36
33
  if (this.sessionTrackingActive) {
37
34
  utils_1.sessionListener.removeStateChangeListener(this.handleStateChange);
38
35
  }
39
36
  this.sessionTrackingActive = false;
40
- };
41
- SessionTracker.prototype.handleStateChange = function (state) {
37
+ }
38
+ handleStateChange(state) {
42
39
  if (state === 'started') {
43
40
  this.sessionStarted();
44
41
  }
45
42
  else {
46
43
  this.sessionStopped();
47
44
  }
48
- };
49
- SessionTracker.prototype.sessionStarted = function () {
50
- var _a;
51
- var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
45
+ }
46
+ sessionStarted() {
47
+ const attributes = this.options.attributes ?? {};
52
48
  logger.debug('Recording automatically tracked page view event', {
53
- SESSION_START_EVENT: SESSION_START_EVENT,
54
- attributes: attributes,
49
+ SESSION_START_EVENT: utils_1.SESSION_START_EVENT,
50
+ attributes,
55
51
  });
56
- this.eventRecorder(SESSION_START_EVENT, attributes);
52
+ this.eventRecorder(utils_1.SESSION_START_EVENT, attributes);
57
53
  // NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
58
54
  if (!this.initialEventSent) {
59
55
  this.initialEventSent = true;
60
56
  }
61
- };
62
- SessionTracker.prototype.sessionStopped = function () {
63
- var _a;
64
- var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
57
+ }
58
+ sessionStopped() {
59
+ const attributes = this.options.attributes ?? {};
65
60
  logger.debug('Recording automatically tracked page view event', {
66
- SESSION_STOP_EVENT: SESSION_STOP_EVENT,
67
- attributes: attributes,
61
+ SESSION_STOP_EVENT: utils_1.SESSION_STOP_EVENT,
62
+ attributes,
68
63
  });
69
- this.eventRecorder(SESSION_STOP_EVENT, attributes);
70
- };
71
- return SessionTracker;
72
- }());
64
+ this.eventRecorder(utils_1.SESSION_STOP_EVENT, attributes);
65
+ }
66
+ }
73
67
  exports.SessionTracker = SessionTracker;
@@ -3,13 +3,11 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.SessionTracker = void 0;
6
- var utils_1 = require("@aws-amplify/core/internals/utils");
7
- var core_1 = require("@aws-amplify/core");
8
- var SESSION_START_EVENT = '_session.start';
9
- var SESSION_STOP_EVENT = '_session.stop';
10
- var logger = new core_1.ConsoleLogger('SessionTracker');
11
- var SessionTracker = /** @class */ (function () {
12
- function SessionTracker(eventRecorder, options) {
6
+ const utils_1 = require("@aws-amplify/core/internals/utils");
7
+ const core_1 = require("@aws-amplify/core");
8
+ const logger = new core_1.ConsoleLogger('SessionTracker');
9
+ class SessionTracker {
10
+ constructor(eventRecorder, options) {
13
11
  this.options = {};
14
12
  this.eventRecorder = eventRecorder;
15
13
  this.initialEventSent = false;
@@ -17,57 +15,53 @@ var SessionTracker = /** @class */ (function () {
17
15
  this.handleStateChange = this.handleStateChange.bind(this);
18
16
  this.configure(eventRecorder, options);
19
17
  }
20
- SessionTracker.prototype.configure = function (eventRecorder, options) {
21
- var _a;
18
+ configure(eventRecorder, options) {
22
19
  this.eventRecorder = eventRecorder;
23
20
  // Clean up any existing listeners
24
21
  this.cleanup();
25
22
  // Apply defaults
26
23
  this.options = {
27
- attributes: (_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : {},
24
+ attributes: options?.attributes ?? {},
28
25
  };
29
26
  // Setup state listeners
30
27
  if (!this.sessionTrackingActive) {
31
28
  utils_1.sessionListener.addStateChangeListener(this.handleStateChange, !this.initialEventSent);
32
29
  this.sessionTrackingActive = true;
33
30
  }
34
- };
35
- SessionTracker.prototype.cleanup = function () {
31
+ }
32
+ cleanup() {
36
33
  if (this.sessionTrackingActive) {
37
34
  utils_1.sessionListener.removeStateChangeListener(this.handleStateChange);
38
35
  }
39
36
  this.sessionTrackingActive = false;
40
- };
41
- SessionTracker.prototype.handleStateChange = function (state) {
37
+ }
38
+ handleStateChange(state) {
42
39
  if (state === 'started') {
43
40
  this.sessionStarted();
44
41
  }
45
42
  else {
46
43
  this.sessionStopped();
47
44
  }
48
- };
49
- SessionTracker.prototype.sessionStarted = function () {
50
- var _a;
51
- var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
45
+ }
46
+ sessionStarted() {
47
+ const attributes = this.options.attributes ?? {};
52
48
  logger.debug('Recording automatically tracked page view event', {
53
- SESSION_START_EVENT: SESSION_START_EVENT,
54
- attributes: attributes,
49
+ SESSION_START_EVENT: utils_1.SESSION_START_EVENT,
50
+ attributes,
55
51
  });
56
- this.eventRecorder(SESSION_START_EVENT, attributes);
52
+ this.eventRecorder(utils_1.SESSION_START_EVENT, attributes);
57
53
  // NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
58
54
  if (!this.initialEventSent) {
59
55
  this.initialEventSent = true;
60
56
  }
61
- };
62
- SessionTracker.prototype.sessionStopped = function () {
63
- var _a;
64
- var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
57
+ }
58
+ sessionStopped() {
59
+ const attributes = this.options.attributes ?? {};
65
60
  logger.debug('Recording automatically tracked page view event', {
66
- SESSION_STOP_EVENT: SESSION_STOP_EVENT,
67
- attributes: attributes,
61
+ SESSION_STOP_EVENT: utils_1.SESSION_STOP_EVENT,
62
+ attributes,
68
63
  });
69
- this.eventRecorder(SESSION_STOP_EVENT, attributes);
70
- };
71
- return SessionTracker;
72
- }());
64
+ this.eventRecorder(utils_1.SESSION_STOP_EVENT, attributes);
65
+ }
66
+ }
73
67
  exports.SessionTracker = SessionTracker;