@aws-amplify/analytics 7.0.1-console-preview.8d88eef.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/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib/providers/pinpoint/apis/configureAutoTrack.js +35 -0
- package/lib/providers/pinpoint/apis/index.d.ts +1 -0
- package/lib/providers/pinpoint/apis/index.js +3 -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 -1
- 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 +16 -0
- package/lib/types/trackers.d.ts +22 -0
- 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/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +31 -0
- 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 +1 -1
- 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 -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 +16 -0
- package/lib-esm/types/trackers.d.ts +22 -0
- 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/pinpoint/apis/configureAutoTrack.ts +49 -0
- package/src/providers/pinpoint/apis/index.ts +1 -0
- package/src/providers/pinpoint/apis/record.ts +1 -1
- package/src/providers/pinpoint/index.ts +6 -2
- package/src/providers/pinpoint/types/index.ts +5 -1
- 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 +25 -0
- package/src/types/trackers.ts +35 -0
- 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/types/analytics.d.ts +0 -50
- package/lib-esm/types/analytics.d.ts +0 -50
- 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,106 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
sessionListener,
|
|
6
|
+
SessionState,
|
|
7
|
+
} from '@aws-amplify/core/internals/utils';
|
|
8
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
9
|
+
import {
|
|
10
|
+
SessionTrackingOptions,
|
|
11
|
+
TrackerEventRecorder,
|
|
12
|
+
TrackerInterface,
|
|
13
|
+
} from '../types/trackers';
|
|
14
|
+
|
|
15
|
+
const SESSION_START_EVENT = '_session.start';
|
|
16
|
+
const SESSION_STOP_EVENT = '_session.stop';
|
|
17
|
+
|
|
18
|
+
const logger = new ConsoleLogger('SessionTracker');
|
|
19
|
+
|
|
20
|
+
export class SessionTracker implements TrackerInterface {
|
|
21
|
+
private options: SessionTrackingOptions;
|
|
22
|
+
private eventRecorder: TrackerEventRecorder;
|
|
23
|
+
private initialEventSent: boolean;
|
|
24
|
+
private sessionTrackingActive: boolean;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
eventRecorder: TrackerEventRecorder,
|
|
28
|
+
options?: SessionTrackingOptions
|
|
29
|
+
) {
|
|
30
|
+
this.options = {};
|
|
31
|
+
this.eventRecorder = eventRecorder;
|
|
32
|
+
this.initialEventSent = false;
|
|
33
|
+
this.sessionTrackingActive = false;
|
|
34
|
+
this.handleStateChange = this.handleStateChange.bind(this);
|
|
35
|
+
|
|
36
|
+
this.configure(eventRecorder, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public configure(
|
|
40
|
+
eventRecorder: TrackerEventRecorder,
|
|
41
|
+
options?: SessionTrackingOptions
|
|
42
|
+
) {
|
|
43
|
+
this.eventRecorder = eventRecorder;
|
|
44
|
+
|
|
45
|
+
// Clean up any existing listeners
|
|
46
|
+
this.cleanup();
|
|
47
|
+
|
|
48
|
+
// Apply defaults
|
|
49
|
+
this.options = {
|
|
50
|
+
attributes: options?.attributes ?? {},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Setup state listeners
|
|
54
|
+
if (!this.sessionTrackingActive) {
|
|
55
|
+
sessionListener.addStateChangeListener(
|
|
56
|
+
this.handleStateChange,
|
|
57
|
+
!this.initialEventSent
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
this.sessionTrackingActive = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public cleanup() {
|
|
65
|
+
if (this.sessionTrackingActive) {
|
|
66
|
+
sessionListener.removeStateChangeListener(this.handleStateChange);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.sessionTrackingActive = false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private handleStateChange(state: SessionState) {
|
|
73
|
+
if (state === 'started') {
|
|
74
|
+
this.sessionStarted();
|
|
75
|
+
} else {
|
|
76
|
+
this.sessionStopped();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private sessionStarted() {
|
|
81
|
+
const attributes = this.options.attributes ?? {};
|
|
82
|
+
|
|
83
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
84
|
+
SESSION_START_EVENT,
|
|
85
|
+
attributes,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
this.eventRecorder(SESSION_START_EVENT, attributes);
|
|
89
|
+
|
|
90
|
+
// NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
|
|
91
|
+
if (!this.initialEventSent) {
|
|
92
|
+
this.initialEventSent = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private sessionStopped() {
|
|
97
|
+
const attributes = this.options.attributes ?? {};
|
|
98
|
+
|
|
99
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
100
|
+
SESSION_STOP_EVENT,
|
|
101
|
+
attributes,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
sessionListener,
|
|
6
|
+
SessionState,
|
|
7
|
+
} from '@aws-amplify/core/internals/utils';
|
|
8
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
9
|
+
import {
|
|
10
|
+
SessionTrackingOptions,
|
|
11
|
+
TrackerEventRecorder,
|
|
12
|
+
TrackerInterface,
|
|
13
|
+
} from '../types/trackers';
|
|
14
|
+
|
|
15
|
+
const SESSION_START_EVENT = '_session.start';
|
|
16
|
+
const SESSION_STOP_EVENT = '_session.stop';
|
|
17
|
+
|
|
18
|
+
const logger = new ConsoleLogger('SessionTracker');
|
|
19
|
+
|
|
20
|
+
export class SessionTracker implements TrackerInterface {
|
|
21
|
+
private options: SessionTrackingOptions;
|
|
22
|
+
private eventRecorder: TrackerEventRecorder;
|
|
23
|
+
private sessionTrackingActive: boolean;
|
|
24
|
+
private initialEventSent: boolean;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
eventRecorder: TrackerEventRecorder,
|
|
28
|
+
options?: SessionTrackingOptions
|
|
29
|
+
) {
|
|
30
|
+
this.options = {};
|
|
31
|
+
this.eventRecorder = eventRecorder;
|
|
32
|
+
this.sessionTrackingActive = false;
|
|
33
|
+
this.initialEventSent = false;
|
|
34
|
+
this.handleStateChange = this.handleStateChange.bind(this);
|
|
35
|
+
|
|
36
|
+
this.configure(eventRecorder, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public configure(
|
|
40
|
+
eventRecorder: TrackerEventRecorder,
|
|
41
|
+
options?: SessionTrackingOptions
|
|
42
|
+
) {
|
|
43
|
+
this.eventRecorder = eventRecorder;
|
|
44
|
+
|
|
45
|
+
// Clean up any existing listeners
|
|
46
|
+
this.cleanup();
|
|
47
|
+
|
|
48
|
+
// Apply defaults
|
|
49
|
+
this.options = {
|
|
50
|
+
attributes: options?.attributes ?? {},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Setup state listeners
|
|
54
|
+
if (!this.sessionTrackingActive) {
|
|
55
|
+
sessionListener.addStateChangeListener(
|
|
56
|
+
this.handleStateChange,
|
|
57
|
+
!this.initialEventSent
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
this.sessionTrackingActive = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public cleanup() {
|
|
65
|
+
if (this.sessionTrackingActive) {
|
|
66
|
+
sessionListener.removeStateChangeListener(this.handleStateChange);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.sessionTrackingActive = false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private handleStateChange(state: SessionState) {
|
|
73
|
+
if (state === 'started') {
|
|
74
|
+
this.sessionStarted();
|
|
75
|
+
} else {
|
|
76
|
+
this.sessionStopped();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private sessionStarted() {
|
|
81
|
+
const attributes = this.options.attributes ?? {};
|
|
82
|
+
|
|
83
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
84
|
+
SESSION_START_EVENT,
|
|
85
|
+
attributes,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
this.eventRecorder(SESSION_START_EVENT, attributes);
|
|
89
|
+
|
|
90
|
+
// NOTE: The initial event will not be re-sent on re-configuration (e.g. to add additional custom attributes)
|
|
91
|
+
if (!this.initialEventSent) {
|
|
92
|
+
this.initialEventSent = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private sessionStopped() {
|
|
97
|
+
const attributes = this.options.attributes ?? {};
|
|
98
|
+
|
|
99
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
100
|
+
SESSION_STOP_EVENT,
|
|
101
|
+
attributes,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
this.eventRecorder(SESSION_STOP_EVENT, attributes);
|
|
105
|
+
}
|
|
106
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export {
|
|
5
|
-
AutoTrackAttributes,
|
|
6
|
-
AutoTrackEventOpts,
|
|
7
|
-
AutoTrackPageViewOpts,
|
|
8
|
-
AutoTrackSessionOpts,
|
|
9
|
-
EventAttributes,
|
|
10
|
-
EventMetrics,
|
|
11
|
-
EventTrackOpts,
|
|
12
|
-
PageViewTrackOpts,
|
|
13
|
-
SessionTrackOpts,
|
|
14
|
-
} from './analytics';
|
|
15
|
-
|
|
16
4
|
export { AnalyticsServiceOptions } from './options';
|
|
17
5
|
|
|
18
|
-
export {
|
|
6
|
+
export {
|
|
7
|
+
AnalyticsConfigureAutoTrackInput,
|
|
8
|
+
AnalyticsIdentifyUserInput,
|
|
9
|
+
} from './inputs';
|
|
19
10
|
|
|
20
11
|
export { KinesisStream, KinesisShard, KinesisEventData } from './kinesis';
|
package/src/types/inputs.ts
CHANGED
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import { UserProfile } from '@aws-amplify/core';
|
|
5
5
|
import { AnalyticsServiceOptions } from '.';
|
|
6
|
+
import {
|
|
7
|
+
SessionTrackingOptions,
|
|
8
|
+
PageViewTrackingOptions,
|
|
9
|
+
EventTrackingOptions,
|
|
10
|
+
} from './trackers';
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* Input type for `identifyUser`.
|
|
@@ -25,3 +30,23 @@ export type AnalyticsIdentifyUserInput<
|
|
|
25
30
|
*/
|
|
26
31
|
options?: ServiceOptions;
|
|
27
32
|
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Input type for `configureAutoTrack`.
|
|
36
|
+
*/
|
|
37
|
+
export type AnalyticsConfigureAutoTrackInput = {
|
|
38
|
+
enable: boolean;
|
|
39
|
+
} & (
|
|
40
|
+
| {
|
|
41
|
+
type: 'session';
|
|
42
|
+
options?: SessionTrackingOptions;
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
type: 'pageView';
|
|
46
|
+
options?: PageViewTrackingOptions;
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
type: 'event';
|
|
50
|
+
options?: EventTrackingOptions;
|
|
51
|
+
}
|
|
52
|
+
);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export type SessionTrackingOptions = {
|
|
5
|
+
attributes?: TrackerAttributes;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type PageViewTrackingOptions = {
|
|
9
|
+
attributes?: TrackerAttributes;
|
|
10
|
+
eventName?: string;
|
|
11
|
+
urlProvider?: () => string;
|
|
12
|
+
appType?: 'multiPage' | 'singlePage';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type EventTrackingOptions = {
|
|
16
|
+
attributes?: TrackerAttributes;
|
|
17
|
+
events?: DOMEvent[];
|
|
18
|
+
selectorPrefix?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type TrackerType = 'event' | 'pageView' | 'session';
|
|
22
|
+
|
|
23
|
+
export type TrackerAttributes = Record<string, string>;
|
|
24
|
+
|
|
25
|
+
export type TrackerEventRecorder = (
|
|
26
|
+
eventName: string,
|
|
27
|
+
attributes: TrackerAttributes
|
|
28
|
+
) => void;
|
|
29
|
+
|
|
30
|
+
export type DOMEvent = keyof GlobalEventHandlersEventMap;
|
|
31
|
+
|
|
32
|
+
export interface TrackerInterface {
|
|
33
|
+
configure(eventRecorder: TrackerEventRecorder, options?: object): void;
|
|
34
|
+
cleanup(): void;
|
|
35
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AnalyticsValidationErrorCode, assertValidationError } from '../errors';
|
|
5
|
+
import { AnalyticsConfigureAutoTrackInput } from '../types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Validates tracker configuration.
|
|
9
|
+
*/
|
|
10
|
+
export const validateTrackerConfiguration = (
|
|
11
|
+
input: AnalyticsConfigureAutoTrackInput
|
|
12
|
+
) => {
|
|
13
|
+
// React Native only supports session tracking
|
|
14
|
+
assertValidationError(
|
|
15
|
+
input.type === 'session',
|
|
16
|
+
AnalyticsValidationErrorCode.UnsupportedPlatform
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AnalyticsValidationErrorCode, assertValidationError } from '../errors';
|
|
5
|
+
import { AnalyticsConfigureAutoTrackInput } from '../types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Validates tracker configuration.
|
|
9
|
+
*/
|
|
10
|
+
export const validateTrackerConfiguration = (
|
|
11
|
+
input: AnalyticsConfigureAutoTrackInput
|
|
12
|
+
) => {
|
|
13
|
+
assertValidationError(
|
|
14
|
+
input.type === 'event' ||
|
|
15
|
+
input.type === 'pageView' ||
|
|
16
|
+
input.type === 'session',
|
|
17
|
+
AnalyticsValidationErrorCode.InvalidTracker
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
TrackerAttributes,
|
|
6
|
+
TrackerEventRecorder,
|
|
7
|
+
TrackerInterface,
|
|
8
|
+
TrackerType,
|
|
9
|
+
} from '../types/trackers';
|
|
10
|
+
import { EventTracker, PageViewTracker, SessionTracker } from '../trackers';
|
|
11
|
+
import { ConfigureAutoTrackInput } from '../providers/pinpoint';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Updates a provider's trackers as appropriate for the provided auto-track configuration.
|
|
15
|
+
*
|
|
16
|
+
* @remark
|
|
17
|
+
* This utility will mutate the provider's configured trackers via `providerTrackers`.
|
|
18
|
+
*/
|
|
19
|
+
export const updateProviderTrackers = (
|
|
20
|
+
input: ConfigureAutoTrackInput,
|
|
21
|
+
providerEventRecorder: TrackerEventRecorder,
|
|
22
|
+
providerTrackers: Partial<Record<TrackerType, TrackerInterface>>
|
|
23
|
+
) => {
|
|
24
|
+
let trackerInstance;
|
|
25
|
+
const trackerType = input.type;
|
|
26
|
+
const currentTracker = providerTrackers[trackerType];
|
|
27
|
+
|
|
28
|
+
// Check if the tracker was disabled & should be cleaned up
|
|
29
|
+
if (!input.enable) {
|
|
30
|
+
if (currentTracker) {
|
|
31
|
+
currentTracker.cleanup();
|
|
32
|
+
delete providerTrackers[trackerType];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Re-configure the existing tracker, or create & configure an instance if it doesn't exist yet
|
|
39
|
+
if (currentTracker) {
|
|
40
|
+
currentTracker.configure(providerEventRecorder, input.options);
|
|
41
|
+
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Create a new tracker instance for the type
|
|
46
|
+
if (trackerType === 'event') {
|
|
47
|
+
trackerInstance = new EventTracker(providerEventRecorder, input.options);
|
|
48
|
+
} else if (trackerType === 'pageView') {
|
|
49
|
+
trackerInstance = new PageViewTracker(providerEventRecorder, input.options);
|
|
50
|
+
} else if (trackerType === 'session') {
|
|
51
|
+
trackerInstance = new SessionTracker(providerEventRecorder, input.options);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (trackerInstance) {
|
|
55
|
+
providerTrackers[trackerType] = trackerInstance;
|
|
56
|
+
}
|
|
57
|
+
};
|
package/lib/types/analytics.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Analytics instance options
|
|
3
|
-
*/
|
|
4
|
-
export interface EventAttributes {
|
|
5
|
-
[key: string]: string;
|
|
6
|
-
}
|
|
7
|
-
export interface EventMetrics {
|
|
8
|
-
[key: string]: number;
|
|
9
|
-
}
|
|
10
|
-
export interface PageViewTrackOpts {
|
|
11
|
-
enable: boolean;
|
|
12
|
-
type?: string;
|
|
13
|
-
eventName?: string;
|
|
14
|
-
provider?: string;
|
|
15
|
-
attributes?: EventAttributes | (() => EventAttributes | Promise<EventAttributes>);
|
|
16
|
-
getUrl?: () => string;
|
|
17
|
-
}
|
|
18
|
-
export interface EventTrackOpts {
|
|
19
|
-
enable: boolean;
|
|
20
|
-
events?: Array<string>;
|
|
21
|
-
selectorPrefix?: string;
|
|
22
|
-
provider?: string;
|
|
23
|
-
attributes?: EventAttributes | (() => EventAttributes | Promise<EventAttributes>);
|
|
24
|
-
}
|
|
25
|
-
export interface SessionTrackOpts {
|
|
26
|
-
enable: boolean;
|
|
27
|
-
attributes?: EventAttributes | (() => EventAttributes | Promise<EventAttributes>);
|
|
28
|
-
provider?: string;
|
|
29
|
-
}
|
|
30
|
-
export type AutoTrackAttributes = (() => EventAttributes | Promise<EventAttributes>) | EventAttributes;
|
|
31
|
-
export interface AutoTrackSessionOpts {
|
|
32
|
-
enable: boolean;
|
|
33
|
-
attributes?: AutoTrackAttributes;
|
|
34
|
-
provider?: string;
|
|
35
|
-
}
|
|
36
|
-
export interface AutoTrackPageViewOpts {
|
|
37
|
-
enable: boolean;
|
|
38
|
-
eventName?: string;
|
|
39
|
-
attributes?: AutoTrackAttributes;
|
|
40
|
-
type?: 'SPA' | 'multiPageApp';
|
|
41
|
-
provider?: string;
|
|
42
|
-
getUrl?: () => string;
|
|
43
|
-
}
|
|
44
|
-
export interface AutoTrackEventOpts {
|
|
45
|
-
enable: boolean;
|
|
46
|
-
events?: string[];
|
|
47
|
-
selectorPrefix?: string;
|
|
48
|
-
provider?: string;
|
|
49
|
-
attributes?: AutoTrackAttributes;
|
|
50
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Analytics instance options
|
|
3
|
-
*/
|
|
4
|
-
export interface EventAttributes {
|
|
5
|
-
[key: string]: string;
|
|
6
|
-
}
|
|
7
|
-
export interface EventMetrics {
|
|
8
|
-
[key: string]: number;
|
|
9
|
-
}
|
|
10
|
-
export interface PageViewTrackOpts {
|
|
11
|
-
enable: boolean;
|
|
12
|
-
type?: string;
|
|
13
|
-
eventName?: string;
|
|
14
|
-
provider?: string;
|
|
15
|
-
attributes?: EventAttributes | (() => EventAttributes | Promise<EventAttributes>);
|
|
16
|
-
getUrl?: () => string;
|
|
17
|
-
}
|
|
18
|
-
export interface EventTrackOpts {
|
|
19
|
-
enable: boolean;
|
|
20
|
-
events?: Array<string>;
|
|
21
|
-
selectorPrefix?: string;
|
|
22
|
-
provider?: string;
|
|
23
|
-
attributes?: EventAttributes | (() => EventAttributes | Promise<EventAttributes>);
|
|
24
|
-
}
|
|
25
|
-
export interface SessionTrackOpts {
|
|
26
|
-
enable: boolean;
|
|
27
|
-
attributes?: EventAttributes | (() => EventAttributes | Promise<EventAttributes>);
|
|
28
|
-
provider?: string;
|
|
29
|
-
}
|
|
30
|
-
export type AutoTrackAttributes = (() => EventAttributes | Promise<EventAttributes>) | EventAttributes;
|
|
31
|
-
export interface AutoTrackSessionOpts {
|
|
32
|
-
enable: boolean;
|
|
33
|
-
attributes?: AutoTrackAttributes;
|
|
34
|
-
provider?: string;
|
|
35
|
-
}
|
|
36
|
-
export interface AutoTrackPageViewOpts {
|
|
37
|
-
enable: boolean;
|
|
38
|
-
eventName?: string;
|
|
39
|
-
attributes?: AutoTrackAttributes;
|
|
40
|
-
type?: 'SPA' | 'multiPageApp';
|
|
41
|
-
provider?: string;
|
|
42
|
-
getUrl?: () => string;
|
|
43
|
-
}
|
|
44
|
-
export interface AutoTrackEventOpts {
|
|
45
|
-
enable: boolean;
|
|
46
|
-
events?: string[];
|
|
47
|
-
selectorPrefix?: string;
|
|
48
|
-
provider?: string;
|
|
49
|
-
attributes?: AutoTrackAttributes;
|
|
50
|
-
}
|
package/src/types/analytics.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Analytics instance options
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface EventAttributes {
|
|
9
|
-
[key: string]: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface EventMetrics {
|
|
13
|
-
[key: string]: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface PageViewTrackOpts {
|
|
17
|
-
enable: boolean;
|
|
18
|
-
type?: string;
|
|
19
|
-
eventName?: string;
|
|
20
|
-
provider?: string;
|
|
21
|
-
attributes?:
|
|
22
|
-
| EventAttributes
|
|
23
|
-
| (() => EventAttributes | Promise<EventAttributes>);
|
|
24
|
-
getUrl?: () => string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface EventTrackOpts {
|
|
28
|
-
enable: boolean;
|
|
29
|
-
events?: Array<string>;
|
|
30
|
-
selectorPrefix?: string;
|
|
31
|
-
provider?: string;
|
|
32
|
-
attributes?:
|
|
33
|
-
| EventAttributes
|
|
34
|
-
| (() => EventAttributes | Promise<EventAttributes>);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface SessionTrackOpts {
|
|
38
|
-
enable: boolean;
|
|
39
|
-
attributes?:
|
|
40
|
-
| EventAttributes
|
|
41
|
-
| (() => EventAttributes | Promise<EventAttributes>);
|
|
42
|
-
provider?: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type AutoTrackAttributes =
|
|
46
|
-
| (() => EventAttributes | Promise<EventAttributes>)
|
|
47
|
-
| EventAttributes;
|
|
48
|
-
|
|
49
|
-
export interface AutoTrackSessionOpts {
|
|
50
|
-
enable: boolean;
|
|
51
|
-
attributes?: AutoTrackAttributes;
|
|
52
|
-
provider?: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface AutoTrackPageViewOpts {
|
|
56
|
-
enable: boolean;
|
|
57
|
-
eventName?: string;
|
|
58
|
-
attributes?: AutoTrackAttributes;
|
|
59
|
-
type?: 'SPA' | 'multiPageApp';
|
|
60
|
-
provider?: string;
|
|
61
|
-
getUrl?: () => string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface AutoTrackEventOpts {
|
|
65
|
-
enable: boolean;
|
|
66
|
-
events?: string[];
|
|
67
|
-
selectorPrefix?: string;
|
|
68
|
-
provider?: string;
|
|
69
|
-
attributes?: AutoTrackAttributes;
|
|
70
|
-
}
|
|
File without changes
|
|
File without changes
|