@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.
- package/lib/apis/disable.js +1 -1
- package/lib/apis/enable.js +1 -1
- package/lib/errors/AnalyticsError.js +7 -11
- package/lib/errors/assertValidationError.js +6 -6
- package/lib/errors/validation.js +10 -11
- package/lib/providers/kinesis/apis/flushEvents.js +20 -23
- package/lib/providers/kinesis/apis/record.js +24 -26
- package/lib/providers/kinesis/utils/getEventBuffer.js +39 -70
- package/lib/providers/kinesis/utils/resolveConfig.js +14 -13
- package/lib/providers/kinesis-firehose/apis/flushEvents.js +19 -22
- package/lib/providers/kinesis-firehose/apis/record.js +22 -24
- package/lib/providers/kinesis-firehose/utils/getEventBuffer.js +39 -68
- package/lib/providers/kinesis-firehose/utils/resolveConfig.js +14 -13
- package/lib/providers/personalize/apis/flushEvents.js +18 -21
- package/lib/providers/personalize/apis/record.js +55 -71
- package/lib/providers/personalize/utils/autoTrackMedia.js +96 -98
- package/lib/providers/personalize/utils/cachedSession.js +30 -42
- package/lib/providers/personalize/utils/getEventBuffer.js +35 -62
- package/lib/providers/personalize/utils/resolveConfig.js +14 -13
- package/lib/providers/pinpoint/apis/configureAutoTrack.js +6 -6
- package/lib/providers/pinpoint/apis/flushEvents.js +10 -13
- package/lib/providers/pinpoint/apis/identifyUser.js +18 -30
- package/lib/providers/pinpoint/apis/record.js +15 -16
- package/lib/providers/pinpoint/utils/resolveConfig.js +5 -6
- package/lib/providers/pinpoint/utils/resolveCredentials.js +7 -15
- package/lib/setupTests.js +1 -1
- package/lib/trackers/EventTracker.js +39 -45
- package/lib/trackers/PageViewTracker.js +41 -45
- package/lib/trackers/SessionTracker.js +25 -31
- package/lib/trackers/SessionTracker.native.js +25 -31
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/eventBuffer/EventBuffer.js +34 -62
- package/lib/utils/groupBy.js +4 -7
- package/lib/utils/resolveCredentials.js +7 -15
- package/lib/utils/statusHelpers.js +4 -4
- package/lib/utils/trackerConfigHelpers.js +2 -2
- package/lib/utils/trackerConfigHelpers.native.js +2 -2
- package/lib/utils/trackerHelpers.js +5 -5
- package/lib/utils/userAgent.js +3 -3
- package/lib-esm/apis/disable.js +1 -1
- package/lib-esm/apis/enable.js +1 -1
- package/lib-esm/errors/AnalyticsError.js +6 -11
- package/lib-esm/errors/assertValidationError.js +4 -4
- package/lib-esm/errors/validation.js +10 -11
- package/lib-esm/providers/kinesis/apis/flushEvents.js +15 -18
- package/lib-esm/providers/kinesis/apis/record.js +18 -20
- package/lib-esm/providers/kinesis/utils/constants.js +1 -1
- package/lib-esm/providers/kinesis/utils/getEventBuffer.js +37 -68
- package/lib-esm/providers/kinesis/utils/resolveConfig.js +11 -10
- package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +15 -18
- package/lib-esm/providers/kinesis-firehose/apis/record.js +17 -19
- package/lib-esm/providers/kinesis-firehose/utils/constants.js +1 -1
- package/lib-esm/providers/kinesis-firehose/utils/getEventBuffer.js +37 -66
- package/lib-esm/providers/kinesis-firehose/utils/resolveConfig.js +11 -10
- package/lib-esm/providers/personalize/apis/flushEvents.js +14 -17
- package/lib-esm/providers/personalize/apis/record.js +50 -66
- package/lib-esm/providers/personalize/utils/autoTrackMedia.js +94 -96
- package/lib-esm/providers/personalize/utils/cachedSession.js +28 -40
- package/lib-esm/providers/personalize/utils/constants.js +4 -4
- package/lib-esm/providers/personalize/utils/getEventBuffer.js +33 -60
- package/lib-esm/providers/personalize/utils/resolveConfig.js +11 -10
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +4 -4
- package/lib-esm/providers/pinpoint/apis/flushEvents.js +5 -8
- package/lib-esm/providers/pinpoint/apis/identifyUser.js +14 -26
- package/lib-esm/providers/pinpoint/apis/record.js +9 -10
- package/lib-esm/providers/pinpoint/utils/resolveConfig.js +3 -4
- package/lib-esm/providers/pinpoint/utils/resolveCredentials.js +5 -13
- package/lib-esm/setupTests.js +1 -1
- package/lib-esm/trackers/EventTracker.js +37 -44
- package/lib-esm/trackers/PageViewTracker.js +39 -44
- package/lib-esm/trackers/SessionTracker.js +22 -29
- package/lib-esm/trackers/SessionTracker.native.js +22 -29
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/utils/eventBuffer/EventBuffer.js +33 -62
- package/lib-esm/utils/groupBy.js +4 -7
- package/lib-esm/utils/resolveCredentials.js +5 -13
- package/lib-esm/utils/statusHelpers.js +4 -4
- package/lib-esm/utils/trackerConfigHelpers.js +1 -1
- package/lib-esm/utils/trackerConfigHelpers.native.js +1 -1
- package/lib-esm/utils/trackerHelpers.js +4 -4
- package/lib-esm/utils/userAgent.js +2 -2
- package/package.json +6 -9
- package/src/providers/kinesis/utils/getEventBuffer.ts +6 -7
- package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +6 -7
- package/src/providers/personalize/utils/getEventBuffer.ts +6 -7
- package/src/trackers/SessionTracker.native.ts +2 -3
- 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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:
|
|
29
|
-
events:
|
|
30
|
-
selectorPrefix:
|
|
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
|
-
|
|
35
|
-
document.addEventListener(targetEvent,
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
document.removeEventListener(targetEvent,
|
|
46
|
+
this.options.events?.forEach(targetEvent => {
|
|
47
|
+
document.removeEventListener(targetEvent, this.handleDocEvent, {
|
|
52
48
|
capture: true,
|
|
53
49
|
});
|
|
54
50
|
});
|
|
55
|
-
}
|
|
56
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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 (!
|
|
69
|
+
if (!this.options.events?.includes(event.type)) {
|
|
75
70
|
return;
|
|
76
71
|
}
|
|
77
72
|
if (eventSource instanceof HTMLElement) {
|
|
78
|
-
|
|
73
|
+
const target = eventSource.closest(triggerSelector);
|
|
79
74
|
if (target) {
|
|
80
75
|
// Parse event name from the element
|
|
81
|
-
|
|
76
|
+
const eventName = target.getAttribute(eventNameSelector) || DEFAULT_EVENT_NAME;
|
|
82
77
|
// Parse attributes from the element
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
rawElementAttributes
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
85
|
+
const attributes = Object.assign({
|
|
91
86
|
type: event.type,
|
|
92
|
-
target:
|
|
93
|
-
}, this.options.attributes,
|
|
87
|
+
target: `${target.localName} with id ${target.id}`,
|
|
88
|
+
}, this.options.attributes, elementAttributes);
|
|
94
89
|
logger.debug('Recording automatically tracked DOM event', {
|
|
95
|
-
eventName
|
|
96
|
-
attributes
|
|
90
|
+
eventName,
|
|
91
|
+
attributes,
|
|
97
92
|
});
|
|
98
93
|
this.eventRecorder(eventName, attributes);
|
|
99
94
|
}
|
|
100
95
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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:
|
|
32
|
-
attributes:
|
|
33
|
-
eventName:
|
|
34
|
-
urlProvider:
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
55
|
+
this.pushStateProxy?.revoke();
|
|
56
|
+
this.replaceStateProxy?.revoke();
|
|
59
57
|
window.removeEventListener('popstate', this.handleLocationChange);
|
|
60
58
|
this.spaTrackingActive = false;
|
|
61
59
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
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:
|
|
69
|
-
|
|
70
|
-
|
|
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:
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
86
|
+
}
|
|
87
|
+
setupMPATracking() {
|
|
91
88
|
this.handleLocationChange();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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
|
|
104
|
-
attributes
|
|
100
|
+
eventName,
|
|
101
|
+
attributes,
|
|
105
102
|
});
|
|
106
103
|
this.eventRecorder(eventName, attributes);
|
|
107
104
|
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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
|
|
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
|
-
|
|
63
|
-
|
|
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
|
|
61
|
+
SESSION_STOP_EVENT: utils_1.SESSION_STOP_EVENT,
|
|
62
|
+
attributes,
|
|
68
63
|
});
|
|
69
|
-
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
70
|
-
}
|
|
71
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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
|
|
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
|
-
|
|
63
|
-
|
|
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
|
|
61
|
+
SESSION_STOP_EVENT: utils_1.SESSION_STOP_EVENT,
|
|
62
|
+
attributes,
|
|
68
63
|
});
|
|
69
|
-
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
}());
|
|
64
|
+
this.eventRecorder(utils_1.SESSION_STOP_EVENT, attributes);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
73
67
|
exports.SessionTracker = SessionTracker;
|