@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
@@ -6,7 +6,7 @@ import { record as recordCore } from '@aws-amplify/core/internals/providers/pinp
6
6
  import { AnalyticsValidationErrorCode, assertValidationError, } from '../../../errors';
7
7
  import { getAnalyticsUserAgentString, isAnalyticsEnabled, } from '../../../utils';
8
8
  import { resolveConfig, resolveCredentials } from '../utils';
9
- var logger = new ConsoleLogger('Analytics');
9
+ const logger = new ConsoleLogger('Analytics');
10
10
  /**
11
11
  * Records an Analytic event to Pinpoint. Events will be buffered and periodically sent to Pinpoint.
12
12
  *
@@ -35,28 +35,27 @@ var logger = new ConsoleLogger('Analytics');
35
35
  * })
36
36
  * ```
37
37
  */
38
- export var record = function (input) {
39
- var _a = resolveConfig(), appId = _a.appId, region = _a.region;
38
+ export const record = (input) => {
39
+ const { appId, region } = resolveConfig();
40
40
  if (!isAnalyticsEnabled()) {
41
41
  logger.debug('Analytics is disabled, event will not be recorded.');
42
42
  return;
43
43
  }
44
44
  assertValidationError(!!input.name, AnalyticsValidationErrorCode.NoEventName);
45
45
  resolveCredentials()
46
- .then(function (_a) {
47
- var credentials = _a.credentials, identityId = _a.identityId;
46
+ .then(({ credentials, identityId }) => {
48
47
  Hub.dispatch('analytics', { event: 'record', data: input, message: 'Recording Analytics event' }, 'Analytics', AMPLIFY_SYMBOL);
49
48
  recordCore({
50
- appId: appId,
49
+ appId,
51
50
  category: 'Analytics',
52
- credentials: credentials,
51
+ credentials,
53
52
  event: input,
54
- identityId: identityId,
55
- region: region,
53
+ identityId,
54
+ region,
56
55
  userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
57
56
  });
58
57
  })
59
- .catch(function (e) {
58
+ .catch(e => {
60
59
  // An error occured while fetching credentials or persisting the event to the buffer
61
60
  logger.warn('Failed to record event.', e);
62
61
  });
@@ -5,10 +5,9 @@ import { AnalyticsValidationErrorCode, assertValidationError, } from '../../../e
5
5
  /**
6
6
  * @internal
7
7
  */
8
- export var resolveConfig = function () {
9
- var _a, _b;
10
- var _c = (_b = (_a = Amplify.getConfig().Analytics) === null || _a === void 0 ? void 0 : _a.Pinpoint) !== null && _b !== void 0 ? _b : {}, appId = _c.appId, region = _c.region;
8
+ export const resolveConfig = () => {
9
+ const { appId, region } = Amplify.getConfig().Analytics?.Pinpoint ?? {};
11
10
  assertValidationError(!!appId, AnalyticsValidationErrorCode.NoAppId);
12
11
  assertValidationError(!!region, AnalyticsValidationErrorCode.NoRegion);
13
- return { appId: appId, region: region };
12
+ return { appId, region };
14
13
  };
@@ -1,20 +1,12 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { __awaiter, __generator } from "tslib";
4
3
  import { fetchAuthSession } from '@aws-amplify/core';
5
4
  import { AnalyticsValidationErrorCode, assertValidationError, } from '../../../errors';
6
5
  /**
7
6
  * @internal
8
7
  */
9
- export var resolveCredentials = function () { return __awaiter(void 0, void 0, void 0, function () {
10
- var _a, credentials, identityId;
11
- return __generator(this, function (_b) {
12
- switch (_b.label) {
13
- case 0: return [4 /*yield*/, fetchAuthSession()];
14
- case 1:
15
- _a = _b.sent(), credentials = _a.credentials, identityId = _a.identityId;
16
- assertValidationError(!!credentials, AnalyticsValidationErrorCode.NoCredentials);
17
- return [2 /*return*/, { credentials: credentials, identityId: identityId }];
18
- }
19
- });
20
- }); };
8
+ export const resolveCredentials = async () => {
9
+ const { credentials, identityId } = await fetchAuthSession();
10
+ assertValidationError(!!credentials, AnalyticsValidationErrorCode.NoCredentials);
11
+ return { credentials, identityId };
12
+ };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
- var anyGlobal = global;
4
+ const anyGlobal = global;
5
5
  anyGlobal.navigator = anyGlobal.navigator || {};
6
6
  // @ts-ignore
7
7
  anyGlobal.navigator.sendBeacon = anyGlobal.navigator.sendBeacon || jest.fn();
@@ -2,56 +2,51 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { ConsoleLogger } from '@aws-amplify/core';
4
4
  import { isBrowser } from '@aws-amplify/core/internals/utils';
5
- var DEFAULT_EVENTS = ['click'];
6
- var DEFAULT_SELECTOR_PREFIX = 'data-amplify-analytics-';
7
- var DEFAULT_EVENT_NAME = 'event'; // Default event name as sent to the analytics provider
8
- var logger = new ConsoleLogger('EventTracker');
9
- var EventTracker = /** @class */ (function () {
10
- function EventTracker(eventRecorder, options) {
5
+ const DEFAULT_EVENTS = ['click'];
6
+ const DEFAULT_SELECTOR_PREFIX = 'data-amplify-analytics-';
7
+ const DEFAULT_EVENT_NAME = 'event'; // Default event name as sent to the analytics provider
8
+ const logger = new ConsoleLogger('EventTracker');
9
+ export class EventTracker {
10
+ constructor(eventRecorder, options) {
11
11
  this.options = {};
12
12
  this.trackerActive = false;
13
13
  this.eventRecorder = eventRecorder;
14
14
  this.handleDocEvent = this.handleDocEvent.bind(this);
15
15
  this.configure(eventRecorder, options);
16
16
  }
17
- EventTracker.prototype.configure = function (eventRecorder, options) {
18
- var _this = this;
19
- var _a, _b, _c, _d;
17
+ configure(eventRecorder, options) {
20
18
  this.eventRecorder = eventRecorder;
21
19
  // Clean up any existing listeners
22
20
  this.cleanup();
23
21
  // Apply defaults
24
22
  this.options = {
25
- attributes: (_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : undefined,
26
- events: (_b = options === null || options === void 0 ? void 0 : options.events) !== null && _b !== void 0 ? _b : DEFAULT_EVENTS,
27
- selectorPrefix: (_c = options === null || options === void 0 ? void 0 : options.selectorPrefix) !== null && _c !== void 0 ? _c : DEFAULT_SELECTOR_PREFIX,
23
+ attributes: options?.attributes ?? undefined,
24
+ events: options?.events ?? DEFAULT_EVENTS,
25
+ selectorPrefix: options?.selectorPrefix ?? DEFAULT_SELECTOR_PREFIX,
28
26
  };
29
27
  // Register event listeners
30
28
  if (isBrowser()) {
31
- (_d = this.options.events) === null || _d === void 0 ? void 0 : _d.forEach(function (targetEvent) {
32
- document.addEventListener(targetEvent, _this.handleDocEvent, {
29
+ this.options.events?.forEach(targetEvent => {
30
+ document.addEventListener(targetEvent, this.handleDocEvent, {
33
31
  capture: true,
34
32
  });
35
33
  });
36
34
  this.trackerActive = true;
37
35
  }
38
- };
39
- EventTracker.prototype.cleanup = function () {
40
- var _this = this;
41
- var _a;
36
+ }
37
+ cleanup() {
42
38
  // No-op if document listener is not active
43
39
  if (!this.trackerActive) {
44
40
  return;
45
41
  }
46
42
  // Clean up event listeners
47
- (_a = this.options.events) === null || _a === void 0 ? void 0 : _a.forEach(function (targetEvent) {
48
- document.removeEventListener(targetEvent, _this.handleDocEvent, {
43
+ this.options.events?.forEach(targetEvent => {
44
+ document.removeEventListener(targetEvent, this.handleDocEvent, {
49
45
  capture: true,
50
46
  });
51
47
  });
52
- };
53
- EventTracker.prototype.handleDocEvent = function (event) {
54
- var _a;
48
+ }
49
+ handleDocEvent(event) {
55
50
  /**
56
51
  * Example DOM element:
57
52
  *
@@ -63,39 +58,37 @@ var EventTracker = /** @class */ (function () {
63
58
  * />
64
59
  * ```
65
60
  */
66
- var triggerSelector = "[".concat(this.options.selectorPrefix, "on]");
67
- var attrSelector = "".concat(this.options.selectorPrefix, "attrs");
68
- var eventNameSelector = "".concat(this.options.selectorPrefix, "name");
69
- var eventSource = event.target;
61
+ const triggerSelector = `[${this.options.selectorPrefix}on]`;
62
+ const attrSelector = `${this.options.selectorPrefix}attrs`;
63
+ const eventNameSelector = `${this.options.selectorPrefix}name`;
64
+ const eventSource = event.target;
70
65
  // Validate that the triggering event type is being tracked
71
- if (!((_a = this.options.events) === null || _a === void 0 ? void 0 : _a.includes(event.type))) {
66
+ if (!this.options.events?.includes(event.type)) {
72
67
  return;
73
68
  }
74
69
  if (eventSource instanceof HTMLElement) {
75
- var target = eventSource.closest(triggerSelector);
70
+ const target = eventSource.closest(triggerSelector);
76
71
  if (target) {
77
72
  // Parse event name from the element
78
- var eventName = target.getAttribute(eventNameSelector) || DEFAULT_EVENT_NAME;
73
+ const eventName = target.getAttribute(eventNameSelector) || DEFAULT_EVENT_NAME;
79
74
  // Parse attributes from the element
80
- var elementAttributes_1 = {};
81
- var rawElementAttributes = target.getAttribute(attrSelector);
82
- rawElementAttributes === null || rawElementAttributes === void 0 ? void 0 : rawElementAttributes.split(/\s*,\s*/).forEach(function (attr) {
83
- var tmp = attr.trim().split(/\s*:\s*/);
84
- elementAttributes_1[tmp[0]] = tmp[1];
75
+ const elementAttributes = {};
76
+ const rawElementAttributes = target.getAttribute(attrSelector);
77
+ rawElementAttributes?.split(/\s*,\s*/).forEach(attr => {
78
+ const tmp = attr.trim().split(/\s*:\s*/);
79
+ elementAttributes[tmp[0]] = tmp[1];
85
80
  });
86
81
  // Assemble final list of attributes
87
- var attributes = Object.assign({
82
+ const attributes = Object.assign({
88
83
  type: event.type,
89
- target: "".concat(target.localName, " with id ").concat(target.id),
90
- }, this.options.attributes, elementAttributes_1);
84
+ target: `${target.localName} with id ${target.id}`,
85
+ }, this.options.attributes, elementAttributes);
91
86
  logger.debug('Recording automatically tracked DOM event', {
92
- eventName: eventName,
93
- attributes: attributes,
87
+ eventName,
88
+ attributes,
94
89
  });
95
90
  this.eventRecorder(eventName, attributes);
96
91
  }
97
92
  }
98
- };
99
- return EventTracker;
100
- }());
101
- export { EventTracker };
93
+ }
94
+ }
@@ -2,15 +2,15 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { ConsoleLogger } from '@aws-amplify/core';
4
4
  import { isBrowser } from '@aws-amplify/core/internals/utils';
5
- var logger = new ConsoleLogger('PageViewTracker');
6
- var DEFAULT_EVENT_NAME = 'pageView';
7
- var DEFAULT_APP_TYPE = 'singlePage';
8
- var DEFAULT_URL_PROVIDER = function () {
5
+ const logger = new ConsoleLogger('PageViewTracker');
6
+ const DEFAULT_EVENT_NAME = 'pageView';
7
+ const DEFAULT_APP_TYPE = 'singlePage';
8
+ const DEFAULT_URL_PROVIDER = () => {
9
9
  return window.location.origin + window.location.pathname;
10
10
  };
11
- var PREV_URL_STORAGE_KEY = 'aws-amplify-analytics-prevUrl';
12
- var PageViewTracker = /** @class */ (function () {
13
- function PageViewTracker(eventRecorder, options) {
11
+ const PREV_URL_STORAGE_KEY = 'aws-amplify-analytics-prevUrl';
12
+ export class PageViewTracker {
13
+ constructor(eventRecorder, options) {
14
14
  this.options = {};
15
15
  this.trackerActive = true;
16
16
  this.eventRecorder = eventRecorder;
@@ -18,17 +18,16 @@ var PageViewTracker = /** @class */ (function () {
18
18
  this.handleLocationChange = this.handleLocationChange.bind(this);
19
19
  this.configure(eventRecorder, options);
20
20
  }
21
- PageViewTracker.prototype.configure = function (eventRecorder, options) {
22
- var _a, _b, _c, _d, _e, _f;
21
+ configure(eventRecorder, options) {
23
22
  this.eventRecorder = eventRecorder;
24
23
  // Clean up any existing listeners
25
24
  this.cleanup();
26
25
  // Apply defaults
27
26
  this.options = {
28
- appType: (_a = options === null || options === void 0 ? void 0 : options.appType) !== null && _a !== void 0 ? _a : DEFAULT_APP_TYPE,
29
- attributes: (_b = options === null || options === void 0 ? void 0 : options.attributes) !== null && _b !== void 0 ? _b : undefined,
30
- eventName: (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.eventName) !== null && _d !== void 0 ? _d : DEFAULT_EVENT_NAME,
31
- urlProvider: (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.urlProvider) !== null && _f !== void 0 ? _f : DEFAULT_URL_PROVIDER,
27
+ appType: options?.appType ?? DEFAULT_APP_TYPE,
28
+ attributes: options?.attributes ?? undefined,
29
+ eventName: this.options?.eventName ?? DEFAULT_EVENT_NAME,
30
+ urlProvider: this.options?.urlProvider ?? DEFAULT_URL_PROVIDER,
32
31
  };
33
32
  // Configure SPA or MPA page view tracking
34
33
  if (isBrowser()) {
@@ -40,9 +39,8 @@ var PageViewTracker = /** @class */ (function () {
40
39
  }
41
40
  this.trackerActive = true;
42
41
  }
43
- };
44
- PageViewTracker.prototype.cleanup = function () {
45
- var _a, _b;
42
+ }
43
+ cleanup() {
46
44
  // No-op if document listener is not active
47
45
  if (!this.trackerActive) {
48
46
  return;
@@ -51,27 +49,26 @@ var PageViewTracker = /** @class */ (function () {
51
49
  if (this.spaTrackingActive) {
52
50
  window.history.pushState = this.originalPushState;
53
51
  window.history.replaceState = this.originalReplaceState;
54
- (_a = this.pushStateProxy) === null || _a === void 0 ? void 0 : _a.revoke();
55
- (_b = this.replaceStateProxy) === null || _b === void 0 ? void 0 : _b.revoke();
52
+ this.pushStateProxy?.revoke();
53
+ this.replaceStateProxy?.revoke();
56
54
  window.removeEventListener('popstate', this.handleLocationChange);
57
55
  this.spaTrackingActive = false;
58
56
  }
59
- };
60
- PageViewTracker.prototype.setupSPATracking = function () {
61
- var _this = this;
57
+ }
58
+ setupSPATracking() {
62
59
  if (!this.spaTrackingActive) {
63
60
  // Configure proxies on History APIs
64
61
  this.pushStateProxy = Proxy.revocable(window.history.pushState, {
65
- apply: function (target, thisArg, args) {
66
- var proxiedResult = target.apply(thisArg, args);
67
- _this.handleLocationChange();
62
+ apply: (target, thisArg, args) => {
63
+ const proxiedResult = target.apply(thisArg, args);
64
+ this.handleLocationChange();
68
65
  return proxiedResult;
69
66
  },
70
67
  });
71
68
  this.replaceStateProxy = Proxy.revocable(window.history.replaceState, {
72
- apply: function (target, thisArg, args) {
73
- var proxiedResult = target.apply(thisArg, args);
74
- _this.handleLocationChange();
69
+ apply: (target, thisArg, args) => {
70
+ const proxiedResult = target.apply(thisArg, args);
71
+ this.handleLocationChange();
75
72
  return proxiedResult;
76
73
  },
77
74
  });
@@ -83,31 +80,29 @@ var PageViewTracker = /** @class */ (function () {
83
80
  sessionStorage.removeItem(PREV_URL_STORAGE_KEY);
84
81
  this.spaTrackingActive = true;
85
82
  }
86
- };
87
- PageViewTracker.prototype.setupMPATracking = function () {
83
+ }
84
+ setupMPATracking() {
88
85
  this.handleLocationChange();
89
- };
90
- PageViewTracker.prototype.handleLocationChange = function () {
91
- var currentUrl = this.options.urlProvider();
92
- var eventName = this.options.eventName || DEFAULT_EVENT_NAME;
86
+ }
87
+ handleLocationChange() {
88
+ const currentUrl = this.options.urlProvider();
89
+ const eventName = this.options.eventName || DEFAULT_EVENT_NAME;
93
90
  if (this.urlHasChanged()) {
94
91
  sessionStorage.setItem(PREV_URL_STORAGE_KEY, currentUrl);
95
92
  // Assemble attribute list
96
- var attributes = Object.assign({
93
+ const attributes = Object.assign({
97
94
  url: currentUrl,
98
95
  }, this.options.attributes);
99
96
  logger.debug('Recording automatically tracked page view event', {
100
- eventName: eventName,
101
- attributes: attributes,
97
+ eventName,
98
+ attributes,
102
99
  });
103
100
  this.eventRecorder(eventName, attributes);
104
101
  }
105
- };
106
- PageViewTracker.prototype.urlHasChanged = function () {
107
- var prevUrl = sessionStorage.getItem(PREV_URL_STORAGE_KEY);
108
- var currUrl = this.options.urlProvider();
102
+ }
103
+ urlHasChanged() {
104
+ const prevUrl = sessionStorage.getItem(PREV_URL_STORAGE_KEY);
105
+ const currUrl = this.options.urlProvider();
109
106
  return currUrl !== prevUrl;
110
- };
111
- return PageViewTracker;
112
- }());
113
- export { PageViewTracker };
107
+ }
108
+ }
@@ -1,12 +1,10 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { sessionListener, } from '@aws-amplify/core/internals/utils';
3
+ import { sessionListener, SESSION_START_EVENT, SESSION_STOP_EVENT, } from '@aws-amplify/core/internals/utils';
4
4
  import { ConsoleLogger } from '@aws-amplify/core';
5
- var SESSION_START_EVENT = '_session.start';
6
- var SESSION_STOP_EVENT = '_session.stop';
7
- var logger = new ConsoleLogger('SessionTracker');
8
- var SessionTracker = /** @class */ (function () {
9
- function SessionTracker(eventRecorder, options) {
5
+ const logger = new ConsoleLogger('SessionTracker');
6
+ export class SessionTracker {
7
+ constructor(eventRecorder, options) {
10
8
  this.options = {};
11
9
  this.eventRecorder = eventRecorder;
12
10
  this.sessionTrackingActive = false;
@@ -14,57 +12,52 @@ var SessionTracker = /** @class */ (function () {
14
12
  this.handleStateChange = this.handleStateChange.bind(this);
15
13
  this.configure(eventRecorder, options);
16
14
  }
17
- SessionTracker.prototype.configure = function (eventRecorder, options) {
18
- var _a;
15
+ configure(eventRecorder, options) {
19
16
  this.eventRecorder = eventRecorder;
20
17
  // Clean up any existing listeners
21
18
  this.cleanup();
22
19
  // Apply defaults
23
20
  this.options = {
24
- attributes: (_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : {},
21
+ attributes: options?.attributes ?? {},
25
22
  };
26
23
  // Setup state listeners
27
24
  if (!this.sessionTrackingActive) {
28
25
  sessionListener.addStateChangeListener(this.handleStateChange, !this.initialEventSent);
29
26
  this.sessionTrackingActive = true;
30
27
  }
31
- };
32
- SessionTracker.prototype.cleanup = function () {
28
+ }
29
+ cleanup() {
33
30
  if (this.sessionTrackingActive) {
34
31
  sessionListener.removeStateChangeListener(this.handleStateChange);
35
32
  }
36
33
  this.sessionTrackingActive = false;
37
- };
38
- SessionTracker.prototype.handleStateChange = function (state) {
34
+ }
35
+ handleStateChange(state) {
39
36
  if (state === 'started') {
40
37
  this.sessionStarted();
41
38
  }
42
39
  else {
43
40
  this.sessionStopped();
44
41
  }
45
- };
46
- SessionTracker.prototype.sessionStarted = function () {
47
- var _a;
48
- var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
42
+ }
43
+ sessionStarted() {
44
+ const attributes = this.options.attributes ?? {};
49
45
  logger.debug('Recording automatically tracked page view event', {
50
- SESSION_START_EVENT: SESSION_START_EVENT,
51
- attributes: attributes,
46
+ SESSION_START_EVENT,
47
+ attributes,
52
48
  });
53
49
  this.eventRecorder(SESSION_START_EVENT, attributes);
54
50
  // NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
55
51
  if (!this.initialEventSent) {
56
52
  this.initialEventSent = true;
57
53
  }
58
- };
59
- SessionTracker.prototype.sessionStopped = function () {
60
- var _a;
61
- var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
54
+ }
55
+ sessionStopped() {
56
+ const attributes = this.options.attributes ?? {};
62
57
  logger.debug('Recording automatically tracked page view event', {
63
- SESSION_STOP_EVENT: SESSION_STOP_EVENT,
64
- attributes: attributes,
58
+ SESSION_STOP_EVENT,
59
+ attributes,
65
60
  });
66
61
  this.eventRecorder(SESSION_STOP_EVENT, attributes);
67
- };
68
- return SessionTracker;
69
- }());
70
- export { SessionTracker };
62
+ }
63
+ }
@@ -1,12 +1,10 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { sessionListener, } from '@aws-amplify/core/internals/utils';
3
+ import { sessionListener, SESSION_START_EVENT, SESSION_STOP_EVENT, } from '@aws-amplify/core/internals/utils';
4
4
  import { ConsoleLogger } from '@aws-amplify/core';
5
- var SESSION_START_EVENT = '_session.start';
6
- var SESSION_STOP_EVENT = '_session.stop';
7
- var logger = new ConsoleLogger('SessionTracker');
8
- var SessionTracker = /** @class */ (function () {
9
- function SessionTracker(eventRecorder, options) {
5
+ const logger = new ConsoleLogger('SessionTracker');
6
+ export class SessionTracker {
7
+ constructor(eventRecorder, options) {
10
8
  this.options = {};
11
9
  this.eventRecorder = eventRecorder;
12
10
  this.initialEventSent = false;
@@ -14,57 +12,52 @@ var SessionTracker = /** @class */ (function () {
14
12
  this.handleStateChange = this.handleStateChange.bind(this);
15
13
  this.configure(eventRecorder, options);
16
14
  }
17
- SessionTracker.prototype.configure = function (eventRecorder, options) {
18
- var _a;
15
+ configure(eventRecorder, options) {
19
16
  this.eventRecorder = eventRecorder;
20
17
  // Clean up any existing listeners
21
18
  this.cleanup();
22
19
  // Apply defaults
23
20
  this.options = {
24
- attributes: (_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : {},
21
+ attributes: options?.attributes ?? {},
25
22
  };
26
23
  // Setup state listeners
27
24
  if (!this.sessionTrackingActive) {
28
25
  sessionListener.addStateChangeListener(this.handleStateChange, !this.initialEventSent);
29
26
  this.sessionTrackingActive = true;
30
27
  }
31
- };
32
- SessionTracker.prototype.cleanup = function () {
28
+ }
29
+ cleanup() {
33
30
  if (this.sessionTrackingActive) {
34
31
  sessionListener.removeStateChangeListener(this.handleStateChange);
35
32
  }
36
33
  this.sessionTrackingActive = false;
37
- };
38
- SessionTracker.prototype.handleStateChange = function (state) {
34
+ }
35
+ handleStateChange(state) {
39
36
  if (state === 'started') {
40
37
  this.sessionStarted();
41
38
  }
42
39
  else {
43
40
  this.sessionStopped();
44
41
  }
45
- };
46
- SessionTracker.prototype.sessionStarted = function () {
47
- var _a;
48
- var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
42
+ }
43
+ sessionStarted() {
44
+ const attributes = this.options.attributes ?? {};
49
45
  logger.debug('Recording automatically tracked page view event', {
50
- SESSION_START_EVENT: SESSION_START_EVENT,
51
- attributes: attributes,
46
+ SESSION_START_EVENT,
47
+ attributes,
52
48
  });
53
49
  this.eventRecorder(SESSION_START_EVENT, attributes);
54
50
  // NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
55
51
  if (!this.initialEventSent) {
56
52
  this.initialEventSent = true;
57
53
  }
58
- };
59
- SessionTracker.prototype.sessionStopped = function () {
60
- var _a;
61
- var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
54
+ }
55
+ sessionStopped() {
56
+ const attributes = this.options.attributes ?? {};
62
57
  logger.debug('Recording automatically tracked page view event', {
63
- SESSION_STOP_EVENT: SESSION_STOP_EVENT,
64
- attributes: attributes,
58
+ SESSION_STOP_EVENT,
59
+ attributes,
65
60
  });
66
61
  this.eventRecorder(SESSION_STOP_EVENT, attributes);
67
- };
68
- return SessionTracker;
69
- }());
70
- export { SessionTracker };
62
+ }
63
+ }