@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
|
@@ -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
|
-
|
|
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
|
|
39
|
-
|
|
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(
|
|
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
|
|
49
|
+
appId,
|
|
51
50
|
category: 'Analytics',
|
|
52
|
-
credentials
|
|
51
|
+
credentials,
|
|
53
52
|
event: input,
|
|
54
|
-
identityId
|
|
55
|
-
region
|
|
53
|
+
identityId,
|
|
54
|
+
region,
|
|
56
55
|
userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
|
|
57
56
|
});
|
|
58
57
|
})
|
|
59
|
-
.catch(
|
|
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
|
|
9
|
-
|
|
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
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
};
|
package/lib-esm/setupTests.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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:
|
|
26
|
-
events:
|
|
27
|
-
selectorPrefix:
|
|
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
|
-
|
|
32
|
-
document.addEventListener(targetEvent,
|
|
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
|
-
|
|
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
|
-
|
|
48
|
-
document.removeEventListener(targetEvent,
|
|
43
|
+
this.options.events?.forEach(targetEvent => {
|
|
44
|
+
document.removeEventListener(targetEvent, this.handleDocEvent, {
|
|
49
45
|
capture: true,
|
|
50
46
|
});
|
|
51
47
|
});
|
|
52
|
-
}
|
|
53
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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 (!
|
|
66
|
+
if (!this.options.events?.includes(event.type)) {
|
|
72
67
|
return;
|
|
73
68
|
}
|
|
74
69
|
if (eventSource instanceof HTMLElement) {
|
|
75
|
-
|
|
70
|
+
const target = eventSource.closest(triggerSelector);
|
|
76
71
|
if (target) {
|
|
77
72
|
// Parse event name from the element
|
|
78
|
-
|
|
73
|
+
const eventName = target.getAttribute(eventNameSelector) || DEFAULT_EVENT_NAME;
|
|
79
74
|
// Parse attributes from the element
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
rawElementAttributes
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
82
|
+
const attributes = Object.assign({
|
|
88
83
|
type: event.type,
|
|
89
|
-
target:
|
|
90
|
-
}, this.options.attributes,
|
|
84
|
+
target: `${target.localName} with id ${target.id}`,
|
|
85
|
+
}, this.options.attributes, elementAttributes);
|
|
91
86
|
logger.debug('Recording automatically tracked DOM event', {
|
|
92
|
-
eventName
|
|
93
|
-
attributes
|
|
87
|
+
eventName,
|
|
88
|
+
attributes,
|
|
94
89
|
});
|
|
95
90
|
this.eventRecorder(eventName, attributes);
|
|
96
91
|
}
|
|
97
92
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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:
|
|
29
|
-
attributes:
|
|
30
|
-
eventName:
|
|
31
|
-
urlProvider:
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
52
|
+
this.pushStateProxy?.revoke();
|
|
53
|
+
this.replaceStateProxy?.revoke();
|
|
56
54
|
window.removeEventListener('popstate', this.handleLocationChange);
|
|
57
55
|
this.spaTrackingActive = false;
|
|
58
56
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
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:
|
|
66
|
-
|
|
67
|
-
|
|
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:
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
83
|
+
}
|
|
84
|
+
setupMPATracking() {
|
|
88
85
|
this.handleLocationChange();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
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
|
|
101
|
-
attributes
|
|
97
|
+
eventName,
|
|
98
|
+
attributes,
|
|
102
99
|
});
|
|
103
100
|
this.eventRecorder(eventName, attributes);
|
|
104
101
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
28
|
+
}
|
|
29
|
+
cleanup() {
|
|
33
30
|
if (this.sessionTrackingActive) {
|
|
34
31
|
sessionListener.removeStateChangeListener(this.handleStateChange);
|
|
35
32
|
}
|
|
36
33
|
this.sessionTrackingActive = false;
|
|
37
|
-
}
|
|
38
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
|
51
|
-
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
|
-
|
|
60
|
-
|
|
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
|
|
64
|
-
attributes
|
|
58
|
+
SESSION_STOP_EVENT,
|
|
59
|
+
attributes,
|
|
65
60
|
});
|
|
66
61
|
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
67
|
-
}
|
|
68
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
28
|
+
}
|
|
29
|
+
cleanup() {
|
|
33
30
|
if (this.sessionTrackingActive) {
|
|
34
31
|
sessionListener.removeStateChangeListener(this.handleStateChange);
|
|
35
32
|
}
|
|
36
33
|
this.sessionTrackingActive = false;
|
|
37
|
-
}
|
|
38
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
|
51
|
-
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
|
-
|
|
60
|
-
|
|
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
|
|
64
|
-
attributes
|
|
58
|
+
SESSION_STOP_EVENT,
|
|
59
|
+
attributes,
|
|
65
60
|
});
|
|
66
61
|
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}());
|
|
70
|
-
export { SessionTracker };
|
|
62
|
+
}
|
|
63
|
+
}
|