@aws-amplify/analytics 7.0.16 → 7.0.17-unstable.0d2aa5d.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/dist/cjs/providers/kinesis/apis/flushEvents.js +8 -6
- package/dist/cjs/providers/kinesis/apis/flushEvents.js.map +1 -1
- package/dist/cjs/providers/kinesis/apis/record.js +7 -7
- package/dist/cjs/providers/kinesis/apis/record.js.map +1 -1
- package/dist/cjs/providers/kinesis/utils/getEventBuffer.js +2 -2
- package/dist/cjs/providers/kinesis/utils/getEventBuffer.js.map +1 -1
- package/dist/cjs/providers/kinesis-firehose/apis/flushEvents.js +10 -8
- package/dist/cjs/providers/kinesis-firehose/apis/flushEvents.js.map +1 -1
- package/dist/cjs/providers/kinesis-firehose/apis/record.js +8 -8
- package/dist/cjs/providers/kinesis-firehose/apis/record.js.map +1 -1
- package/dist/cjs/providers/kinesis-firehose/utils/getEventBuffer.js +2 -2
- package/dist/cjs/providers/kinesis-firehose/utils/getEventBuffer.js.map +1 -1
- package/dist/cjs/providers/personalize/apis/flushEvents.js +10 -8
- package/dist/cjs/providers/personalize/apis/flushEvents.js.map +1 -1
- package/dist/cjs/providers/personalize/apis/record.js +14 -14
- package/dist/cjs/providers/personalize/apis/record.js.map +1 -1
- package/dist/cjs/providers/personalize/utils/autoTrackMedia.js +8 -8
- package/dist/cjs/providers/personalize/utils/autoTrackMedia.js.map +1 -1
- package/dist/cjs/providers/personalize/utils/getEventBuffer.js +2 -2
- package/dist/cjs/providers/personalize/utils/getEventBuffer.js.map +1 -1
- package/dist/cjs/providers/pinpoint/apis/flushEvents.js +20 -16
- package/dist/cjs/providers/pinpoint/apis/flushEvents.js.map +1 -1
- package/dist/cjs/providers/pinpoint/apis/identifyUser.js +1 -1
- package/dist/cjs/providers/pinpoint/apis/identifyUser.js.map +1 -1
- package/dist/cjs/trackers/PageViewTracker.js +2 -4
- package/dist/cjs/trackers/PageViewTracker.js.map +1 -1
- package/dist/cjs/utils/resolveCredentials.js +1 -1
- package/dist/cjs/utils/resolveCredentials.js.map +1 -1
- package/dist/esm/apis/disable.mjs +1 -1
- package/dist/esm/apis/enable.mjs +1 -1
- package/dist/esm/providers/kinesis/apis/flushEvents.mjs +5 -3
- package/dist/esm/providers/kinesis/apis/flushEvents.mjs.map +1 -1
- package/dist/esm/providers/kinesis/apis/record.mjs +3 -3
- package/dist/esm/providers/kinesis/apis/record.mjs.map +1 -1
- package/dist/esm/providers/kinesis/types/inputs.d.ts +2 -2
- package/dist/esm/providers/kinesis/utils/getEventBuffer.mjs +3 -3
- package/dist/esm/providers/kinesis/utils/getEventBuffer.mjs.map +1 -1
- package/dist/esm/providers/kinesis-firehose/apis/flushEvents.mjs +5 -3
- package/dist/esm/providers/kinesis-firehose/apis/flushEvents.mjs.map +1 -1
- package/dist/esm/providers/kinesis-firehose/apis/record.mjs +3 -3
- package/dist/esm/providers/kinesis-firehose/apis/record.mjs.map +1 -1
- package/dist/esm/providers/kinesis-firehose/types/buffer.d.ts +1 -1
- package/dist/esm/providers/kinesis-firehose/types/inputs.d.ts +2 -2
- package/dist/esm/providers/kinesis-firehose/utils/getEventBuffer.mjs +3 -3
- package/dist/esm/providers/kinesis-firehose/utils/getEventBuffer.mjs.map +1 -1
- package/dist/esm/providers/personalize/apis/flushEvents.mjs +5 -3
- package/dist/esm/providers/personalize/apis/flushEvents.mjs.map +1 -1
- package/dist/esm/providers/personalize/apis/record.mjs +3 -3
- package/dist/esm/providers/personalize/apis/record.mjs.map +1 -1
- package/dist/esm/providers/personalize/types/buffer.d.ts +4 -4
- package/dist/esm/providers/personalize/types/inputs.d.ts +2 -2
- package/dist/esm/providers/personalize/utils/autoTrackMedia.d.ts +2 -2
- package/dist/esm/providers/personalize/utils/autoTrackMedia.mjs +8 -8
- package/dist/esm/providers/personalize/utils/autoTrackMedia.mjs.map +1 -1
- package/dist/esm/providers/personalize/utils/cachedSession.mjs.map +1 -1
- package/dist/esm/providers/personalize/utils/getEventBuffer.mjs +3 -3
- package/dist/esm/providers/personalize/utils/getEventBuffer.mjs.map +1 -1
- package/dist/esm/providers/pinpoint/apis/configureAutoTrack.mjs +1 -1
- package/dist/esm/providers/pinpoint/apis/flushEvents.mjs +18 -14
- package/dist/esm/providers/pinpoint/apis/flushEvents.mjs.map +1 -1
- package/dist/esm/providers/pinpoint/apis/identifyUser.d.ts +1 -1
- package/dist/esm/providers/pinpoint/apis/identifyUser.mjs +2 -2
- package/dist/esm/providers/pinpoint/apis/identifyUser.mjs.map +1 -1
- package/dist/esm/providers/pinpoint/apis/record.mjs.map +1 -1
- package/dist/esm/providers/pinpoint/types/inputs.d.ts +1 -1
- package/dist/esm/trackers/PageViewTracker.mjs +2 -4
- package/dist/esm/trackers/PageViewTracker.mjs.map +1 -1
- package/dist/esm/trackers/SessionTracker.mjs.map +1 -1
- package/dist/esm/trackers/SessionTracker.native.mjs.map +1 -1
- package/dist/esm/types/inputs.d.ts +3 -3
- package/dist/esm/types/kinesis.d.ts +2 -2
- package/dist/esm/types/trackers.d.ts +7 -7
- package/dist/esm/utils/eventBuffer/types.d.ts +3 -5
- package/dist/esm/utils/resolveCredentials.mjs +1 -1
- package/dist/esm/utils/resolveCredentials.mjs.map +1 -1
- package/dist/esm/utils/userAgent.mjs.map +1 -1
- package/package.json +110 -110
- package/src/errors/assertValidationError.ts +1 -1
- package/src/providers/kinesis/apis/flushEvents.ts +7 -4
- package/src/providers/kinesis/apis/record.ts +6 -3
- package/src/providers/kinesis/types/buffer.ts +1 -0
- package/src/providers/kinesis/types/inputs.ts +2 -2
- package/src/providers/kinesis/utils/getEventBuffer.ts +22 -21
- package/src/providers/kinesis/utils/resolveConfig.ts +4 -1
- package/src/providers/kinesis-firehose/apis/flushEvents.ts +7 -4
- package/src/providers/kinesis-firehose/apis/record.ts +6 -3
- package/src/providers/kinesis-firehose/types/buffer.ts +2 -1
- package/src/providers/kinesis-firehose/types/inputs.ts +2 -2
- package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +23 -21
- package/src/providers/kinesis-firehose/utils/resolveConfig.ts +4 -1
- package/src/providers/personalize/apis/flushEvents.ts +7 -4
- package/src/providers/personalize/apis/record.ts +8 -5
- package/src/providers/personalize/types/buffer.ts +6 -4
- package/src/providers/personalize/types/inputs.ts +2 -2
- package/src/providers/personalize/utils/autoTrackMedia.ts +34 -26
- package/src/providers/personalize/utils/cachedSession.ts +5 -5
- package/src/providers/personalize/utils/getEventBuffer.ts +24 -20
- package/src/providers/personalize/utils/resolveConfig.ts +4 -2
- package/src/providers/pinpoint/apis/configureAutoTrack.ts +5 -2
- package/src/providers/pinpoint/apis/flushEvents.ts +8 -5
- package/src/providers/pinpoint/apis/identifyUser.ts +3 -2
- package/src/providers/pinpoint/apis/record.ts +4 -2
- package/src/providers/pinpoint/types/inputs.ts +3 -1
- package/src/providers/pinpoint/utils/resolveConfig.ts +1 -0
- package/src/providers/pinpoint/utils/resolveCredentials.ts +3 -1
- package/src/trackers/EventTracker.ts +7 -6
- package/src/trackers/PageViewTracker.ts +8 -13
- package/src/trackers/SessionTracker.native.ts +6 -5
- package/src/trackers/SessionTracker.ts +6 -5
- package/src/types/inputs.ts +6 -5
- package/src/types/kinesis.ts +2 -2
- package/src/types/trackers.ts +8 -8
- package/src/utils/eventBuffer/EventBuffer.ts +3 -2
- package/src/utils/eventBuffer/types.ts +3 -5
- package/src/utils/groupBy.ts +3 -2
- package/src/utils/resolveCredentials.ts +4 -2
- package/src/utils/trackerConfigHelpers.native.ts +2 -2
- package/src/utils/trackerConfigHelpers.ts +2 -2
- package/src/utils/trackerHelpers.ts +1 -2
- package/src/utils/userAgent.ts +1 -1
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
AWSCredentials,
|
|
6
|
-
haveCredentialsChanged
|
|
4
|
+
import {
|
|
5
|
+
AWSCredentials,
|
|
6
|
+
haveCredentialsChanged,
|
|
7
7
|
} from '@aws-amplify/core/internals/utils';
|
|
8
8
|
import {
|
|
9
9
|
PersonalizeEventsClient,
|
|
10
10
|
PutEventsCommand,
|
|
11
11
|
} from '@aws-sdk/client-personalize-events';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
groupBy,
|
|
15
|
-
IAnalyticsClient
|
|
16
|
-
} from '../../../utils';
|
|
12
|
+
|
|
13
|
+
import { EventBuffer, IAnalyticsClient, groupBy } from '../../../utils';
|
|
17
14
|
import { PersonalizeBufferConfig, PersonalizeBufferEvent } from '../types';
|
|
18
15
|
|
|
19
16
|
/**
|
|
@@ -25,15 +22,17 @@ import { PersonalizeBufferConfig, PersonalizeBufferEvent } from '../types';
|
|
|
25
22
|
* When a new session is initiated, the previous ones should be released.
|
|
26
23
|
* */
|
|
27
24
|
const eventBufferMap: Record<string, EventBuffer<PersonalizeBufferEvent>> = {};
|
|
28
|
-
const cachedClients: Record<string, [PersonalizeEventsClient, AWSCredentials]> =
|
|
25
|
+
const cachedClients: Record<string, [PersonalizeEventsClient, AWSCredentials]> =
|
|
26
|
+
{};
|
|
29
27
|
|
|
30
28
|
const DELIMITER = '#';
|
|
31
29
|
|
|
32
30
|
const createPutEventsCommand = (
|
|
33
31
|
ids: string,
|
|
34
|
-
events: PersonalizeBufferEvent[]
|
|
32
|
+
events: PersonalizeBufferEvent[],
|
|
35
33
|
): PutEventsCommand => {
|
|
36
34
|
const [trackingId, sessionId, userId] = ids.split(DELIMITER);
|
|
35
|
+
|
|
37
36
|
return new PutEventsCommand({
|
|
38
37
|
trackingId,
|
|
39
38
|
sessionId,
|
|
@@ -49,7 +48,7 @@ const createPutEventsCommand = (
|
|
|
49
48
|
|
|
50
49
|
const submitEvents = async (
|
|
51
50
|
events: PersonalizeBufferEvent[],
|
|
52
|
-
client: PersonalizeEventsClient
|
|
51
|
+
client: PersonalizeEventsClient,
|
|
53
52
|
): Promise<PersonalizeBufferEvent[]> => {
|
|
54
53
|
const groupedByIds = Object.entries(
|
|
55
54
|
groupBy(
|
|
@@ -57,15 +56,16 @@ const submitEvents = async (
|
|
|
57
56
|
[event.trackingId, event.sessionId, event.userId]
|
|
58
57
|
.filter(id => !!id)
|
|
59
58
|
.join(DELIMITER),
|
|
60
|
-
events
|
|
61
|
-
)
|
|
59
|
+
events,
|
|
60
|
+
),
|
|
62
61
|
);
|
|
63
62
|
|
|
64
63
|
const requests = groupedByIds
|
|
65
|
-
.map(([ids,
|
|
64
|
+
.map(([ids, groupedEvents]) => createPutEventsCommand(ids, groupedEvents))
|
|
66
65
|
.map(command => client.send(command));
|
|
67
66
|
|
|
68
67
|
await Promise.allSettled(requests);
|
|
68
|
+
|
|
69
69
|
return Promise.resolve([]);
|
|
70
70
|
};
|
|
71
71
|
|
|
@@ -79,12 +79,16 @@ export const getEventBuffer = ({
|
|
|
79
79
|
userAgentValue,
|
|
80
80
|
}: PersonalizeBufferConfig): EventBuffer<PersonalizeBufferEvent> => {
|
|
81
81
|
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
|
|
82
|
-
const [
|
|
82
|
+
const [cachedClient, cachedCredentials] =
|
|
83
|
+
cachedClients[sessionIdentityKey] ?? [];
|
|
83
84
|
let credentialsHaveChanged = false;
|
|
84
85
|
|
|
85
86
|
// Check if credentials have changed for the cached client
|
|
86
87
|
if (cachedClient) {
|
|
87
|
-
credentialsHaveChanged = haveCredentialsChanged(
|
|
88
|
+
credentialsHaveChanged = haveCredentialsChanged(
|
|
89
|
+
cachedCredentials,
|
|
90
|
+
credentials,
|
|
91
|
+
);
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
@@ -96,11 +100,11 @@ export const getEventBuffer = ({
|
|
|
96
100
|
credentials,
|
|
97
101
|
customUserAgent: userAgentValue,
|
|
98
102
|
}),
|
|
99
|
-
credentials
|
|
103
|
+
credentials,
|
|
100
104
|
];
|
|
101
105
|
}
|
|
102
106
|
|
|
103
|
-
const [
|
|
107
|
+
const [personalizeClient] = cachedClients[sessionIdentityKey];
|
|
104
108
|
|
|
105
109
|
return events => submitEvents(events, personalizeClient);
|
|
106
110
|
};
|
|
@@ -112,11 +116,11 @@ export const getEventBuffer = ({
|
|
|
112
116
|
flushSize,
|
|
113
117
|
flushInterval,
|
|
114
118
|
},
|
|
115
|
-
getClient
|
|
119
|
+
getClient,
|
|
116
120
|
);
|
|
117
121
|
|
|
118
122
|
const releaseSessionKeys = Object.keys(eventBufferMap).filter(
|
|
119
|
-
key => key !== sessionIdentityKey
|
|
123
|
+
key => key !== sessionIdentityKey,
|
|
120
124
|
);
|
|
121
125
|
for (const releaseSessionKey of releaseSessionKeys) {
|
|
122
126
|
eventBufferMap[releaseSessionKey].flushAll().finally(() => {
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { Amplify } from '@aws-amplify/core';
|
|
5
|
+
|
|
5
6
|
import {
|
|
6
7
|
AnalyticsValidationErrorCode,
|
|
7
8
|
assertValidationError,
|
|
8
9
|
} from '../../../errors';
|
|
10
|
+
|
|
9
11
|
import {
|
|
10
12
|
DEFAULT_PERSONALIZE_CONFIG,
|
|
11
13
|
PERSONALIZE_FLUSH_SIZE_MAX,
|
|
@@ -26,12 +28,12 @@ export const resolveConfig = () => {
|
|
|
26
28
|
assertValidationError(!!region, AnalyticsValidationErrorCode.NoRegion);
|
|
27
29
|
assertValidationError(
|
|
28
30
|
!!trackingId,
|
|
29
|
-
AnalyticsValidationErrorCode.NoTrackingId
|
|
31
|
+
AnalyticsValidationErrorCode.NoTrackingId,
|
|
30
32
|
);
|
|
31
33
|
assertValidationError(
|
|
32
34
|
flushSize <= PERSONALIZE_FLUSH_SIZE_MAX,
|
|
33
35
|
AnalyticsValidationErrorCode.InvalidFlushSize,
|
|
34
|
-
`FlushSize for Personalize should be less or equal than ${PERSONALIZE_FLUSH_SIZE_MAX}
|
|
36
|
+
`FlushSize for Personalize should be less or equal than ${PERSONALIZE_FLUSH_SIZE_MAX}`,
|
|
35
37
|
);
|
|
36
38
|
|
|
37
39
|
return {
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { UpdateEndpointException } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
5
|
+
|
|
4
6
|
import { AnalyticsValidationErrorCode } from '../../../errors';
|
|
5
7
|
import {
|
|
6
|
-
TrackerType,
|
|
7
8
|
TrackerAttributes,
|
|
8
9
|
TrackerInterface,
|
|
10
|
+
TrackerType,
|
|
9
11
|
} from '../../../types/trackers';
|
|
10
12
|
import {
|
|
11
13
|
updateProviderTrackers,
|
|
12
14
|
validateTrackerConfiguration,
|
|
13
15
|
} from '../../../utils';
|
|
14
16
|
import { ConfigureAutoTrackInput } from '../types';
|
|
17
|
+
|
|
15
18
|
import { record } from './record';
|
|
16
19
|
|
|
17
20
|
// Configured Tracker instances for Pinpoint
|
|
@@ -20,7 +23,7 @@ const configuredTrackers: Partial<Record<TrackerType, TrackerInterface>> = {};
|
|
|
20
23
|
// Callback that will emit an appropriate event to Pinpoint when required by the Tracker
|
|
21
24
|
const emitTrackingEvent = (
|
|
22
25
|
eventName: string,
|
|
23
|
-
attributes: TrackerAttributes
|
|
26
|
+
attributes: TrackerAttributes,
|
|
24
27
|
) => {
|
|
25
28
|
record({
|
|
26
29
|
name: eventName,
|
|
@@ -1,10 +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
|
-
import { resolveConfig, resolveCredentials } from '../utils';
|
|
5
4
|
import { flushEvents as flushEventsCore } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
6
5
|
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
7
6
|
import { ConsoleLogger } from '@aws-amplify/core';
|
|
7
|
+
|
|
8
|
+
import { resolveConfig, resolveCredentials } from '../utils';
|
|
8
9
|
import { getAnalyticsUserAgentString } from '../../../utils';
|
|
9
10
|
|
|
10
11
|
const logger = new ConsoleLogger('Analytics');
|
|
@@ -20,7 +21,7 @@ export const flushEvents = () => {
|
|
|
20
21
|
const { appId, region, bufferSize, flushSize, flushInterval, resendLimit } =
|
|
21
22
|
resolveConfig();
|
|
22
23
|
resolveCredentials()
|
|
23
|
-
.then(({ credentials, identityId }) =>
|
|
24
|
+
.then(({ credentials, identityId }) => {
|
|
24
25
|
flushEventsCore({
|
|
25
26
|
appId,
|
|
26
27
|
region,
|
|
@@ -31,7 +32,9 @@ export const flushEvents = () => {
|
|
|
31
32
|
flushInterval,
|
|
32
33
|
resendLimit,
|
|
33
34
|
userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
|
|
34
|
-
})
|
|
35
|
-
)
|
|
36
|
-
.catch(e =>
|
|
35
|
+
});
|
|
36
|
+
})
|
|
37
|
+
.catch(e => {
|
|
38
|
+
logger.warn('Failed to flush events', e);
|
|
39
|
+
});
|
|
37
40
|
};
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
5
5
|
import {
|
|
6
|
-
updateEndpoint,
|
|
7
6
|
UpdateEndpointException,
|
|
7
|
+
updateEndpoint,
|
|
8
8
|
} from '@aws-amplify/core/internals/providers/pinpoint';
|
|
9
|
+
|
|
9
10
|
import { AnalyticsValidationErrorCode } from '../../../errors';
|
|
10
11
|
import { getAnalyticsUserAgentString } from '../../../utils';
|
|
11
12
|
import { IdentifyUserInput } from '../types';
|
|
@@ -16,7 +17,7 @@ import { resolveConfig, resolveCredentials } from '../utils';
|
|
|
16
17
|
* profile and activities or actions in your application. Activity can be tracked across devices & platforms by using
|
|
17
18
|
* the same `userId`.
|
|
18
19
|
*
|
|
19
|
-
* @param {
|
|
20
|
+
* @param {IdentifyUserInput} params The input object used to construct requests sent to Pinpoint's UpdateEndpoint
|
|
20
21
|
* API.
|
|
21
22
|
*
|
|
22
23
|
* @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { ConsoleLogger, Hub } from '@aws-amplify/core';
|
|
5
5
|
import {
|
|
6
6
|
AMPLIFY_SYMBOL,
|
|
7
7
|
AnalyticsAction,
|
|
8
8
|
} from '@aws-amplify/core/internals/utils';
|
|
9
9
|
import { record as recordCore } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
10
|
+
|
|
10
11
|
import {
|
|
11
12
|
AnalyticsValidationErrorCode,
|
|
12
13
|
assertValidationError,
|
|
@@ -54,6 +55,7 @@ export const record = (input: RecordInput): void => {
|
|
|
54
55
|
|
|
55
56
|
if (!isAnalyticsEnabled()) {
|
|
56
57
|
logger.debug('Analytics is disabled, event will not be recorded.');
|
|
58
|
+
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -65,7 +67,7 @@ export const record = (input: RecordInput): void => {
|
|
|
65
67
|
'analytics',
|
|
66
68
|
{ event: 'record', data: input, message: 'Recording Analytics event' },
|
|
67
69
|
'Analytics',
|
|
68
|
-
AMPLIFY_SYMBOL
|
|
70
|
+
AMPLIFY_SYMBOL,
|
|
69
71
|
);
|
|
70
72
|
recordCore({
|
|
71
73
|
appId,
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
import {
|
|
7
7
|
AnalyticsConfigureAutoTrackInput,
|
|
8
8
|
AnalyticsIdentifyUserInput,
|
|
9
9
|
} from '../../../types';
|
|
10
10
|
|
|
11
|
+
import { IdentifyUserOptions } from './options';
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* Input type for Pinpoint record API.
|
|
13
15
|
*/
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { fetchAuthSession } from '@aws-amplify/core';
|
|
5
|
+
|
|
5
6
|
import {
|
|
6
7
|
AnalyticsValidationErrorCode,
|
|
7
8
|
assertValidationError,
|
|
@@ -14,7 +15,8 @@ export const resolveCredentials = async () => {
|
|
|
14
15
|
const { credentials, identityId } = await fetchAuthSession();
|
|
15
16
|
assertValidationError(
|
|
16
17
|
!!credentials,
|
|
17
|
-
AnalyticsValidationErrorCode.NoCredentials
|
|
18
|
+
AnalyticsValidationErrorCode.NoCredentials,
|
|
18
19
|
);
|
|
20
|
+
|
|
19
21
|
return { credentials, identityId };
|
|
20
22
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
5
|
+
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
6
|
+
|
|
4
7
|
import {
|
|
5
|
-
EventTrackingOptions,
|
|
6
8
|
DOMEvent,
|
|
9
|
+
EventTrackingOptions,
|
|
7
10
|
TrackerEventRecorder,
|
|
8
11
|
TrackerInterface,
|
|
9
12
|
} from '../types/trackers';
|
|
10
|
-
import { ConsoleLogger } from '@aws-amplify/core';
|
|
11
|
-
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
12
13
|
|
|
13
14
|
const DEFAULT_EVENTS = ['click'] as DOMEvent[];
|
|
14
15
|
const DEFAULT_SELECTOR_PREFIX = 'data-amplify-analytics-';
|
|
@@ -23,7 +24,7 @@ export class EventTracker implements TrackerInterface {
|
|
|
23
24
|
|
|
24
25
|
constructor(
|
|
25
26
|
eventRecorder: TrackerEventRecorder,
|
|
26
|
-
options?: EventTrackingOptions
|
|
27
|
+
options?: EventTrackingOptions,
|
|
27
28
|
) {
|
|
28
29
|
this.options = {};
|
|
29
30
|
this.trackerActive = false;
|
|
@@ -35,7 +36,7 @@ export class EventTracker implements TrackerInterface {
|
|
|
35
36
|
|
|
36
37
|
public configure(
|
|
37
38
|
eventRecorder: TrackerEventRecorder,
|
|
38
|
-
options?: EventTrackingOptions
|
|
39
|
+
options?: EventTrackingOptions,
|
|
39
40
|
) {
|
|
40
41
|
this.eventRecorder = eventRecorder;
|
|
41
42
|
|
|
@@ -120,7 +121,7 @@ export class EventTracker implements TrackerInterface {
|
|
|
120
121
|
target: `${target.localName} with id ${target.id}`,
|
|
121
122
|
},
|
|
122
123
|
this.options.attributes,
|
|
123
|
-
elementAttributes
|
|
124
|
+
elementAttributes,
|
|
124
125
|
);
|
|
125
126
|
|
|
126
127
|
logger.debug('Recording automatically tracked DOM event', {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
5
|
+
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
6
|
+
|
|
4
7
|
import {
|
|
5
8
|
PageViewTrackingOptions,
|
|
6
9
|
TrackerEventRecorder,
|
|
7
10
|
TrackerInterface,
|
|
8
11
|
} from '../types/trackers';
|
|
9
|
-
import { ConsoleLogger } from '@aws-amplify/core';
|
|
10
|
-
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
11
12
|
|
|
12
13
|
const logger = new ConsoleLogger('PageViewTracker');
|
|
13
14
|
|
|
@@ -32,7 +33,7 @@ export class PageViewTracker implements TrackerInterface {
|
|
|
32
33
|
|
|
33
34
|
constructor(
|
|
34
35
|
eventRecorder: TrackerEventRecorder,
|
|
35
|
-
options?: PageViewTrackingOptions
|
|
36
|
+
options?: PageViewTrackingOptions,
|
|
36
37
|
) {
|
|
37
38
|
this.options = {};
|
|
38
39
|
this.trackerActive = true;
|
|
@@ -45,7 +46,7 @@ export class PageViewTracker implements TrackerInterface {
|
|
|
45
46
|
|
|
46
47
|
public configure(
|
|
47
48
|
eventRecorder: TrackerEventRecorder,
|
|
48
|
-
options?: PageViewTrackingOptions
|
|
49
|
+
options?: PageViewTrackingOptions,
|
|
49
50
|
) {
|
|
50
51
|
this.eventRecorder = eventRecorder;
|
|
51
52
|
|
|
@@ -95,20 +96,14 @@ export class PageViewTracker implements TrackerInterface {
|
|
|
95
96
|
// Configure proxies on History APIs
|
|
96
97
|
this.pushStateProxy = Proxy.revocable(window.history.pushState, {
|
|
97
98
|
apply: (target, thisArg, args) => {
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
target.apply(thisArg, args as any);
|
|
100
100
|
this.handleLocationChange();
|
|
101
|
-
|
|
102
|
-
return proxiedResult;
|
|
103
101
|
},
|
|
104
102
|
});
|
|
105
103
|
this.replaceStateProxy = Proxy.revocable(window.history.replaceState, {
|
|
106
104
|
apply: (target, thisArg, args) => {
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
target.apply(thisArg, args as any);
|
|
109
106
|
this.handleLocationChange();
|
|
110
|
-
|
|
111
|
-
return proxiedResult;
|
|
112
107
|
},
|
|
113
108
|
});
|
|
114
109
|
|
|
@@ -139,7 +134,7 @@ export class PageViewTracker implements TrackerInterface {
|
|
|
139
134
|
{
|
|
140
135
|
url: currentUrl,
|
|
141
136
|
},
|
|
142
|
-
this.options.attributes
|
|
137
|
+
this.options.attributes,
|
|
143
138
|
);
|
|
144
139
|
|
|
145
140
|
logger.debug('Recording automatically tracked page view event', {
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
sessionListener,
|
|
6
|
-
SessionState,
|
|
7
5
|
SESSION_START_EVENT,
|
|
8
6
|
SESSION_STOP_EVENT,
|
|
7
|
+
SessionState,
|
|
8
|
+
sessionListener,
|
|
9
9
|
} from '@aws-amplify/core/internals/utils';
|
|
10
10
|
import { ConsoleLogger } from '@aws-amplify/core';
|
|
11
|
+
|
|
11
12
|
import {
|
|
12
13
|
SessionTrackingOptions,
|
|
13
14
|
TrackerEventRecorder,
|
|
@@ -24,7 +25,7 @@ export class SessionTracker implements TrackerInterface {
|
|
|
24
25
|
|
|
25
26
|
constructor(
|
|
26
27
|
eventRecorder: TrackerEventRecorder,
|
|
27
|
-
options?: SessionTrackingOptions
|
|
28
|
+
options?: SessionTrackingOptions,
|
|
28
29
|
) {
|
|
29
30
|
this.options = {};
|
|
30
31
|
this.eventRecorder = eventRecorder;
|
|
@@ -37,7 +38,7 @@ export class SessionTracker implements TrackerInterface {
|
|
|
37
38
|
|
|
38
39
|
public configure(
|
|
39
40
|
eventRecorder: TrackerEventRecorder,
|
|
40
|
-
options?: SessionTrackingOptions
|
|
41
|
+
options?: SessionTrackingOptions,
|
|
41
42
|
) {
|
|
42
43
|
this.eventRecorder = eventRecorder;
|
|
43
44
|
|
|
@@ -53,7 +54,7 @@ export class SessionTracker implements TrackerInterface {
|
|
|
53
54
|
if (!this.sessionTrackingActive) {
|
|
54
55
|
sessionListener.addStateChangeListener(
|
|
55
56
|
this.handleStateChange,
|
|
56
|
-
!this.initialEventSent
|
|
57
|
+
!this.initialEventSent,
|
|
57
58
|
);
|
|
58
59
|
|
|
59
60
|
this.sessionTrackingActive = true;
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
sessionListener,
|
|
6
|
-
SessionState,
|
|
7
5
|
SESSION_START_EVENT,
|
|
8
6
|
SESSION_STOP_EVENT,
|
|
7
|
+
SessionState,
|
|
8
|
+
sessionListener,
|
|
9
9
|
} from '@aws-amplify/core/internals/utils';
|
|
10
10
|
import { ConsoleLogger } from '@aws-amplify/core';
|
|
11
|
+
|
|
11
12
|
import {
|
|
12
13
|
SessionTrackingOptions,
|
|
13
14
|
TrackerEventRecorder,
|
|
@@ -24,7 +25,7 @@ export class SessionTracker implements TrackerInterface {
|
|
|
24
25
|
|
|
25
26
|
constructor(
|
|
26
27
|
eventRecorder: TrackerEventRecorder,
|
|
27
|
-
options?: SessionTrackingOptions
|
|
28
|
+
options?: SessionTrackingOptions,
|
|
28
29
|
) {
|
|
29
30
|
this.options = {};
|
|
30
31
|
this.eventRecorder = eventRecorder;
|
|
@@ -37,7 +38,7 @@ export class SessionTracker implements TrackerInterface {
|
|
|
37
38
|
|
|
38
39
|
public configure(
|
|
39
40
|
eventRecorder: TrackerEventRecorder,
|
|
40
|
-
options?: SessionTrackingOptions
|
|
41
|
+
options?: SessionTrackingOptions,
|
|
41
42
|
) {
|
|
42
43
|
this.eventRecorder = eventRecorder;
|
|
43
44
|
|
|
@@ -53,7 +54,7 @@ export class SessionTracker implements TrackerInterface {
|
|
|
53
54
|
if (!this.sessionTrackingActive) {
|
|
54
55
|
sessionListener.addStateChangeListener(
|
|
55
56
|
this.handleStateChange,
|
|
56
|
-
!this.initialEventSent
|
|
57
|
+
!this.initialEventSent,
|
|
57
58
|
);
|
|
58
59
|
|
|
59
60
|
this.sessionTrackingActive = true;
|
package/src/types/inputs.ts
CHANGED
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { UserProfile } from '@aws-amplify/core';
|
|
5
|
+
|
|
5
6
|
import { AnalyticsServiceOptions } from './options';
|
|
6
7
|
import {
|
|
7
|
-
SessionTrackingOptions,
|
|
8
|
-
PageViewTrackingOptions,
|
|
9
8
|
EventTrackingOptions,
|
|
9
|
+
PageViewTrackingOptions,
|
|
10
|
+
SessionTrackingOptions,
|
|
10
11
|
} from './trackers';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Input type for `identifyUser`.
|
|
14
15
|
*/
|
|
15
|
-
export
|
|
16
|
+
export interface AnalyticsIdentifyUserInput<
|
|
16
17
|
ServiceOptions extends AnalyticsServiceOptions = AnalyticsServiceOptions,
|
|
17
|
-
>
|
|
18
|
+
> {
|
|
18
19
|
/**
|
|
19
20
|
* A User ID associated to the current device.
|
|
20
21
|
*/
|
|
@@ -29,7 +30,7 @@ export type AnalyticsIdentifyUserInput<
|
|
|
29
30
|
* Options to be passed to the API.
|
|
30
31
|
*/
|
|
31
32
|
options?: ServiceOptions;
|
|
32
|
-
}
|
|
33
|
+
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Input type for `configureAutoTrack`.
|
package/src/types/kinesis.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export interface KinesisStream {
|
|
5
5
|
region: string;
|
|
6
6
|
streamName: string;
|
|
7
|
-
}
|
|
7
|
+
}
|
|
8
8
|
|
|
9
9
|
export type KinesisShard = KinesisStream & {
|
|
10
10
|
partitionKey: string;
|
package/src/types/trackers.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export interface SessionTrackingOptions {
|
|
5
5
|
attributes?: TrackerAttributes;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export interface PageViewTrackingOptions {
|
|
9
9
|
attributes?: TrackerAttributes;
|
|
10
10
|
eventName?: string;
|
|
11
|
-
urlProvider
|
|
11
|
+
urlProvider?(): string;
|
|
12
12
|
appType?: 'multiPage' | 'singlePage';
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export interface EventTrackingOptions {
|
|
16
16
|
attributes?: TrackerAttributes;
|
|
17
17
|
events?: DOMEvent[];
|
|
18
18
|
selectorPrefix?: string;
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
21
|
export type TrackerType = 'event' | 'pageView' | 'session';
|
|
22
22
|
|
|
@@ -24,7 +24,7 @@ export type TrackerAttributes = Record<string, string>;
|
|
|
24
24
|
|
|
25
25
|
export type TrackerEventRecorder = (
|
|
26
26
|
eventName: string,
|
|
27
|
-
attributes: TrackerAttributes
|
|
27
|
+
attributes: TrackerAttributes,
|
|
28
28
|
) => void;
|
|
29
29
|
|
|
30
30
|
export type DOMEvent = keyof GlobalEventHandlersEventMap;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { ConsoleLogger } from '@aws-amplify/core';
|
|
5
|
+
|
|
5
6
|
import { EventBufferConfig, IAnalyticsClient } from './';
|
|
6
7
|
|
|
7
8
|
const logger = new ConsoleLogger('EventBuffer');
|
|
@@ -15,7 +16,7 @@ export class EventBuffer<T> {
|
|
|
15
16
|
|
|
16
17
|
constructor(
|
|
17
18
|
config: EventBufferConfig,
|
|
18
|
-
getAnalyticsClient: () => IAnalyticsClient<T
|
|
19
|
+
getAnalyticsClient: () => IAnalyticsClient<T>,
|
|
19
20
|
) {
|
|
20
21
|
this.list = [];
|
|
21
22
|
this.config = config;
|
|
@@ -27,7 +28,7 @@ export class EventBuffer<T> {
|
|
|
27
28
|
for (const event of events) {
|
|
28
29
|
if (this.list.length + 1 > this.config.bufferSize) {
|
|
29
30
|
logger.debug(
|
|
30
|
-
`Exceed ${typeof event} event buffer limits, event dropped
|
|
31
|
+
`Exceed ${typeof event} event buffer limits, event dropped`,
|
|
31
32
|
);
|
|
32
33
|
continue;
|
|
33
34
|
}
|
|
@@ -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
3
|
|
|
4
|
-
export
|
|
5
|
-
(events: T[]): Promise<T[]>;
|
|
6
|
-
}
|
|
4
|
+
export type IAnalyticsClient<T> = (events: T[]) => Promise<T[]>;
|
|
7
5
|
|
|
8
|
-
export
|
|
6
|
+
export interface EventBufferConfig {
|
|
9
7
|
flushSize: number;
|
|
10
8
|
flushInterval: number;
|
|
11
9
|
bufferSize: number;
|
|
12
|
-
}
|
|
10
|
+
}
|
package/src/utils/groupBy.ts
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
export const groupBy = <T>(
|
|
5
5
|
getGroupId: (x: T) => string,
|
|
6
|
-
list: T[]
|
|
6
|
+
list: T[],
|
|
7
7
|
): Record<string, T[]> => {
|
|
8
8
|
return list.reduce(
|
|
9
9
|
(result, current) => {
|
|
10
10
|
const groupId = getGroupId(current);
|
|
11
|
+
|
|
11
12
|
return { ...result, [groupId]: [...(result[groupId] ?? []), current] };
|
|
12
13
|
},
|
|
13
|
-
{} as Record<string, T[]
|
|
14
|
+
{} as Record<string, T[]>,
|
|
14
15
|
);
|
|
15
16
|
};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { AnalyticsValidationErrorCode, assertValidationError } from '../errors';
|
|
5
4
|
import { fetchAuthSession } from '@aws-amplify/core';
|
|
6
5
|
|
|
6
|
+
import { AnalyticsValidationErrorCode, assertValidationError } from '../errors';
|
|
7
|
+
|
|
7
8
|
export const resolveCredentials = async () => {
|
|
8
9
|
const { credentials, identityId } = await fetchAuthSession();
|
|
9
10
|
assertValidationError(
|
|
10
11
|
!!credentials,
|
|
11
|
-
AnalyticsValidationErrorCode.NoCredentials
|
|
12
|
+
AnalyticsValidationErrorCode.NoCredentials,
|
|
12
13
|
);
|
|
14
|
+
|
|
13
15
|
return { credentials, identityId };
|
|
14
16
|
};
|