@aws-amplify/analytics 7.0.1-console-preview.8d88eef.0 → 7.0.1-console-preview.b278dcb.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/errors/validation.d.ts +2 -0
- package/lib/errors/validation.js +8 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib/providers/pinpoint/apis/configureAutoTrack.js +35 -0
- package/lib/providers/pinpoint/apis/index.d.ts +1 -0
- package/lib/providers/pinpoint/apis/index.js +3 -1
- package/lib/providers/pinpoint/index.d.ts +2 -2
- package/lib/providers/pinpoint/index.js +2 -1
- package/lib/providers/pinpoint/types/index.d.ts +1 -1
- package/lib/providers/pinpoint/types/inputs.d.ts +5 -1
- package/lib/trackers/EventTracker.d.ts +10 -0
- package/lib/trackers/EventTracker.js +104 -0
- package/lib/trackers/PageViewTracker.d.ts +18 -0
- package/lib/trackers/PageViewTracker.js +116 -0
- package/lib/trackers/SessionTracker.d.ts +13 -0
- package/lib/trackers/SessionTracker.js +73 -0
- package/lib/trackers/SessionTracker.native.d.ts +13 -0
- package/lib/trackers/SessionTracker.native.js +73 -0
- package/lib/trackers/index.d.ts +3 -0
- package/lib/trackers/index.js +11 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +1 -2
- package/lib/types/inputs.d.ts +16 -0
- package/lib/types/trackers.d.ts +22 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +5 -1
- package/lib/utils/trackerConfigHelpers.d.ts +5 -0
- package/lib/utils/trackerConfigHelpers.js +15 -0
- package/lib/utils/trackerConfigHelpers.native.d.ts +5 -0
- package/lib/utils/trackerConfigHelpers.native.js +14 -0
- package/lib/utils/trackerHelpers.d.ts +9 -0
- package/lib/utils/trackerHelpers.js +44 -0
- package/lib-esm/errors/validation.d.ts +2 -0
- package/lib-esm/errors/validation.js +8 -0
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +31 -0
- package/lib-esm/providers/pinpoint/apis/index.d.ts +1 -0
- package/lib-esm/providers/pinpoint/apis/index.js +1 -0
- package/lib-esm/providers/pinpoint/apis/record.js +1 -1
- package/lib-esm/providers/pinpoint/index.d.ts +2 -2
- package/lib-esm/providers/pinpoint/index.js +1 -1
- package/lib-esm/providers/pinpoint/types/index.d.ts +1 -1
- package/lib-esm/providers/pinpoint/types/inputs.d.ts +5 -1
- package/lib-esm/trackers/EventTracker.d.ts +10 -0
- package/lib-esm/trackers/EventTracker.js +101 -0
- package/lib-esm/trackers/PageViewTracker.d.ts +18 -0
- package/lib-esm/trackers/PageViewTracker.js +113 -0
- package/lib-esm/trackers/SessionTracker.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.js +70 -0
- package/lib-esm/trackers/SessionTracker.native.d.ts +13 -0
- package/lib-esm/trackers/SessionTracker.native.js +70 -0
- package/lib-esm/trackers/index.d.ts +3 -0
- package/lib-esm/trackers/index.js +5 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +1 -2
- package/lib-esm/types/inputs.d.ts +16 -0
- package/lib-esm/types/trackers.d.ts +22 -0
- package/lib-esm/utils/index.d.ts +2 -0
- package/lib-esm/utils/index.js +2 -0
- package/lib-esm/utils/trackerConfigHelpers.d.ts +5 -0
- package/lib-esm/utils/trackerConfigHelpers.js +11 -0
- package/lib-esm/utils/trackerConfigHelpers.native.d.ts +5 -0
- package/lib-esm/utils/trackerConfigHelpers.native.js +10 -0
- package/lib-esm/utils/trackerHelpers.d.ts +9 -0
- package/lib-esm/utils/trackerHelpers.js +40 -0
- package/package.json +5 -4
- package/src/errors/validation.ts +8 -0
- package/src/index.ts +3 -1
- package/src/providers/pinpoint/apis/configureAutoTrack.ts +49 -0
- package/src/providers/pinpoint/apis/index.ts +1 -0
- package/src/providers/pinpoint/apis/record.ts +1 -1
- package/src/providers/pinpoint/index.ts +6 -2
- package/src/providers/pinpoint/types/index.ts +5 -1
- package/src/providers/pinpoint/types/inputs.ts +9 -1
- package/src/trackers/EventTracker.ts +135 -0
- package/src/trackers/PageViewTracker.ts +160 -0
- package/src/trackers/SessionTracker.native.ts +106 -0
- package/src/trackers/SessionTracker.ts +106 -0
- package/src/trackers/index.ts +6 -0
- package/src/types/index.ts +4 -13
- package/src/types/inputs.ts +25 -0
- package/src/types/trackers.ts +35 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/trackerConfigHelpers.native.ts +18 -0
- package/src/utils/trackerConfigHelpers.ts +19 -0
- package/src/utils/trackerHelpers.ts +57 -0
- package/lib/types/analytics.d.ts +0 -50
- package/lib-esm/types/analytics.d.ts +0 -50
- package/src/types/analytics.ts +0 -70
- /package/lib/types/{analytics.js → trackers.js} +0 -0
- /package/lib-esm/types/{analytics.js → trackers.js} +0 -0
package/lib/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';
|
package/lib/types/inputs.d.ts
CHANGED
|
@@ -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
|
*/
|
|
@@ -17,3 +18,18 @@ export type AnalyticsIdentifyUserInput<ServiceOptions extends AnalyticsServiceOp
|
|
|
17
18
|
*/
|
|
18
19
|
options?: ServiceOptions;
|
|
19
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
|
+
}
|
package/lib/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/utils/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.getAnalyticsUserAgentString = exports.getAnalyticsUserAgent = exports.isAnalyticsEnabled = exports.disableAnalytics = exports.enableAnalytics = exports.EventBuffer = exports.groupBy = exports.resolveCredentials = void 0;
|
|
5
|
+
exports.validateTrackerConfiguration = exports.updateProviderTrackers = exports.getAnalyticsUserAgentString = exports.getAnalyticsUserAgent = exports.isAnalyticsEnabled = exports.disableAnalytics = exports.enableAnalytics = exports.EventBuffer = exports.groupBy = exports.resolveCredentials = void 0;
|
|
6
6
|
var resolveCredentials_1 = require("./resolveCredentials");
|
|
7
7
|
Object.defineProperty(exports, "resolveCredentials", { enumerable: true, get: function () { return resolveCredentials_1.resolveCredentials; } });
|
|
8
8
|
var groupBy_1 = require("./groupBy");
|
|
@@ -16,3 +16,7 @@ Object.defineProperty(exports, "isAnalyticsEnabled", { enumerable: true, get: fu
|
|
|
16
16
|
var userAgent_1 = require("./userAgent");
|
|
17
17
|
Object.defineProperty(exports, "getAnalyticsUserAgent", { enumerable: true, get: function () { return userAgent_1.getAnalyticsUserAgent; } });
|
|
18
18
|
Object.defineProperty(exports, "getAnalyticsUserAgentString", { enumerable: true, get: function () { return userAgent_1.getAnalyticsUserAgentString; } });
|
|
19
|
+
var trackerHelpers_1 = require("./trackerHelpers");
|
|
20
|
+
Object.defineProperty(exports, "updateProviderTrackers", { enumerable: true, get: function () { return trackerHelpers_1.updateProviderTrackers; } });
|
|
21
|
+
var trackerConfigHelpers_1 = require("./trackerConfigHelpers");
|
|
22
|
+
Object.defineProperty(exports, "validateTrackerConfiguration", { enumerable: true, get: function () { return trackerConfigHelpers_1.validateTrackerConfiguration; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.validateTrackerConfiguration = void 0;
|
|
6
|
+
var errors_1 = require("../errors");
|
|
7
|
+
/**
|
|
8
|
+
* Validates tracker configuration.
|
|
9
|
+
*/
|
|
10
|
+
var validateTrackerConfiguration = function (input) {
|
|
11
|
+
(0, errors_1.assertValidationError)(input.type === 'event' ||
|
|
12
|
+
input.type === 'pageView' ||
|
|
13
|
+
input.type === 'session', errors_1.AnalyticsValidationErrorCode.InvalidTracker);
|
|
14
|
+
};
|
|
15
|
+
exports.validateTrackerConfiguration = validateTrackerConfiguration;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.validateTrackerConfiguration = void 0;
|
|
6
|
+
var errors_1 = require("../errors");
|
|
7
|
+
/**
|
|
8
|
+
* Validates tracker configuration.
|
|
9
|
+
*/
|
|
10
|
+
var validateTrackerConfiguration = function (input) {
|
|
11
|
+
// React Native only supports session tracking
|
|
12
|
+
(0, errors_1.assertValidationError)(input.type === 'session', errors_1.AnalyticsValidationErrorCode.UnsupportedPlatform);
|
|
13
|
+
};
|
|
14
|
+
exports.validateTrackerConfiguration = validateTrackerConfiguration;
|
|
@@ -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,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.updateProviderTrackers = void 0;
|
|
6
|
+
var trackers_1 = require("../trackers");
|
|
7
|
+
/**
|
|
8
|
+
* Updates a provider's trackers as appropriate for the provided auto-track configuration.
|
|
9
|
+
*
|
|
10
|
+
* @remark
|
|
11
|
+
* This utility will mutate the provider's configured trackers via `providerTrackers`.
|
|
12
|
+
*/
|
|
13
|
+
var updateProviderTrackers = function (input, providerEventRecorder, providerTrackers) {
|
|
14
|
+
var trackerInstance;
|
|
15
|
+
var trackerType = input.type;
|
|
16
|
+
var currentTracker = providerTrackers[trackerType];
|
|
17
|
+
// Check if the tracker was disabled & should be cleaned up
|
|
18
|
+
if (!input.enable) {
|
|
19
|
+
if (currentTracker) {
|
|
20
|
+
currentTracker.cleanup();
|
|
21
|
+
delete providerTrackers[trackerType];
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Re-configure the existing tracker, or create & configure an instance if it doesn't exist yet
|
|
26
|
+
if (currentTracker) {
|
|
27
|
+
currentTracker.configure(providerEventRecorder, input.options);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Create a new tracker instance for the type
|
|
31
|
+
if (trackerType === 'event') {
|
|
32
|
+
trackerInstance = new trackers_1.EventTracker(providerEventRecorder, input.options);
|
|
33
|
+
}
|
|
34
|
+
else if (trackerType === 'pageView') {
|
|
35
|
+
trackerInstance = new trackers_1.PageViewTracker(providerEventRecorder, input.options);
|
|
36
|
+
}
|
|
37
|
+
else if (trackerType === 'session') {
|
|
38
|
+
trackerInstance = new trackers_1.SessionTracker(providerEventRecorder, input.options);
|
|
39
|
+
}
|
|
40
|
+
if (trackerInstance) {
|
|
41
|
+
providerTrackers[trackerType] = trackerInstance;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.updateProviderTrackers = updateProviderTrackers;
|
|
@@ -4,6 +4,8 @@ export declare enum AnalyticsValidationErrorCode {
|
|
|
4
4
|
NoCredentials = "NoCredentials",
|
|
5
5
|
NoEventName = "NoEventName",
|
|
6
6
|
NoRegion = "NoRegion",
|
|
7
|
+
InvalidTracker = "InvalidTracker",
|
|
8
|
+
UnsupportedPlatform = "UnsupportedPlatform",
|
|
7
9
|
NoTrackingId = "NoTrackingId",
|
|
8
10
|
InvalidFlushSize = "InvalidFlushSize"
|
|
9
11
|
}
|
|
@@ -7,6 +7,8 @@ export var AnalyticsValidationErrorCode;
|
|
|
7
7
|
AnalyticsValidationErrorCode["NoCredentials"] = "NoCredentials";
|
|
8
8
|
AnalyticsValidationErrorCode["NoEventName"] = "NoEventName";
|
|
9
9
|
AnalyticsValidationErrorCode["NoRegion"] = "NoRegion";
|
|
10
|
+
AnalyticsValidationErrorCode["InvalidTracker"] = "InvalidTracker";
|
|
11
|
+
AnalyticsValidationErrorCode["UnsupportedPlatform"] = "UnsupportedPlatform";
|
|
10
12
|
AnalyticsValidationErrorCode["NoTrackingId"] = "NoTrackingId";
|
|
11
13
|
AnalyticsValidationErrorCode["InvalidFlushSize"] = "InvalidFlushSize";
|
|
12
14
|
})(AnalyticsValidationErrorCode || (AnalyticsValidationErrorCode = {}));
|
|
@@ -23,6 +25,12 @@ export var validationErrorMap = (_a = {},
|
|
|
23
25
|
_a[AnalyticsValidationErrorCode.NoRegion] = {
|
|
24
26
|
message: 'Missing region.',
|
|
25
27
|
},
|
|
28
|
+
_a[AnalyticsValidationErrorCode.InvalidTracker] = {
|
|
29
|
+
message: 'Invalid tracker type specified.',
|
|
30
|
+
},
|
|
31
|
+
_a[AnalyticsValidationErrorCode.UnsupportedPlatform] = {
|
|
32
|
+
message: 'Only session tracking is supported on React Native.',
|
|
33
|
+
},
|
|
26
34
|
_a[AnalyticsValidationErrorCode.InvalidFlushSize] = {
|
|
27
35
|
message: 'Invalid FlushSize, it should be smaller than BufferSize',
|
|
28
36
|
},
|
package/lib-esm/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { record, identifyUser, RecordInput, IdentifyUserInput,
|
|
1
|
+
export { record, identifyUser, configureAutoTrack, flushEvents, RecordInput, IdentifyUserInput, ConfigureAutoTrackInput, } from './providers/pinpoint';
|
|
2
2
|
export { enable, disable } from './apis';
|
|
3
3
|
export { AnalyticsError } from './errors';
|
package/lib-esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export { record, identifyUser, flushEvents, } from './providers/pinpoint';
|
|
3
|
+
export { record, identifyUser, configureAutoTrack, flushEvents, } from './providers/pinpoint';
|
|
4
4
|
export { enable, disable } from './apis';
|
|
5
5
|
export { AnalyticsError } from './errors';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfigureAutoTrackInput } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Configures automatic event tracking for Pinpoint. This API will automatically transmit an analytic event when
|
|
4
|
+
* configured events are detected within your application. This can include: DOM element events (via the `event`
|
|
5
|
+
* tracker), session events (via the `session` tracker), and page view events (via the `pageView` tracker).
|
|
6
|
+
*
|
|
7
|
+
* @remark Only session tracking is currently supported on React Native.
|
|
8
|
+
*
|
|
9
|
+
* @param {ConfigureAutoTrackInput} params The input object to configure auto track behavior.
|
|
10
|
+
*
|
|
11
|
+
* @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
|
|
12
|
+
* @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
|
|
13
|
+
* configuration is incorrect.
|
|
14
|
+
*/
|
|
15
|
+
export declare const configureAutoTrack: (input: ConfigureAutoTrackInput) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { updateProviderTrackers, validateTrackerConfiguration, } from '../../../utils';
|
|
4
|
+
import { record } from './record';
|
|
5
|
+
// Configured Tracker instances for Pinpoint
|
|
6
|
+
var configuredTrackers = {};
|
|
7
|
+
// Callback that will emit an appropriate event to Pinpoint when required by the Tracker
|
|
8
|
+
var emitTrackingEvent = function (eventName, attributes) {
|
|
9
|
+
record({
|
|
10
|
+
name: eventName,
|
|
11
|
+
attributes: attributes,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Configures automatic event tracking for Pinpoint. This API will automatically transmit an analytic event when
|
|
16
|
+
* configured events are detected within your application. This can include: DOM element events (via the `event`
|
|
17
|
+
* tracker), session events (via the `session` tracker), and page view events (via the `pageView` tracker).
|
|
18
|
+
*
|
|
19
|
+
* @remark Only session tracking is currently supported on React Native.
|
|
20
|
+
*
|
|
21
|
+
* @param {ConfigureAutoTrackInput} params The input object to configure auto track behavior.
|
|
22
|
+
*
|
|
23
|
+
* @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
|
|
24
|
+
* @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
|
|
25
|
+
* configuration is incorrect.
|
|
26
|
+
*/
|
|
27
|
+
export var configureAutoTrack = function (input) {
|
|
28
|
+
validateTrackerConfiguration(input);
|
|
29
|
+
// Initialize or update this provider's trackers
|
|
30
|
+
updateProviderTrackers(input, emitTrackingEvent, configuredTrackers);
|
|
31
|
+
};
|
|
@@ -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 { Hub, ConsoleLogger } from '@aws-amplify/core';
|
|
4
|
-
import { AMPLIFY_SYMBOL, AnalyticsAction } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { AMPLIFY_SYMBOL, AnalyticsAction, } from '@aws-amplify/core/internals/utils';
|
|
5
5
|
import { record as recordCore } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
6
6
|
import { AnalyticsValidationErrorCode, assertValidationError, } from '../../../errors';
|
|
7
7
|
import { getAnalyticsUserAgentString, isAnalyticsEnabled, } from '../../../utils';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { record, identifyUser, flushEvents } from './apis';
|
|
2
|
-
export { RecordInput, IdentifyUserInput } from './types/inputs';
|
|
1
|
+
export { record, identifyUser, flushEvents, configureAutoTrack } from './apis';
|
|
2
|
+
export { RecordInput, IdentifyUserInput, ConfigureAutoTrackInput, } from './types/inputs';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { RecordInput, IdentifyUserInput } from './inputs';
|
|
1
|
+
export { RecordInput, IdentifyUserInput, ConfigureAutoTrackInput, } from './inputs';
|
|
2
2
|
export { IdentifyUserOptions } from './options';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
2
2
|
import { IdentifyUserOptions } from '.';
|
|
3
|
-
import { AnalyticsIdentifyUserInput } from '../../../types';
|
|
3
|
+
import { AnalyticsConfigureAutoTrackInput, AnalyticsIdentifyUserInput } from '../../../types';
|
|
4
4
|
/**
|
|
5
5
|
* Input type for Pinpoint record API.
|
|
6
6
|
*/
|
|
@@ -9,3 +9,7 @@ export type RecordInput = PinpointAnalyticsEvent;
|
|
|
9
9
|
* Input type for Pinpoint identifyUser API.
|
|
10
10
|
*/
|
|
11
11
|
export type IdentifyUserInput = AnalyticsIdentifyUserInput<IdentifyUserOptions>;
|
|
12
|
+
/**
|
|
13
|
+
* Input type for Pinpoint configureAutoTrack API.
|
|
14
|
+
*/
|
|
15
|
+
export type ConfigureAutoTrackInput = AnalyticsConfigureAutoTrackInput;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EventTrackingOptions, TrackerEventRecorder, TrackerInterface } from '../types/trackers';
|
|
2
|
+
export declare class EventTracker implements TrackerInterface {
|
|
3
|
+
private trackerActive;
|
|
4
|
+
private options;
|
|
5
|
+
private eventRecorder;
|
|
6
|
+
constructor(eventRecorder: TrackerEventRecorder, options?: EventTrackingOptions);
|
|
7
|
+
configure(eventRecorder: TrackerEventRecorder, options?: EventTrackingOptions): void;
|
|
8
|
+
cleanup(): void;
|
|
9
|
+
private handleDocEvent;
|
|
10
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
4
|
+
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
5
|
+
var DEFAULT_EVENTS = ['click'];
|
|
6
|
+
var DEFAULT_SELECTOR_PREFIX = 'data-amplify-analytics-';
|
|
7
|
+
var DEFAULT_EVENT_NAME = 'event'; // Default event name as sent to the analytics provider
|
|
8
|
+
var logger = new ConsoleLogger('EventTracker');
|
|
9
|
+
var EventTracker = /** @class */ (function () {
|
|
10
|
+
function EventTracker(eventRecorder, options) {
|
|
11
|
+
this.options = {};
|
|
12
|
+
this.trackerActive = false;
|
|
13
|
+
this.eventRecorder = eventRecorder;
|
|
14
|
+
this.handleDocEvent = this.handleDocEvent.bind(this);
|
|
15
|
+
this.configure(eventRecorder, options);
|
|
16
|
+
}
|
|
17
|
+
EventTracker.prototype.configure = function (eventRecorder, options) {
|
|
18
|
+
var _this = this;
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
|
+
this.eventRecorder = eventRecorder;
|
|
21
|
+
// Clean up any existing listeners
|
|
22
|
+
this.cleanup();
|
|
23
|
+
// Apply defaults
|
|
24
|
+
this.options = {
|
|
25
|
+
attributes: (_a = options === null || options === void 0 ? void 0 : options.attributes) !== null && _a !== void 0 ? _a : undefined,
|
|
26
|
+
events: (_b = options === null || options === void 0 ? void 0 : options.events) !== null && _b !== void 0 ? _b : DEFAULT_EVENTS,
|
|
27
|
+
selectorPrefix: (_c = options === null || options === void 0 ? void 0 : options.selectorPrefix) !== null && _c !== void 0 ? _c : DEFAULT_SELECTOR_PREFIX,
|
|
28
|
+
};
|
|
29
|
+
// Register event listeners
|
|
30
|
+
if (isBrowser()) {
|
|
31
|
+
(_d = this.options.events) === null || _d === void 0 ? void 0 : _d.forEach(function (targetEvent) {
|
|
32
|
+
document.addEventListener(targetEvent, _this.handleDocEvent, {
|
|
33
|
+
capture: true,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
this.trackerActive = true;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
EventTracker.prototype.cleanup = function () {
|
|
40
|
+
var _this = this;
|
|
41
|
+
var _a;
|
|
42
|
+
// No-op if document listener is not active
|
|
43
|
+
if (!this.trackerActive) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// Clean up event listeners
|
|
47
|
+
(_a = this.options.events) === null || _a === void 0 ? void 0 : _a.forEach(function (targetEvent) {
|
|
48
|
+
document.removeEventListener(targetEvent, _this.handleDocEvent, {
|
|
49
|
+
capture: true,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
EventTracker.prototype.handleDocEvent = function (event) {
|
|
54
|
+
var _a;
|
|
55
|
+
/**
|
|
56
|
+
* Example DOM element:
|
|
57
|
+
*
|
|
58
|
+
* ```
|
|
59
|
+
* <button
|
|
60
|
+
* data-amplify-analytics-on="click"
|
|
61
|
+
* data-amplify-analytics-name="click"
|
|
62
|
+
* data-amplify-analytics-attrs="attr1:attr1_value,attr2:attr2_value"
|
|
63
|
+
* />
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
var triggerSelector = "[".concat(this.options.selectorPrefix, "on]");
|
|
67
|
+
var attrSelector = "".concat(this.options.selectorPrefix, "attrs");
|
|
68
|
+
var eventNameSelector = "".concat(this.options.selectorPrefix, "name");
|
|
69
|
+
var eventSource = event.target;
|
|
70
|
+
// Validate that the triggering event type is being tracked
|
|
71
|
+
if (!((_a = this.options.events) === null || _a === void 0 ? void 0 : _a.includes(event.type))) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (eventSource instanceof HTMLElement) {
|
|
75
|
+
var target = eventSource.closest(triggerSelector);
|
|
76
|
+
if (target) {
|
|
77
|
+
// Parse event name from the element
|
|
78
|
+
var eventName = target.getAttribute(eventNameSelector) || DEFAULT_EVENT_NAME;
|
|
79
|
+
// Parse attributes from the element
|
|
80
|
+
var elementAttributes_1 = {};
|
|
81
|
+
var rawElementAttributes = target.getAttribute(attrSelector);
|
|
82
|
+
rawElementAttributes === null || rawElementAttributes === void 0 ? void 0 : rawElementAttributes.split(/\s*,\s*/).forEach(function (attr) {
|
|
83
|
+
var tmp = attr.trim().split(/\s*:\s*/);
|
|
84
|
+
elementAttributes_1[tmp[0]] = tmp[1];
|
|
85
|
+
});
|
|
86
|
+
// Assemble final list of attributes
|
|
87
|
+
var attributes = Object.assign({
|
|
88
|
+
type: event.type,
|
|
89
|
+
target: "".concat(target.localName, " with id ").concat(target.id),
|
|
90
|
+
}, this.options.attributes, elementAttributes_1);
|
|
91
|
+
logger.debug('Recording automatically tracked DOM event', {
|
|
92
|
+
eventName: eventName,
|
|
93
|
+
attributes: attributes,
|
|
94
|
+
});
|
|
95
|
+
this.eventRecorder(eventName, attributes);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return EventTracker;
|
|
100
|
+
}());
|
|
101
|
+
export { EventTracker };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PageViewTrackingOptions, TrackerEventRecorder, TrackerInterface } from '../types/trackers';
|
|
2
|
+
export declare class PageViewTracker implements TrackerInterface {
|
|
3
|
+
private trackerActive;
|
|
4
|
+
private options;
|
|
5
|
+
private eventRecorder;
|
|
6
|
+
private spaTrackingActive;
|
|
7
|
+
private pushStateProxy?;
|
|
8
|
+
private replaceStateProxy?;
|
|
9
|
+
private originalPushState;
|
|
10
|
+
private originalReplaceState;
|
|
11
|
+
constructor(eventRecorder: TrackerEventRecorder, options?: PageViewTrackingOptions);
|
|
12
|
+
configure(eventRecorder: TrackerEventRecorder, options?: PageViewTrackingOptions): void;
|
|
13
|
+
cleanup(): void;
|
|
14
|
+
private setupSPATracking;
|
|
15
|
+
private setupMPATracking;
|
|
16
|
+
private handleLocationChange;
|
|
17
|
+
private urlHasChanged;
|
|
18
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
4
|
+
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
5
|
+
var logger = new ConsoleLogger('PageViewTracker');
|
|
6
|
+
var DEFAULT_EVENT_NAME = 'pageView';
|
|
7
|
+
var DEFAULT_APP_TYPE = 'singlePage';
|
|
8
|
+
var DEFAULT_URL_PROVIDER = function () {
|
|
9
|
+
return window.location.origin + window.location.pathname;
|
|
10
|
+
};
|
|
11
|
+
var PREV_URL_STORAGE_KEY = 'aws-amplify-analytics-prevUrl';
|
|
12
|
+
var PageViewTracker = /** @class */ (function () {
|
|
13
|
+
function PageViewTracker(eventRecorder, options) {
|
|
14
|
+
this.options = {};
|
|
15
|
+
this.trackerActive = true;
|
|
16
|
+
this.eventRecorder = eventRecorder;
|
|
17
|
+
this.spaTrackingActive = false;
|
|
18
|
+
this.handleLocationChange = this.handleLocationChange.bind(this);
|
|
19
|
+
this.configure(eventRecorder, options);
|
|
20
|
+
}
|
|
21
|
+
PageViewTracker.prototype.configure = function (eventRecorder, options) {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f;
|
|
23
|
+
this.eventRecorder = eventRecorder;
|
|
24
|
+
// Clean up any existing listeners
|
|
25
|
+
this.cleanup();
|
|
26
|
+
// Apply defaults
|
|
27
|
+
this.options = {
|
|
28
|
+
appType: (_a = options === null || options === void 0 ? void 0 : options.appType) !== null && _a !== void 0 ? _a : DEFAULT_APP_TYPE,
|
|
29
|
+
attributes: (_b = options === null || options === void 0 ? void 0 : options.attributes) !== null && _b !== void 0 ? _b : undefined,
|
|
30
|
+
eventName: (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.eventName) !== null && _d !== void 0 ? _d : DEFAULT_EVENT_NAME,
|
|
31
|
+
urlProvider: (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.urlProvider) !== null && _f !== void 0 ? _f : DEFAULT_URL_PROVIDER,
|
|
32
|
+
};
|
|
33
|
+
// Configure SPA or MPA page view tracking
|
|
34
|
+
if (isBrowser()) {
|
|
35
|
+
if (this.options.appType === 'singlePage') {
|
|
36
|
+
this.setupSPATracking();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.setupMPATracking();
|
|
40
|
+
}
|
|
41
|
+
this.trackerActive = true;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
PageViewTracker.prototype.cleanup = function () {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
// No-op if document listener is not active
|
|
47
|
+
if (!this.trackerActive) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Clean up SPA page view listeners
|
|
51
|
+
if (this.spaTrackingActive) {
|
|
52
|
+
window.history.pushState = this.originalPushState;
|
|
53
|
+
window.history.replaceState = this.originalReplaceState;
|
|
54
|
+
(_a = this.pushStateProxy) === null || _a === void 0 ? void 0 : _a.revoke();
|
|
55
|
+
(_b = this.replaceStateProxy) === null || _b === void 0 ? void 0 : _b.revoke();
|
|
56
|
+
window.removeEventListener('popstate', this.handleLocationChange);
|
|
57
|
+
this.spaTrackingActive = false;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
PageViewTracker.prototype.setupSPATracking = function () {
|
|
61
|
+
var _this = this;
|
|
62
|
+
if (!this.spaTrackingActive) {
|
|
63
|
+
// Configure proxies on History APIs
|
|
64
|
+
this.pushStateProxy = Proxy.revocable(window.history.pushState, {
|
|
65
|
+
apply: function (target, thisArg, args) {
|
|
66
|
+
var proxiedResult = target.apply(thisArg, args);
|
|
67
|
+
_this.handleLocationChange();
|
|
68
|
+
return proxiedResult;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
this.replaceStateProxy = Proxy.revocable(window.history.replaceState, {
|
|
72
|
+
apply: function (target, thisArg, args) {
|
|
73
|
+
var proxiedResult = target.apply(thisArg, args);
|
|
74
|
+
_this.handleLocationChange();
|
|
75
|
+
return proxiedResult;
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
this.originalPushState = window.history.pushState;
|
|
79
|
+
this.originalReplaceState = window.history.replaceState;
|
|
80
|
+
window.history.pushState = this.pushStateProxy.proxy;
|
|
81
|
+
window.history.replaceState = this.replaceStateProxy.proxy;
|
|
82
|
+
window.addEventListener('popstate', this.handleLocationChange);
|
|
83
|
+
sessionStorage.removeItem(PREV_URL_STORAGE_KEY);
|
|
84
|
+
this.spaTrackingActive = true;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
PageViewTracker.prototype.setupMPATracking = function () {
|
|
88
|
+
this.handleLocationChange();
|
|
89
|
+
};
|
|
90
|
+
PageViewTracker.prototype.handleLocationChange = function () {
|
|
91
|
+
var currentUrl = this.options.urlProvider();
|
|
92
|
+
var eventName = this.options.eventName || DEFAULT_EVENT_NAME;
|
|
93
|
+
if (this.urlHasChanged()) {
|
|
94
|
+
sessionStorage.setItem(PREV_URL_STORAGE_KEY, currentUrl);
|
|
95
|
+
// Assemble attribute list
|
|
96
|
+
var attributes = Object.assign({
|
|
97
|
+
url: currentUrl,
|
|
98
|
+
}, this.options.attributes);
|
|
99
|
+
logger.debug('Recording automatically tracked page view event', {
|
|
100
|
+
eventName: eventName,
|
|
101
|
+
attributes: attributes,
|
|
102
|
+
});
|
|
103
|
+
this.eventRecorder(eventName, attributes);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
PageViewTracker.prototype.urlHasChanged = function () {
|
|
107
|
+
var prevUrl = sessionStorage.getItem(PREV_URL_STORAGE_KEY);
|
|
108
|
+
var currUrl = this.options.urlProvider();
|
|
109
|
+
return currUrl !== prevUrl;
|
|
110
|
+
};
|
|
111
|
+
return PageViewTracker;
|
|
112
|
+
}());
|
|
113
|
+
export { PageViewTracker };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SessionTrackingOptions, TrackerEventRecorder, TrackerInterface } from '../types/trackers';
|
|
2
|
+
export declare class SessionTracker implements TrackerInterface {
|
|
3
|
+
private options;
|
|
4
|
+
private eventRecorder;
|
|
5
|
+
private sessionTrackingActive;
|
|
6
|
+
private initialEventSent;
|
|
7
|
+
constructor(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions);
|
|
8
|
+
configure(eventRecorder: TrackerEventRecorder, options?: SessionTrackingOptions): void;
|
|
9
|
+
cleanup(): void;
|
|
10
|
+
private handleStateChange;
|
|
11
|
+
private sessionStarted;
|
|
12
|
+
private sessionStopped;
|
|
13
|
+
}
|