@aws-amplify/analytics 7.0.1-console-preview.8f82e46.0 → 7.0.1-console-preview.b278dcb.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/errors/validation.d.ts +2 -0
- package/lib/errors/validation.js +8 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/providers/kinesis/apis/flushEvents.js +2 -1
- package/lib/providers/kinesis/apis/record.js +2 -1
- package/lib/providers/kinesis-firehose/apis/flushEvents.js +2 -1
- package/lib/providers/kinesis-firehose/apis/record.js +2 -1
- package/lib/providers/personalize/apis/flushEvents.js +2 -1
- package/lib/providers/personalize/apis/record.js +2 -1
- package/lib/providers/personalize/utils/autoTrackMedia.js +2 -1
- package/lib/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib/providers/pinpoint/apis/configureAutoTrack.js +35 -0
- package/lib/providers/pinpoint/apis/flushEvents.js +2 -1
- package/lib/providers/pinpoint/apis/identifyUser.js +4 -5
- package/lib/providers/pinpoint/apis/index.d.ts +1 -0
- package/lib/providers/pinpoint/apis/index.js +3 -1
- package/lib/providers/pinpoint/apis/record.js +1 -1
- package/lib/providers/pinpoint/index.d.ts +2 -2
- package/lib/providers/pinpoint/index.js +2 -1
- package/lib/providers/pinpoint/types/index.d.ts +1 -2
- package/lib/providers/pinpoint/types/index.js +0 -3
- package/lib/providers/pinpoint/types/inputs.d.ts +5 -1
- package/lib/trackers/EventTracker.d.ts +10 -0
- package/lib/trackers/EventTracker.js +104 -0
- package/lib/trackers/PageViewTracker.d.ts +18 -0
- package/lib/trackers/PageViewTracker.js +116 -0
- package/lib/trackers/SessionTracker.d.ts +13 -0
- package/lib/trackers/SessionTracker.js +73 -0
- package/lib/trackers/SessionTracker.native.d.ts +13 -0
- package/lib/trackers/SessionTracker.native.js +73 -0
- package/lib/trackers/index.d.ts +3 -0
- package/lib/trackers/index.js +11 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +1 -2
- package/lib/types/inputs.d.ts +17 -3
- package/lib/types/options.d.ts +1 -1
- package/lib/types/trackers.d.ts +22 -0
- package/lib/utils/eventBuffer/EventBuffer.js +2 -2
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +5 -1
- package/lib/utils/trackerConfigHelpers.d.ts +5 -0
- package/lib/utils/trackerConfigHelpers.js +15 -0
- package/lib/utils/trackerConfigHelpers.native.d.ts +5 -0
- package/lib/utils/trackerConfigHelpers.native.js +14 -0
- package/lib/utils/trackerHelpers.d.ts +9 -0
- package/lib/utils/trackerHelpers.js +44 -0
- package/lib-esm/errors/validation.d.ts +2 -0
- package/lib-esm/errors/validation.js +8 -0
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/providers/kinesis/apis/flushEvents.js +2 -1
- package/lib-esm/providers/kinesis/apis/record.js +2 -1
- package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +2 -1
- package/lib-esm/providers/kinesis-firehose/apis/record.js +3 -2
- package/lib-esm/providers/personalize/apis/flushEvents.js +2 -1
- package/lib-esm/providers/personalize/apis/record.js +2 -1
- package/lib-esm/providers/personalize/utils/autoTrackMedia.js +2 -1
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +31 -0
- package/lib-esm/providers/pinpoint/apis/flushEvents.js +2 -1
- package/lib-esm/providers/pinpoint/apis/identifyUser.js +5 -6
- package/lib-esm/providers/pinpoint/apis/index.d.ts +1 -0
- package/lib-esm/providers/pinpoint/apis/index.js +1 -0
- package/lib-esm/providers/pinpoint/apis/record.js +3 -3
- package/lib-esm/providers/pinpoint/index.d.ts +2 -2
- package/lib-esm/providers/pinpoint/index.js +1 -1
- package/lib-esm/providers/pinpoint/types/index.d.ts +1 -2
- package/lib-esm/providers/pinpoint/types/index.js +1 -1
- package/lib-esm/providers/pinpoint/types/inputs.d.ts +5 -1
- package/lib-esm/trackers/EventTracker.d.ts +10 -0
- package/lib-esm/trackers/EventTracker.js +101 -0
- package/lib-esm/trackers/PageViewTracker.d.ts +18 -0
- package/lib-esm/trackers/PageViewTracker.js +113 -0
- package/lib-esm/trackers/SessionTracker.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.js +70 -0
- package/lib-esm/trackers/SessionTracker.native.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.native.js +70 -0
- package/lib-esm/trackers/index.d.ts +3 -0
- package/lib-esm/trackers/index.js +5 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +1 -2
- package/lib-esm/types/inputs.d.ts +17 -3
- package/lib-esm/types/options.d.ts +1 -1
- package/lib-esm/types/trackers.d.ts +22 -0
- package/lib-esm/utils/eventBuffer/EventBuffer.js +1 -1
- package/lib-esm/utils/index.d.ts +2 -0
- package/lib-esm/utils/index.js +2 -0
- package/lib-esm/utils/trackerConfigHelpers.d.ts +5 -0
- package/lib-esm/utils/trackerConfigHelpers.js +11 -0
- package/lib-esm/utils/trackerConfigHelpers.native.d.ts +5 -0
- package/lib-esm/utils/trackerConfigHelpers.native.js +10 -0
- package/lib-esm/utils/trackerHelpers.d.ts +9 -0
- package/lib-esm/utils/trackerHelpers.js +40 -0
- package/package.json +5 -4
- package/src/errors/validation.ts +8 -0
- package/src/index.ts +3 -1
- package/src/providers/kinesis/apis/flushEvents.ts +2 -4
- package/src/providers/kinesis/apis/record.ts +2 -4
- package/src/providers/kinesis-firehose/apis/flushEvents.ts +2 -4
- package/src/providers/kinesis-firehose/apis/record.ts +3 -5
- package/src/providers/personalize/apis/flushEvents.ts +2 -4
- package/src/providers/personalize/apis/record.ts +2 -4
- package/src/providers/personalize/utils/autoTrackMedia.ts +2 -1
- package/src/providers/pinpoint/apis/configureAutoTrack.ts +49 -0
- package/src/providers/pinpoint/apis/flushEvents.ts +2 -4
- package/src/providers/pinpoint/apis/identifyUser.ts +6 -3
- package/src/providers/pinpoint/apis/index.ts +1 -0
- package/src/providers/pinpoint/apis/record.ts +2 -3
- package/src/providers/pinpoint/index.ts +6 -2
- package/src/providers/pinpoint/types/index.ts +5 -2
- package/src/providers/pinpoint/types/inputs.ts +9 -1
- package/src/trackers/EventTracker.ts +135 -0
- package/src/trackers/PageViewTracker.ts +160 -0
- package/src/trackers/SessionTracker.native.ts +106 -0
- package/src/trackers/SessionTracker.ts +106 -0
- package/src/trackers/index.ts +6 -0
- package/src/types/index.ts +4 -13
- package/src/types/inputs.ts +26 -3
- package/src/types/options.ts +1 -1
- package/src/types/trackers.ts +35 -0
- package/src/utils/eventBuffer/EventBuffer.ts +1 -1
- package/src/utils/index.ts +2 -0
- package/src/utils/trackerConfigHelpers.native.ts +18 -0
- package/src/utils/trackerConfigHelpers.ts +19 -0
- package/src/utils/trackerHelpers.ts +57 -0
- package/lib/providers/pinpoint/types/errors.d.ts +0 -9
- package/lib/providers/pinpoint/types/errors.js +0 -15
- package/lib/types/analytics.d.ts +0 -50
- package/lib-esm/providers/pinpoint/types/errors.d.ts +0 -9
- package/lib-esm/providers/pinpoint/types/errors.js +0 -12
- package/lib-esm/types/analytics.d.ts +0 -50
- package/src/providers/pinpoint/types/errors.ts +0 -12
- package/src/types/analytics.ts +0 -70
- /package/lib/types/{analytics.js → trackers.js} +0 -0
- /package/lib-esm/types/{analytics.js → trackers.js} +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
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 () {
|
|
9
|
+
return window.location.origin + window.location.pathname;
|
|
10
|
+
};
|
|
11
|
+
var PREV_URL_STORAGE_KEY = 'aws-amplify-analytics-prevUrl';
|
|
12
|
+
var PageViewTracker = /** @class */ (function () {
|
|
13
|
+
function PageViewTracker(eventRecorder, options) {
|
|
14
|
+
this.options = {};
|
|
15
|
+
this.trackerActive = true;
|
|
16
|
+
this.eventRecorder = eventRecorder;
|
|
17
|
+
this.spaTrackingActive = false;
|
|
18
|
+
this.handleLocationChange = this.handleLocationChange.bind(this);
|
|
19
|
+
this.configure(eventRecorder, options);
|
|
20
|
+
}
|
|
21
|
+
PageViewTracker.prototype.configure = function (eventRecorder, options) {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f;
|
|
23
|
+
this.eventRecorder = eventRecorder;
|
|
24
|
+
// Clean up any existing listeners
|
|
25
|
+
this.cleanup();
|
|
26
|
+
// Apply defaults
|
|
27
|
+
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,
|
|
32
|
+
};
|
|
33
|
+
// Configure SPA or MPA page view tracking
|
|
34
|
+
if (isBrowser()) {
|
|
35
|
+
if (this.options.appType === 'singlePage') {
|
|
36
|
+
this.setupSPATracking();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.setupMPATracking();
|
|
40
|
+
}
|
|
41
|
+
this.trackerActive = true;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
PageViewTracker.prototype.cleanup = function () {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
// No-op if document listener is not active
|
|
47
|
+
if (!this.trackerActive) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Clean up SPA page view listeners
|
|
51
|
+
if (this.spaTrackingActive) {
|
|
52
|
+
window.history.pushState = this.originalPushState;
|
|
53
|
+
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();
|
|
56
|
+
window.removeEventListener('popstate', this.handleLocationChange);
|
|
57
|
+
this.spaTrackingActive = false;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
PageViewTracker.prototype.setupSPATracking = function () {
|
|
61
|
+
var _this = this;
|
|
62
|
+
if (!this.spaTrackingActive) {
|
|
63
|
+
// Configure proxies on History APIs
|
|
64
|
+
this.pushStateProxy = Proxy.revocable(window.history.pushState, {
|
|
65
|
+
apply: function (target, thisArg, args) {
|
|
66
|
+
var proxiedResult = target.apply(thisArg, args);
|
|
67
|
+
_this.handleLocationChange();
|
|
68
|
+
return proxiedResult;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
this.replaceStateProxy = Proxy.revocable(window.history.replaceState, {
|
|
72
|
+
apply: function (target, thisArg, args) {
|
|
73
|
+
var proxiedResult = target.apply(thisArg, args);
|
|
74
|
+
_this.handleLocationChange();
|
|
75
|
+
return proxiedResult;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
this.originalPushState = window.history.pushState;
|
|
79
|
+
this.originalReplaceState = window.history.replaceState;
|
|
80
|
+
window.history.pushState = this.pushStateProxy.proxy;
|
|
81
|
+
window.history.replaceState = this.replaceStateProxy.proxy;
|
|
82
|
+
window.addEventListener('popstate', this.handleLocationChange);
|
|
83
|
+
sessionStorage.removeItem(PREV_URL_STORAGE_KEY);
|
|
84
|
+
this.spaTrackingActive = true;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
PageViewTracker.prototype.setupMPATracking = function () {
|
|
88
|
+
this.handleLocationChange();
|
|
89
|
+
};
|
|
90
|
+
PageViewTracker.prototype.handleLocationChange = function () {
|
|
91
|
+
var currentUrl = this.options.urlProvider();
|
|
92
|
+
var eventName = this.options.eventName || DEFAULT_EVENT_NAME;
|
|
93
|
+
if (this.urlHasChanged()) {
|
|
94
|
+
sessionStorage.setItem(PREV_URL_STORAGE_KEY, currentUrl);
|
|
95
|
+
// Assemble attribute list
|
|
96
|
+
var attributes = Object.assign({
|
|
97
|
+
url: currentUrl,
|
|
98
|
+
}, this.options.attributes);
|
|
99
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
100
|
+
eventName: eventName,
|
|
101
|
+
attributes: attributes,
|
|
102
|
+
});
|
|
103
|
+
this.eventRecorder(eventName, attributes);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
PageViewTracker.prototype.urlHasChanged = function () {
|
|
107
|
+
var prevUrl = sessionStorage.getItem(PREV_URL_STORAGE_KEY);
|
|
108
|
+
var currUrl = this.options.urlProvider();
|
|
109
|
+
return currUrl !== prevUrl;
|
|
110
|
+
};
|
|
111
|
+
return PageViewTracker;
|
|
112
|
+
}());
|
|
113
|
+
export { PageViewTracker };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SessionTrackingOptions, TrackerEventRecorder, TrackerInterface } from '../types/trackers';
|
|
2
|
+
export declare class SessionTracker implements TrackerInterface {
|
|
3
|
+
private options;
|
|
4
|
+
private eventRecorder;
|
|
5
|
+
private sessionTrackingActive;
|
|
6
|
+
private initialEventSent;
|
|
7
|
+
constructor(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions);
|
|
8
|
+
configure(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions): void;
|
|
9
|
+
cleanup(): void;
|
|
10
|
+
private handleStateChange;
|
|
11
|
+
private sessionStarted;
|
|
12
|
+
private sessionStopped;
|
|
13
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { sessionListener, } from '@aws-amplify/core/internals/utils';
|
|
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) {
|
|
10
|
+
this.options = {};
|
|
11
|
+
this.eventRecorder = eventRecorder;
|
|
12
|
+
this.sessionTrackingActive = false;
|
|
13
|
+
this.initialEventSent = false;
|
|
14
|
+
this.handleStateChange = this.handleStateChange.bind(this);
|
|
15
|
+
this.configure(eventRecorder, options);
|
|
16
|
+
}
|
|
17
|
+
SessionTracker.prototype.configure = function (eventRecorder, options) {
|
|
18
|
+
var _a;
|
|
19
|
+
this.eventRecorder = eventRecorder;
|
|
20
|
+
// Clean up any existing listeners
|
|
21
|
+
this.cleanup();
|
|
22
|
+
// Apply defaults
|
|
23
|
+
this.options = {
|
|
24
|
+
attributes: (_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : {},
|
|
25
|
+
};
|
|
26
|
+
// Setup state listeners
|
|
27
|
+
if (!this.sessionTrackingActive) {
|
|
28
|
+
sessionListener.addStateChangeListener(this.handleStateChange, !this.initialEventSent);
|
|
29
|
+
this.sessionTrackingActive = true;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
SessionTracker.prototype.cleanup = function () {
|
|
33
|
+
if (this.sessionTrackingActive) {
|
|
34
|
+
sessionListener.removeStateChangeListener(this.handleStateChange);
|
|
35
|
+
}
|
|
36
|
+
this.sessionTrackingActive = false;
|
|
37
|
+
};
|
|
38
|
+
SessionTracker.prototype.handleStateChange = function (state) {
|
|
39
|
+
if (state === 'started') {
|
|
40
|
+
this.sessionStarted();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.sessionStopped();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
SessionTracker.prototype.sessionStarted = function () {
|
|
47
|
+
var _a;
|
|
48
|
+
var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
|
|
49
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
50
|
+
SESSION_START_EVENT: SESSION_START_EVENT,
|
|
51
|
+
attributes: attributes,
|
|
52
|
+
});
|
|
53
|
+
this.eventRecorder(SESSION_START_EVENT, attributes);
|
|
54
|
+
// NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
|
|
55
|
+
if (!this.initialEventSent) {
|
|
56
|
+
this.initialEventSent = true;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
SessionTracker.prototype.sessionStopped = function () {
|
|
60
|
+
var _a;
|
|
61
|
+
var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
|
|
62
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
63
|
+
SESSION_STOP_EVENT: SESSION_STOP_EVENT,
|
|
64
|
+
attributes: attributes,
|
|
65
|
+
});
|
|
66
|
+
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
67
|
+
};
|
|
68
|
+
return SessionTracker;
|
|
69
|
+
}());
|
|
70
|
+
export { SessionTracker };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SessionTrackingOptions, TrackerEventRecorder, TrackerInterface } from '../types/trackers';
|
|
2
|
+
export declare class SessionTracker implements TrackerInterface {
|
|
3
|
+
private options;
|
|
4
|
+
private eventRecorder;
|
|
5
|
+
private initialEventSent;
|
|
6
|
+
private sessionTrackingActive;
|
|
7
|
+
constructor(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions);
|
|
8
|
+
configure(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions): void;
|
|
9
|
+
cleanup(): void;
|
|
10
|
+
private handleStateChange;
|
|
11
|
+
private sessionStarted;
|
|
12
|
+
private sessionStopped;
|
|
13
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { sessionListener, } from '@aws-amplify/core/internals/utils';
|
|
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) {
|
|
10
|
+
this.options = {};
|
|
11
|
+
this.eventRecorder = eventRecorder;
|
|
12
|
+
this.initialEventSent = false;
|
|
13
|
+
this.sessionTrackingActive = false;
|
|
14
|
+
this.handleStateChange = this.handleStateChange.bind(this);
|
|
15
|
+
this.configure(eventRecorder, options);
|
|
16
|
+
}
|
|
17
|
+
SessionTracker.prototype.configure = function (eventRecorder, options) {
|
|
18
|
+
var _a;
|
|
19
|
+
this.eventRecorder = eventRecorder;
|
|
20
|
+
// Clean up any existing listeners
|
|
21
|
+
this.cleanup();
|
|
22
|
+
// Apply defaults
|
|
23
|
+
this.options = {
|
|
24
|
+
attributes: (_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : {},
|
|
25
|
+
};
|
|
26
|
+
// Setup state listeners
|
|
27
|
+
if (!this.sessionTrackingActive) {
|
|
28
|
+
sessionListener.addStateChangeListener(this.handleStateChange, !this.initialEventSent);
|
|
29
|
+
this.sessionTrackingActive = true;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
SessionTracker.prototype.cleanup = function () {
|
|
33
|
+
if (this.sessionTrackingActive) {
|
|
34
|
+
sessionListener.removeStateChangeListener(this.handleStateChange);
|
|
35
|
+
}
|
|
36
|
+
this.sessionTrackingActive = false;
|
|
37
|
+
};
|
|
38
|
+
SessionTracker.prototype.handleStateChange = function (state) {
|
|
39
|
+
if (state === 'started') {
|
|
40
|
+
this.sessionStarted();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.sessionStopped();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
SessionTracker.prototype.sessionStarted = function () {
|
|
47
|
+
var _a;
|
|
48
|
+
var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
|
|
49
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
50
|
+
SESSION_START_EVENT: SESSION_START_EVENT,
|
|
51
|
+
attributes: attributes,
|
|
52
|
+
});
|
|
53
|
+
this.eventRecorder(SESSION_START_EVENT, attributes);
|
|
54
|
+
// NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
|
|
55
|
+
if (!this.initialEventSent) {
|
|
56
|
+
this.initialEventSent = true;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
SessionTracker.prototype.sessionStopped = function () {
|
|
60
|
+
var _a;
|
|
61
|
+
var attributes = (_a = this.options.attributes) !== null && _a !== void 0 ? _a : {};
|
|
62
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
63
|
+
SESSION_STOP_EVENT: SESSION_STOP_EVENT,
|
|
64
|
+
attributes: attributes,
|
|
65
|
+
});
|
|
66
|
+
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
67
|
+
};
|
|
68
|
+
return SessionTracker;
|
|
69
|
+
}());
|
|
70
|
+
export { SessionTracker };
|