@aws-amplify/analytics 7.0.1-api-v6-models.8035dfc.0 → 7.0.1-api-v6-models.3eb7748.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/types/buffer.d.ts +2 -2
- package/lib/providers/kinesis-firehose/apis/flushEvents.js +2 -1
- package/lib/providers/kinesis-firehose/apis/record.js +2 -1
- package/lib/providers/kinesis-firehose/types/buffer.d.ts +2 -2
- package/lib/providers/personalize/apis/flushEvents.js +2 -1
- package/lib/providers/personalize/apis/record.js +61 -46
- package/lib/providers/personalize/types/buffer.d.ts +2 -2
- package/lib/providers/personalize/utils/autoTrackMedia.js +2 -1
- package/lib/providers/personalize/utils/cachedSession.d.ts +2 -2
- package/lib/providers/personalize/utils/cachedSession.js +23 -14
- 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/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
- 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/resolveCredentials.d.ts +1 -6
- 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/types/buffer.d.ts +2 -2
- 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/kinesis-firehose/types/buffer.d.ts +2 -2
- package/lib-esm/providers/personalize/apis/flushEvents.js +2 -1
- package/lib-esm/providers/personalize/apis/record.js +61 -46
- package/lib-esm/providers/personalize/types/buffer.d.ts +2 -2
- package/lib-esm/providers/personalize/utils/autoTrackMedia.js +2 -1
- package/lib-esm/providers/personalize/utils/cachedSession.d.ts +2 -2
- package/lib-esm/providers/personalize/utils/cachedSession.js +24 -15
- 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/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
- 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/resolveCredentials.d.ts +1 -6
- 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 +6 -7
- 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/types/buffer.ts +2 -2
- package/src/providers/kinesis-firehose/apis/flushEvents.ts +2 -4
- package/src/providers/kinesis-firehose/apis/record.ts +3 -5
- package/src/providers/kinesis-firehose/types/buffer.ts +2 -2
- package/src/providers/personalize/apis/flushEvents.ts +2 -4
- package/src/providers/personalize/apis/record.ts +5 -7
- package/src/providers/personalize/types/buffer.ts +2 -2
- package/src/providers/personalize/utils/autoTrackMedia.ts +2 -1
- package/src/providers/personalize/utils/cachedSession.ts +8 -7
- 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
package/lib-esm/types/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { AutoTrackAttributes, AutoTrackEventOpts, AutoTrackPageViewOpts, AutoTrackSessionOpts, EventAttributes, EventMetrics, EventTrackOpts, PageViewTrackOpts, SessionTrackOpts, } from './analytics';
|
|
2
1
|
export { AnalyticsServiceOptions } from './options';
|
|
3
|
-
export { AnalyticsIdentifyUserInput } from './inputs';
|
|
2
|
+
export { AnalyticsConfigureAutoTrackInput, AnalyticsIdentifyUserInput, } from './inputs';
|
|
4
3
|
export { KinesisStream, KinesisShard, KinesisEventData } from './kinesis';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { UserProfile } from '@aws-amplify/core';
|
|
2
2
|
import { AnalyticsServiceOptions } from '.';
|
|
3
|
+
import { SessionTrackingOptions, PageViewTrackingOptions, EventTrackingOptions } from './trackers';
|
|
3
4
|
/**
|
|
4
5
|
* Input type for `identifyUser`.
|
|
5
6
|
*/
|
|
@@ -15,7 +16,20 @@ export type AnalyticsIdentifyUserInput<ServiceOptions extends AnalyticsServiceOp
|
|
|
15
16
|
/**
|
|
16
17
|
* Options to be passed to the API.
|
|
17
18
|
*/
|
|
18
|
-
options?:
|
|
19
|
-
serviceOptions?: ServiceOptions;
|
|
20
|
-
};
|
|
19
|
+
options?: ServiceOptions;
|
|
21
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Input type for `configureAutoTrack`.
|
|
23
|
+
*/
|
|
24
|
+
export type AnalyticsConfigureAutoTrackInput = {
|
|
25
|
+
enable: boolean;
|
|
26
|
+
} & ({
|
|
27
|
+
type: 'session';
|
|
28
|
+
options?: SessionTrackingOptions;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'pageView';
|
|
31
|
+
options?: PageViewTrackingOptions;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'event';
|
|
34
|
+
options?: EventTrackingOptions;
|
|
35
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type SessionTrackingOptions = {
|
|
2
|
+
attributes?: TrackerAttributes;
|
|
3
|
+
};
|
|
4
|
+
export type PageViewTrackingOptions = {
|
|
5
|
+
attributes?: TrackerAttributes;
|
|
6
|
+
eventName?: string;
|
|
7
|
+
urlProvider?: () => string;
|
|
8
|
+
appType?: 'multiPage' | 'singlePage';
|
|
9
|
+
};
|
|
10
|
+
export type EventTrackingOptions = {
|
|
11
|
+
attributes?: TrackerAttributes;
|
|
12
|
+
events?: DOMEvent[];
|
|
13
|
+
selectorPrefix?: string;
|
|
14
|
+
};
|
|
15
|
+
export type TrackerType = 'event' | 'pageView' | 'session';
|
|
16
|
+
export type TrackerAttributes = Record<string, string>;
|
|
17
|
+
export type TrackerEventRecorder = (eventName: string, attributes: TrackerAttributes) => void;
|
|
18
|
+
export type DOMEvent = keyof GlobalEventHandlersEventMap;
|
|
19
|
+
export interface TrackerInterface {
|
|
20
|
+
configure(eventRecorder: TrackerEventRecorder, options?: object): void;
|
|
21
|
+
cleanup(): void;
|
|
22
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { __read, __spreadArray, __values } from "tslib";
|
|
4
|
-
import { ConsoleLogger } from '@aws-amplify/core
|
|
4
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
5
5
|
var logger = new ConsoleLogger('EventBuffer');
|
|
6
6
|
var EventBuffer = /** @class */ (function () {
|
|
7
7
|
function EventBuffer(config, getAnalyticsClient) {
|
package/lib-esm/utils/index.d.ts
CHANGED
|
@@ -3,3 +3,5 @@ export { groupBy } from './groupBy';
|
|
|
3
3
|
export { EventBuffer, IAnalyticsClient, EventBufferConfig, } from './eventBuffer';
|
|
4
4
|
export { enableAnalytics, disableAnalytics, isAnalyticsEnabled, } from './statusHelpers';
|
|
5
5
|
export { getAnalyticsUserAgent, getAnalyticsUserAgentString, } from './userAgent';
|
|
6
|
+
export { updateProviderTrackers } from './trackerHelpers';
|
|
7
|
+
export { validateTrackerConfiguration } from './trackerConfigHelpers';
|
package/lib-esm/utils/index.js
CHANGED
|
@@ -5,3 +5,5 @@ export { groupBy } from './groupBy';
|
|
|
5
5
|
export { EventBuffer, } from './eventBuffer';
|
|
6
6
|
export { enableAnalytics, disableAnalytics, isAnalyticsEnabled, } from './statusHelpers';
|
|
7
7
|
export { getAnalyticsUserAgent, getAnalyticsUserAgentString, } from './userAgent';
|
|
8
|
+
export { updateProviderTrackers } from './trackerHelpers';
|
|
9
|
+
export { validateTrackerConfiguration } from './trackerConfigHelpers';
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
export declare const resolveCredentials: () => Promise<{
|
|
2
|
-
credentials:
|
|
3
|
-
accessKeyId: string;
|
|
4
|
-
secretAccessKey: string;
|
|
5
|
-
sessionToken?: string | undefined;
|
|
6
|
-
expiration?: Date | undefined;
|
|
7
|
-
};
|
|
2
|
+
credentials: import("@aws-amplify/core/lib-esm/libraryUtils").AWSCredentials;
|
|
8
3
|
identityId: string | undefined;
|
|
9
4
|
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { AnalyticsValidationErrorCode, assertValidationError } from '../errors';
|
|
4
|
+
/**
|
|
5
|
+
* Validates tracker configuration.
|
|
6
|
+
*/
|
|
7
|
+
export var validateTrackerConfiguration = function (input) {
|
|
8
|
+
assertValidationError(input.type === 'event' ||
|
|
9
|
+
input.type === 'pageView' ||
|
|
10
|
+
input.type === 'session', AnalyticsValidationErrorCode.InvalidTracker);
|
|
11
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { AnalyticsValidationErrorCode, assertValidationError } from '../errors';
|
|
4
|
+
/**
|
|
5
|
+
* Validates tracker configuration.
|
|
6
|
+
*/
|
|
7
|
+
export var validateTrackerConfiguration = function (input) {
|
|
8
|
+
// React Native only supports session tracking
|
|
9
|
+
assertValidationError(input.type === 'session', AnalyticsValidationErrorCode.UnsupportedPlatform);
|
|
10
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TrackerEventRecorder, TrackerInterface, TrackerType } from '../types/trackers';
|
|
2
|
+
import { ConfigureAutoTrackInput } from '../providers/pinpoint';
|
|
3
|
+
/**
|
|
4
|
+
* Updates a provider's trackers as appropriate for the provided auto-track configuration.
|
|
5
|
+
*
|
|
6
|
+
* @remark
|
|
7
|
+
* This utility will mutate the provider's configured trackers via `providerTrackers`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const updateProviderTrackers: (input: ConfigureAutoTrackInput, providerEventRecorder: TrackerEventRecorder, providerTrackers: Partial<Record<TrackerType, TrackerInterface>>) => void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { EventTracker, PageViewTracker, SessionTracker } from '../trackers';
|
|
4
|
+
/**
|
|
5
|
+
* Updates a provider's trackers as appropriate for the provided auto-track configuration.
|
|
6
|
+
*
|
|
7
|
+
* @remark
|
|
8
|
+
* This utility will mutate the provider's configured trackers via `providerTrackers`.
|
|
9
|
+
*/
|
|
10
|
+
export var updateProviderTrackers = function (input, providerEventRecorder, providerTrackers) {
|
|
11
|
+
var trackerInstance;
|
|
12
|
+
var trackerType = input.type;
|
|
13
|
+
var currentTracker = providerTrackers[trackerType];
|
|
14
|
+
// Check if the tracker was disabled & should be cleaned up
|
|
15
|
+
if (!input.enable) {
|
|
16
|
+
if (currentTracker) {
|
|
17
|
+
currentTracker.cleanup();
|
|
18
|
+
delete providerTrackers[trackerType];
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// Re-configure the existing tracker, or create & configure an instance if it doesn't exist yet
|
|
23
|
+
if (currentTracker) {
|
|
24
|
+
currentTracker.configure(providerEventRecorder, input.options);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// Create a new tracker instance for the type
|
|
28
|
+
if (trackerType === 'event') {
|
|
29
|
+
trackerInstance = new EventTracker(providerEventRecorder, input.options);
|
|
30
|
+
}
|
|
31
|
+
else if (trackerType === 'pageView') {
|
|
32
|
+
trackerInstance = new PageViewTracker(providerEventRecorder, input.options);
|
|
33
|
+
}
|
|
34
|
+
else if (trackerType === 'session') {
|
|
35
|
+
trackerInstance = new SessionTracker(providerEventRecorder, input.options);
|
|
36
|
+
}
|
|
37
|
+
if (trackerInstance) {
|
|
38
|
+
providerTrackers[trackerType] = trackerInstance;
|
|
39
|
+
}
|
|
40
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/analytics",
|
|
3
|
-
"version": "7.0.1-api-v6-models.
|
|
3
|
+
"version": "7.0.1-api-v6-models.3eb7748.0+3eb7748",
|
|
4
4
|
"description": "Analytics category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -96,16 +96,15 @@
|
|
|
96
96
|
"@aws-sdk/client-kinesis": "3.398.0",
|
|
97
97
|
"@aws-sdk/client-personalize-events": "3.398.0",
|
|
98
98
|
"@smithy/util-utf8": "2.0.0",
|
|
99
|
-
"tslib": "^2.5.0"
|
|
100
|
-
"uuid": "^9.0.0"
|
|
99
|
+
"tslib": "^2.5.0"
|
|
101
100
|
},
|
|
102
101
|
"peerDependencies": {
|
|
103
|
-
"@aws-amplify/core": "6.0.1-api-v6-models.
|
|
102
|
+
"@aws-amplify/core": "6.0.1-api-v6-models.3eb7748.0+3eb7748"
|
|
104
103
|
},
|
|
105
104
|
"devDependencies": {
|
|
106
|
-
"@aws-amplify/core": "6.0.1-api-v6-models.
|
|
105
|
+
"@aws-amplify/core": "6.0.1-api-v6-models.3eb7748.0+3eb7748",
|
|
106
|
+
"@aws-amplify/react-native": "1.0.1-api-v6-models.3eb7748.0+3eb7748",
|
|
107
107
|
"@aws-sdk/types": "3.398.0",
|
|
108
|
-
"@types/uuid": "^9.0.0",
|
|
109
108
|
"typescript": "5.0.2"
|
|
110
109
|
},
|
|
111
110
|
"jest": {
|
|
@@ -152,5 +151,5 @@
|
|
|
152
151
|
"<rootDir>/src/setupTests.ts"
|
|
153
152
|
]
|
|
154
153
|
},
|
|
155
|
-
"gitHead": "
|
|
154
|
+
"gitHead": "3eb7748aee2fcdea705c93904d1f30ff596649fa"
|
|
156
155
|
}
|
package/src/errors/validation.ts
CHANGED
|
@@ -8,6 +8,8 @@ export enum AnalyticsValidationErrorCode {
|
|
|
8
8
|
NoCredentials = 'NoCredentials',
|
|
9
9
|
NoEventName = 'NoEventName',
|
|
10
10
|
NoRegion = 'NoRegion',
|
|
11
|
+
InvalidTracker = 'InvalidTracker',
|
|
12
|
+
UnsupportedPlatform = 'UnsupportedPlatform',
|
|
11
13
|
NoTrackingId = 'NoTrackingId',
|
|
12
14
|
InvalidFlushSize = 'InvalidFlushSize',
|
|
13
15
|
}
|
|
@@ -26,6 +28,12 @@ export const validationErrorMap: AmplifyErrorMap<AnalyticsValidationErrorCode> =
|
|
|
26
28
|
[AnalyticsValidationErrorCode.NoRegion]: {
|
|
27
29
|
message: 'Missing region.',
|
|
28
30
|
},
|
|
31
|
+
[AnalyticsValidationErrorCode.InvalidTracker]: {
|
|
32
|
+
message: 'Invalid tracker type specified.',
|
|
33
|
+
},
|
|
34
|
+
[AnalyticsValidationErrorCode.UnsupportedPlatform]: {
|
|
35
|
+
message: 'Only session tracking is supported on React Native.',
|
|
36
|
+
},
|
|
29
37
|
[AnalyticsValidationErrorCode.InvalidFlushSize]: {
|
|
30
38
|
message: 'Invalid FlushSize, it should be smaller than BufferSize',
|
|
31
39
|
},
|
package/src/index.ts
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
export {
|
|
5
5
|
record,
|
|
6
6
|
identifyUser,
|
|
7
|
+
configureAutoTrack,
|
|
8
|
+
flushEvents,
|
|
7
9
|
RecordInput,
|
|
8
10
|
IdentifyUserInput,
|
|
9
|
-
|
|
11
|
+
ConfigureAutoTrackInput,
|
|
10
12
|
} from './providers/pinpoint';
|
|
11
13
|
export { enable, disable } from './apis';
|
|
12
14
|
export { AnalyticsError } from './errors';
|
|
@@ -7,10 +7,8 @@ import {
|
|
|
7
7
|
resolveCredentials,
|
|
8
8
|
} from '../../../utils';
|
|
9
9
|
import { getEventBuffer } from '../utils/getEventBuffer';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
ConsoleLogger,
|
|
13
|
-
} from '@aws-amplify/core/internals/utils';
|
|
10
|
+
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
11
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
14
12
|
|
|
15
13
|
const logger = new ConsoleLogger('Kinesis');
|
|
16
14
|
|
|
@@ -10,10 +10,8 @@ import {
|
|
|
10
10
|
resolveCredentials,
|
|
11
11
|
} from '../../../utils';
|
|
12
12
|
import { fromUtf8 } from '@smithy/util-utf8';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
ConsoleLogger,
|
|
16
|
-
} from '@aws-amplify/core/internals/utils';
|
|
13
|
+
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
14
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
17
15
|
|
|
18
16
|
const logger = new ConsoleLogger('Kinesis');
|
|
19
17
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
|
|
4
5
|
import { EventBufferConfig } from '../../../utils';
|
|
5
|
-
import { Credentials } from '@aws-sdk/types';
|
|
6
6
|
import { KinesisShard } from '../../../types';
|
|
7
7
|
|
|
8
8
|
export type KinesisBufferEvent = KinesisShard & {
|
|
@@ -13,7 +13,7 @@ export type KinesisBufferEvent = KinesisShard & {
|
|
|
13
13
|
|
|
14
14
|
export type KinesisEventBufferConfig = EventBufferConfig & {
|
|
15
15
|
region: string;
|
|
16
|
-
credentials:
|
|
16
|
+
credentials: AWSCredentials;
|
|
17
17
|
identityId?: string;
|
|
18
18
|
resendLimit?: number;
|
|
19
19
|
userAgentValue?: string;
|
|
@@ -6,10 +6,8 @@ import {
|
|
|
6
6
|
getAnalyticsUserAgentString,
|
|
7
7
|
resolveCredentials,
|
|
8
8
|
} from '../../../utils';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
ConsoleLogger,
|
|
12
|
-
} from '@aws-amplify/core/internals/utils';
|
|
9
|
+
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
10
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
13
11
|
|
|
14
12
|
const logger = new ConsoleLogger('KinesisFirehose');
|
|
15
13
|
|
|
@@ -9,12 +9,10 @@ import {
|
|
|
9
9
|
resolveCredentials,
|
|
10
10
|
} from '../../../utils';
|
|
11
11
|
import { fromUtf8 } from '@smithy/util-utf8';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
ConsoleLogger as Logger,
|
|
15
|
-
} from '@aws-amplify/core/internals/utils';
|
|
12
|
+
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
13
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
16
14
|
|
|
17
|
-
const logger = new
|
|
15
|
+
const logger = new ConsoleLogger('KinesisFirehose');
|
|
18
16
|
|
|
19
17
|
export const record = ({ streamName, data }: RecordInput): void => {
|
|
20
18
|
if (!isAnalyticsEnabled()) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { EventBufferConfig } from '../../../utils';
|
|
5
5
|
import { KinesisStream } from '../../../types';
|
|
6
|
-
import {
|
|
6
|
+
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
|
|
7
7
|
|
|
8
8
|
export type KinesisFirehoseBufferEvent = KinesisStream & {
|
|
9
9
|
event: Uint8Array;
|
|
@@ -13,7 +13,7 @@ export type KinesisFirehoseBufferEvent = KinesisStream & {
|
|
|
13
13
|
|
|
14
14
|
export type KinesisFirehoseEventBufferConfig = EventBufferConfig & {
|
|
15
15
|
region: string;
|
|
16
|
-
credentials:
|
|
16
|
+
credentials: AWSCredentials;
|
|
17
17
|
identityId?: string;
|
|
18
18
|
resendLimit?: number;
|
|
19
19
|
userAgentValue?: string;
|
|
@@ -6,10 +6,8 @@ import {
|
|
|
6
6
|
getAnalyticsUserAgentString,
|
|
7
7
|
resolveCredentials,
|
|
8
8
|
} from '../../../utils';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
ConsoleLogger,
|
|
12
|
-
} from '@aws-amplify/core/internals/utils';
|
|
9
|
+
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
10
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
13
11
|
|
|
14
12
|
const logger = new ConsoleLogger('Personalize');
|
|
15
13
|
|
|
@@ -14,10 +14,8 @@ import {
|
|
|
14
14
|
isAnalyticsEnabled,
|
|
15
15
|
resolveCredentials,
|
|
16
16
|
} from '../../../utils';
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
ConsoleLogger,
|
|
20
|
-
} from '@aws-amplify/core/internals/utils';
|
|
17
|
+
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
18
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
21
19
|
import {
|
|
22
20
|
IDENTIFY_EVENT_TYPE,
|
|
23
21
|
MEDIA_AUTO_TRACK_EVENT_TYPE,
|
|
@@ -39,10 +37,10 @@ export const record = ({
|
|
|
39
37
|
const { region, trackingId, bufferSize, flushSize, flushInterval } =
|
|
40
38
|
resolveConfig();
|
|
41
39
|
resolveCredentials()
|
|
42
|
-
.then(({ credentials, identityId }) => {
|
|
40
|
+
.then(async ({ credentials, identityId }) => {
|
|
43
41
|
const timestamp = Date.now();
|
|
44
42
|
const { sessionId: cachedSessionId, userId: cachedUserId } =
|
|
45
|
-
resolveCachedSession(
|
|
43
|
+
await resolveCachedSession();
|
|
46
44
|
if (eventType === IDENTIFY_EVENT_TYPE) {
|
|
47
45
|
updateCachedSession(
|
|
48
46
|
typeof properties.userId === 'string' ? properties.userId : '',
|
|
@@ -54,7 +52,7 @@ export const record = ({
|
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
const { sessionId: updatedSessionId, userId: updatedUserId } =
|
|
57
|
-
resolveCachedSession(
|
|
55
|
+
await resolveCachedSession();
|
|
58
56
|
|
|
59
57
|
const eventBuffer = getEventBuffer({
|
|
60
58
|
region,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { PersonalizeEvent } from './';
|
|
5
5
|
import { EventBufferConfig } from '../../../utils';
|
|
6
|
-
import {
|
|
6
|
+
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
|
|
7
7
|
|
|
8
8
|
export type PersonalizeBufferEvent = {
|
|
9
9
|
trackingId: string;
|
|
@@ -15,7 +15,7 @@ export type PersonalizeBufferEvent = {
|
|
|
15
15
|
|
|
16
16
|
export type PersonalizeBufferConfig = EventBufferConfig & {
|
|
17
17
|
region: string;
|
|
18
|
-
credentials:
|
|
18
|
+
credentials: AWSCredentials;
|
|
19
19
|
identityId?: string;
|
|
20
20
|
userAgentValue?: string;
|
|
21
21
|
};
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import { EventBuffer } from '../../../utils';
|
|
5
5
|
import { PersonalizeBufferEvent, PersonalizeEvent } from '../types';
|
|
6
|
-
import {
|
|
6
|
+
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
7
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
7
8
|
|
|
8
9
|
enum HTML5_MEDIA_EVENT {
|
|
9
10
|
'PLAY' = 'play',
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { Cache } from '@aws-amplify/core';
|
|
5
|
-
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
6
|
-
import { v4 as uuid } from 'uuid';
|
|
5
|
+
import { isBrowser, amplifyUuid } from '@aws-amplify/core/internals/utils';
|
|
7
6
|
|
|
8
7
|
const PERSONALIZE_CACHE_USERID = '_awsct_uid';
|
|
9
8
|
const PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
|
|
@@ -27,14 +26,16 @@ const setCache = (key: string, value: unknown) => {
|
|
|
27
26
|
});
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
export const resolveCachedSession = (
|
|
31
|
-
let sessionId: string | undefined = getCache(
|
|
29
|
+
export const resolveCachedSession = async () => {
|
|
30
|
+
let sessionId: string | undefined = await getCache(
|
|
31
|
+
PERSONALIZE_CACHE_SESSIONID
|
|
32
|
+
);
|
|
32
33
|
if (!sessionId) {
|
|
33
|
-
sessionId =
|
|
34
|
+
sessionId = amplifyUuid();
|
|
34
35
|
setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
const userId: string | undefined = getCache(PERSONALIZE_CACHE_USERID);
|
|
38
|
+
const userId: string | undefined = await getCache(PERSONALIZE_CACHE_USERID);
|
|
38
39
|
|
|
39
40
|
return {
|
|
40
41
|
sessionId,
|
|
@@ -58,7 +59,7 @@ export const updateCachedSession = (
|
|
|
58
59
|
!!currentSessionId && !currentUserId && !!newUserId;
|
|
59
60
|
|
|
60
61
|
if (isRequireNewSession) {
|
|
61
|
-
const newSessionId =
|
|
62
|
+
const newSessionId = amplifyUuid();
|
|
62
63
|
setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
|
|
63
64
|
setCache(PERSONALIZE_CACHE_USERID, newUserId);
|
|
64
65
|
} else if (isRequireUpdateSession) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AnalyticsValidationErrorCode } from '../../../errors';
|
|
5
|
+
import {
|
|
6
|
+
TrackerType,
|
|
7
|
+
TrackerAttributes,
|
|
8
|
+
TrackerInterface,
|
|
9
|
+
} from '../../../types/trackers';
|
|
10
|
+
import {
|
|
11
|
+
updateProviderTrackers,
|
|
12
|
+
validateTrackerConfiguration,
|
|
13
|
+
} from '../../../utils';
|
|
14
|
+
import { ConfigureAutoTrackInput } from '../types';
|
|
15
|
+
import { record } from './record';
|
|
16
|
+
|
|
17
|
+
// Configured Tracker instances for Pinpoint
|
|
18
|
+
const configuredTrackers: Partial<Record<TrackerType, TrackerInterface>> = {};
|
|
19
|
+
|
|
20
|
+
// Callback that will emit an appropriate event to Pinpoint when required by the Tracker
|
|
21
|
+
const emitTrackingEvent = (
|
|
22
|
+
eventName: string,
|
|
23
|
+
attributes: TrackerAttributes
|
|
24
|
+
) => {
|
|
25
|
+
record({
|
|
26
|
+
name: eventName,
|
|
27
|
+
attributes,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Configures automatic event tracking for Pinpoint. This API will automatically transmit an analytic event when
|
|
33
|
+
* configured events are detected within your application. This can include: DOM element events (via the `event`
|
|
34
|
+
* tracker), session events (via the `session` tracker), and page view events (via the `pageView` tracker).
|
|
35
|
+
*
|
|
36
|
+
* @remark Only session tracking is currently supported on React Native.
|
|
37
|
+
*
|
|
38
|
+
* @param {ConfigureAutoTrackInput} params The input object to configure auto track behavior.
|
|
39
|
+
*
|
|
40
|
+
* @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
|
|
41
|
+
* @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
|
|
42
|
+
* configuration is incorrect.
|
|
43
|
+
*/
|
|
44
|
+
export const configureAutoTrack = (input: ConfigureAutoTrackInput): void => {
|
|
45
|
+
validateTrackerConfiguration(input);
|
|
46
|
+
|
|
47
|
+
// Initialize or update this provider's trackers
|
|
48
|
+
updateProviderTrackers(input, emitTrackingEvent, configuredTrackers);
|
|
49
|
+
};
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import { resolveConfig, resolveCredentials } from '../utils';
|
|
5
5
|
import { flushEvents as flushEventsCore } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
ConsoleLogger,
|
|
9
|
-
} from '@aws-amplify/core/internals/utils';
|
|
6
|
+
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
7
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
10
8
|
import { getAnalyticsUserAgentString } from '../../../utils';
|
|
11
9
|
|
|
12
10
|
const logger = new ConsoleLogger('Analytics');
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
updateEndpoint,
|
|
7
|
+
UpdateEndpointException,
|
|
8
|
+
} from '@aws-amplify/core/internals/providers/pinpoint';
|
|
6
9
|
import { AnalyticsValidationErrorCode } from '../../../errors';
|
|
7
10
|
import { getAnalyticsUserAgentString } from '../../../utils';
|
|
8
|
-
import { IdentifyUserInput
|
|
11
|
+
import { IdentifyUserInput } from '../types';
|
|
9
12
|
import { resolveConfig, resolveCredentials } from '../utils';
|
|
10
13
|
|
|
11
14
|
/**
|
|
@@ -60,7 +63,7 @@ export const identifyUser = async ({
|
|
|
60
63
|
}: IdentifyUserInput): Promise<void> => {
|
|
61
64
|
const { credentials, identityId } = await resolveCredentials();
|
|
62
65
|
const { appId, region } = resolveConfig();
|
|
63
|
-
const { userAttributes } = options
|
|
66
|
+
const { userAttributes } = options ?? {};
|
|
64
67
|
updateEndpoint({
|
|
65
68
|
appId,
|
|
66
69
|
category: 'Analytics',
|
|
@@ -1,11 +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
|
-
import { Hub } from '@aws-amplify/core';
|
|
4
|
+
import { Hub, ConsoleLogger } from '@aws-amplify/core';
|
|
5
5
|
import {
|
|
6
6
|
AMPLIFY_SYMBOL,
|
|
7
7
|
AnalyticsAction,
|
|
8
|
-
ConsoleLogger as Logger,
|
|
9
8
|
} from '@aws-amplify/core/internals/utils';
|
|
10
9
|
import { record as recordCore } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
11
10
|
import {
|
|
@@ -19,7 +18,7 @@ import {
|
|
|
19
18
|
import { RecordInput } from '../types';
|
|
20
19
|
import { resolveConfig, resolveCredentials } from '../utils';
|
|
21
20
|
|
|
22
|
-
const logger = new
|
|
21
|
+
const logger = new ConsoleLogger('Analytics');
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* Records an Analytic event to Pinpoint. Events will be buffered and periodically sent to Pinpoint.
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export { record, identifyUser, flushEvents } from './apis';
|
|
5
|
-
export {
|
|
4
|
+
export { record, identifyUser, flushEvents, configureAutoTrack } from './apis';
|
|
5
|
+
export {
|
|
6
|
+
RecordInput,
|
|
7
|
+
IdentifyUserInput,
|
|
8
|
+
ConfigureAutoTrackInput,
|
|
9
|
+
} from './types/inputs';
|
|
@@ -1,6 +1,9 @@
|
|
|
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
|
-
|
|
4
|
+
export {
|
|
5
|
+
RecordInput,
|
|
6
|
+
IdentifyUserInput,
|
|
7
|
+
ConfigureAutoTrackInput,
|
|
8
|
+
} from './inputs';
|
|
6
9
|
export { IdentifyUserOptions } from './options';
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
5
5
|
import { IdentifyUserOptions } from '.';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
AnalyticsConfigureAutoTrackInput,
|
|
8
|
+
AnalyticsIdentifyUserInput,
|
|
9
|
+
} from '../../../types';
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Input type for Pinpoint record API.
|
|
@@ -14,3 +17,8 @@ export type RecordInput = PinpointAnalyticsEvent;
|
|
|
14
17
|
* Input type for Pinpoint identifyUser API.
|
|
15
18
|
*/
|
|
16
19
|
export type IdentifyUserInput = AnalyticsIdentifyUserInput<IdentifyUserOptions>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Input type for Pinpoint configureAutoTrack API.
|
|
23
|
+
*/
|
|
24
|
+
export type ConfigureAutoTrackInput = AnalyticsConfigureAutoTrackInput;
|