@aws-amplify/analytics 7.0.1-console-preview.8f82e46.0 → 7.0.1-console-preview.b278dcb.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/errors/validation.d.ts +2 -0
- package/lib/errors/validation.js +8 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/providers/kinesis/apis/flushEvents.js +2 -1
- package/lib/providers/kinesis/apis/record.js +2 -1
- package/lib/providers/kinesis-firehose/apis/flushEvents.js +2 -1
- package/lib/providers/kinesis-firehose/apis/record.js +2 -1
- package/lib/providers/personalize/apis/flushEvents.js +2 -1
- package/lib/providers/personalize/apis/record.js +2 -1
- package/lib/providers/personalize/utils/autoTrackMedia.js +2 -1
- package/lib/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib/providers/pinpoint/apis/configureAutoTrack.js +35 -0
- package/lib/providers/pinpoint/apis/flushEvents.js +2 -1
- package/lib/providers/pinpoint/apis/identifyUser.js +4 -5
- package/lib/providers/pinpoint/apis/index.d.ts +1 -0
- package/lib/providers/pinpoint/apis/index.js +3 -1
- package/lib/providers/pinpoint/apis/record.js +1 -1
- package/lib/providers/pinpoint/index.d.ts +2 -2
- package/lib/providers/pinpoint/index.js +2 -1
- package/lib/providers/pinpoint/types/index.d.ts +1 -2
- package/lib/providers/pinpoint/types/index.js +0 -3
- package/lib/providers/pinpoint/types/inputs.d.ts +5 -1
- package/lib/trackers/EventTracker.d.ts +10 -0
- package/lib/trackers/EventTracker.js +104 -0
- package/lib/trackers/PageViewTracker.d.ts +18 -0
- package/lib/trackers/PageViewTracker.js +116 -0
- package/lib/trackers/SessionTracker.d.ts +13 -0
- package/lib/trackers/SessionTracker.js +73 -0
- package/lib/trackers/SessionTracker.native.d.ts +13 -0
- package/lib/trackers/SessionTracker.native.js +73 -0
- package/lib/trackers/index.d.ts +3 -0
- package/lib/trackers/index.js +11 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +1 -2
- package/lib/types/inputs.d.ts +17 -3
- package/lib/types/options.d.ts +1 -1
- package/lib/types/trackers.d.ts +22 -0
- package/lib/utils/eventBuffer/EventBuffer.js +2 -2
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +5 -1
- package/lib/utils/trackerConfigHelpers.d.ts +5 -0
- package/lib/utils/trackerConfigHelpers.js +15 -0
- package/lib/utils/trackerConfigHelpers.native.d.ts +5 -0
- package/lib/utils/trackerConfigHelpers.native.js +14 -0
- package/lib/utils/trackerHelpers.d.ts +9 -0
- package/lib/utils/trackerHelpers.js +44 -0
- package/lib-esm/errors/validation.d.ts +2 -0
- package/lib-esm/errors/validation.js +8 -0
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/providers/kinesis/apis/flushEvents.js +2 -1
- package/lib-esm/providers/kinesis/apis/record.js +2 -1
- package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +2 -1
- package/lib-esm/providers/kinesis-firehose/apis/record.js +3 -2
- package/lib-esm/providers/personalize/apis/flushEvents.js +2 -1
- package/lib-esm/providers/personalize/apis/record.js +2 -1
- package/lib-esm/providers/personalize/utils/autoTrackMedia.js +2 -1
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +31 -0
- package/lib-esm/providers/pinpoint/apis/flushEvents.js +2 -1
- package/lib-esm/providers/pinpoint/apis/identifyUser.js +5 -6
- package/lib-esm/providers/pinpoint/apis/index.d.ts +1 -0
- package/lib-esm/providers/pinpoint/apis/index.js +1 -0
- package/lib-esm/providers/pinpoint/apis/record.js +3 -3
- package/lib-esm/providers/pinpoint/index.d.ts +2 -2
- package/lib-esm/providers/pinpoint/index.js +1 -1
- package/lib-esm/providers/pinpoint/types/index.d.ts +1 -2
- package/lib-esm/providers/pinpoint/types/index.js +1 -1
- package/lib-esm/providers/pinpoint/types/inputs.d.ts +5 -1
- package/lib-esm/trackers/EventTracker.d.ts +10 -0
- package/lib-esm/trackers/EventTracker.js +101 -0
- package/lib-esm/trackers/PageViewTracker.d.ts +18 -0
- package/lib-esm/trackers/PageViewTracker.js +113 -0
- package/lib-esm/trackers/SessionTracker.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.js +70 -0
- package/lib-esm/trackers/SessionTracker.native.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.native.js +70 -0
- package/lib-esm/trackers/index.d.ts +3 -0
- package/lib-esm/trackers/index.js +5 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +1 -2
- package/lib-esm/types/inputs.d.ts +17 -3
- package/lib-esm/types/options.d.ts +1 -1
- package/lib-esm/types/trackers.d.ts +22 -0
- package/lib-esm/utils/eventBuffer/EventBuffer.js +1 -1
- package/lib-esm/utils/index.d.ts +2 -0
- package/lib-esm/utils/index.js +2 -0
- package/lib-esm/utils/trackerConfigHelpers.d.ts +5 -0
- package/lib-esm/utils/trackerConfigHelpers.js +11 -0
- package/lib-esm/utils/trackerConfigHelpers.native.d.ts +5 -0
- package/lib-esm/utils/trackerConfigHelpers.native.js +10 -0
- package/lib-esm/utils/trackerHelpers.d.ts +9 -0
- package/lib-esm/utils/trackerHelpers.js +40 -0
- package/package.json +5 -4
- package/src/errors/validation.ts +8 -0
- package/src/index.ts +3 -1
- package/src/providers/kinesis/apis/flushEvents.ts +2 -4
- package/src/providers/kinesis/apis/record.ts +2 -4
- package/src/providers/kinesis-firehose/apis/flushEvents.ts +2 -4
- package/src/providers/kinesis-firehose/apis/record.ts +3 -5
- package/src/providers/personalize/apis/flushEvents.ts +2 -4
- package/src/providers/personalize/apis/record.ts +2 -4
- package/src/providers/personalize/utils/autoTrackMedia.ts +2 -1
- package/src/providers/pinpoint/apis/configureAutoTrack.ts +49 -0
- package/src/providers/pinpoint/apis/flushEvents.ts +2 -4
- package/src/providers/pinpoint/apis/identifyUser.ts +6 -3
- package/src/providers/pinpoint/apis/index.ts +1 -0
- package/src/providers/pinpoint/apis/record.ts +2 -3
- package/src/providers/pinpoint/index.ts +6 -2
- package/src/providers/pinpoint/types/index.ts +5 -2
- package/src/providers/pinpoint/types/inputs.ts +9 -1
- package/src/trackers/EventTracker.ts +135 -0
- package/src/trackers/PageViewTracker.ts +160 -0
- package/src/trackers/SessionTracker.native.ts +106 -0
- package/src/trackers/SessionTracker.ts +106 -0
- package/src/trackers/index.ts +6 -0
- package/src/types/index.ts +4 -13
- package/src/types/inputs.ts +26 -3
- package/src/types/options.ts +1 -1
- package/src/types/trackers.ts +35 -0
- package/src/utils/eventBuffer/EventBuffer.ts +1 -1
- package/src/utils/index.ts +2 -0
- package/src/utils/trackerConfigHelpers.native.ts +18 -0
- package/src/utils/trackerConfigHelpers.ts +19 -0
- package/src/utils/trackerHelpers.ts +57 -0
- package/lib/providers/pinpoint/types/errors.d.ts +0 -9
- package/lib/providers/pinpoint/types/errors.js +0 -15
- package/lib/types/analytics.d.ts +0 -50
- package/lib-esm/providers/pinpoint/types/errors.d.ts +0 -9
- package/lib-esm/providers/pinpoint/types/errors.js +0 -12
- package/lib-esm/types/analytics.d.ts +0 -50
- package/src/providers/pinpoint/types/errors.ts +0 -12
- package/src/types/analytics.ts +0 -70
- /package/lib/types/{analytics.js → trackers.js} +0 -0
- /package/lib-esm/types/{analytics.js → trackers.js} +0 -0
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';
|
|
@@ -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-console-preview.
|
|
3
|
+
"version": "7.0.1-console-preview.b278dcb.0+b278dcb",
|
|
4
4
|
"description": "Analytics category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -99,10 +99,11 @@
|
|
|
99
99
|
"tslib": "^2.5.0"
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
|
-
"@aws-amplify/core": "6.0.1-console-preview.
|
|
102
|
+
"@aws-amplify/core": "6.0.1-console-preview.b278dcb.0+b278dcb"
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
|
-
"@aws-amplify/core": "6.0.1-console-preview.
|
|
105
|
+
"@aws-amplify/core": "6.0.1-console-preview.b278dcb.0+b278dcb",
|
|
106
|
+
"@aws-amplify/react-native": "1.0.1-console-preview.b278dcb.0+b278dcb",
|
|
106
107
|
"@aws-sdk/types": "3.398.0",
|
|
107
108
|
"typescript": "5.0.2"
|
|
108
109
|
},
|
|
@@ -150,5 +151,5 @@
|
|
|
150
151
|
"<rootDir>/src/setupTests.ts"
|
|
151
152
|
]
|
|
152
153
|
},
|
|
153
|
-
"gitHead": "
|
|
154
|
+
"gitHead": "b278dcb6dd7334e53d92d22386a22fba3c4a6089"
|
|
154
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
|
|
|
@@ -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()) {
|
|
@@ -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,
|
|
@@ -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',
|
|
@@ -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;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
EventTrackingOptions,
|
|
6
|
+
DOMEvent,
|
|
7
|
+
TrackerEventRecorder,
|
|
8
|
+
TrackerInterface,
|
|
9
|
+
} from '../types/trackers';
|
|
10
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
11
|
+
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
12
|
+
|
|
13
|
+
const DEFAULT_EVENTS = ['click'] as DOMEvent[];
|
|
14
|
+
const DEFAULT_SELECTOR_PREFIX = 'data-amplify-analytics-';
|
|
15
|
+
const DEFAULT_EVENT_NAME = 'event'; // Default event name as sent to the analytics provider
|
|
16
|
+
|
|
17
|
+
const logger = new ConsoleLogger('EventTracker');
|
|
18
|
+
|
|
19
|
+
export class EventTracker implements TrackerInterface {
|
|
20
|
+
private trackerActive: boolean;
|
|
21
|
+
private options: EventTrackingOptions;
|
|
22
|
+
private eventRecorder: TrackerEventRecorder;
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
eventRecorder: TrackerEventRecorder,
|
|
26
|
+
options?: EventTrackingOptions
|
|
27
|
+
) {
|
|
28
|
+
this.options = {};
|
|
29
|
+
this.trackerActive = false;
|
|
30
|
+
this.eventRecorder = eventRecorder;
|
|
31
|
+
this.handleDocEvent = this.handleDocEvent.bind(this);
|
|
32
|
+
|
|
33
|
+
this.configure(eventRecorder, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public configure(
|
|
37
|
+
eventRecorder: TrackerEventRecorder,
|
|
38
|
+
options?: EventTrackingOptions
|
|
39
|
+
) {
|
|
40
|
+
this.eventRecorder = eventRecorder;
|
|
41
|
+
|
|
42
|
+
// Clean up any existing listeners
|
|
43
|
+
this.cleanup();
|
|
44
|
+
|
|
45
|
+
// Apply defaults
|
|
46
|
+
this.options = {
|
|
47
|
+
attributes: options?.attributes ?? undefined,
|
|
48
|
+
events: options?.events ?? DEFAULT_EVENTS,
|
|
49
|
+
selectorPrefix: options?.selectorPrefix ?? DEFAULT_SELECTOR_PREFIX,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Register event listeners
|
|
53
|
+
if (isBrowser()) {
|
|
54
|
+
this.options.events?.forEach(targetEvent => {
|
|
55
|
+
document.addEventListener(targetEvent, this.handleDocEvent, {
|
|
56
|
+
capture: true,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
this.trackerActive = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public cleanup() {
|
|
65
|
+
// No-op if document listener is not active
|
|
66
|
+
if (!this.trackerActive) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Clean up event listeners
|
|
71
|
+
this.options.events?.forEach(targetEvent => {
|
|
72
|
+
document.removeEventListener(targetEvent, this.handleDocEvent, {
|
|
73
|
+
capture: true,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private handleDocEvent(event: Event) {
|
|
79
|
+
/**
|
|
80
|
+
* Example DOM element:
|
|
81
|
+
*
|
|
82
|
+
* ```
|
|
83
|
+
* <button
|
|
84
|
+
* data-amplify-analytics-on="click"
|
|
85
|
+
* data-amplify-analytics-name="click"
|
|
86
|
+
* data-amplify-analytics-attrs="attr1:attr1_value,attr2:attr2_value"
|
|
87
|
+
* />
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
const triggerSelector = `[${this.options.selectorPrefix}on]`;
|
|
91
|
+
const attrSelector = `${this.options.selectorPrefix}attrs`;
|
|
92
|
+
const eventNameSelector = `${this.options.selectorPrefix}name`;
|
|
93
|
+
const eventSource = event.target;
|
|
94
|
+
|
|
95
|
+
// Validate that the triggering event type is being tracked
|
|
96
|
+
if (!this.options.events?.includes(event.type as DOMEvent)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (eventSource instanceof HTMLElement) {
|
|
101
|
+
const target = eventSource.closest(triggerSelector);
|
|
102
|
+
|
|
103
|
+
if (target) {
|
|
104
|
+
// Parse event name from the element
|
|
105
|
+
const eventName =
|
|
106
|
+
target.getAttribute(eventNameSelector) || DEFAULT_EVENT_NAME;
|
|
107
|
+
|
|
108
|
+
// Parse attributes from the element
|
|
109
|
+
const elementAttributes: Record<string, string> = {};
|
|
110
|
+
const rawElementAttributes = target.getAttribute(attrSelector);
|
|
111
|
+
rawElementAttributes?.split(/\s*,\s*/).forEach(attr => {
|
|
112
|
+
const tmp = attr.trim().split(/\s*:\s*/);
|
|
113
|
+
elementAttributes[tmp[0]] = tmp[1];
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Assemble final list of attributes
|
|
117
|
+
const attributes = Object.assign(
|
|
118
|
+
{
|
|
119
|
+
type: event.type,
|
|
120
|
+
target: `${target.localName} with id ${target.id}`,
|
|
121
|
+
},
|
|
122
|
+
this.options.attributes,
|
|
123
|
+
elementAttributes
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
logger.debug('Recording automatically tracked DOM event', {
|
|
127
|
+
eventName,
|
|
128
|
+
attributes,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
this.eventRecorder(eventName, attributes);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|