@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.
Files changed (136) hide show
  1. package/lib/errors/validation.d.ts +2 -0
  2. package/lib/errors/validation.js +8 -0
  3. package/lib/index.d.ts +1 -1
  4. package/lib/index.js +2 -1
  5. package/lib/providers/kinesis/apis/flushEvents.js +2 -1
  6. package/lib/providers/kinesis/apis/record.js +2 -1
  7. package/lib/providers/kinesis-firehose/apis/flushEvents.js +2 -1
  8. package/lib/providers/kinesis-firehose/apis/record.js +2 -1
  9. package/lib/providers/personalize/apis/flushEvents.js +2 -1
  10. package/lib/providers/personalize/apis/record.js +2 -1
  11. package/lib/providers/personalize/utils/autoTrackMedia.js +2 -1
  12. package/lib/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
  13. package/lib/providers/pinpoint/apis/configureAutoTrack.js +35 -0
  14. package/lib/providers/pinpoint/apis/flushEvents.js +2 -1
  15. package/lib/providers/pinpoint/apis/identifyUser.js +4 -5
  16. package/lib/providers/pinpoint/apis/index.d.ts +1 -0
  17. package/lib/providers/pinpoint/apis/index.js +3 -1
  18. package/lib/providers/pinpoint/apis/record.js +1 -1
  19. package/lib/providers/pinpoint/index.d.ts +2 -2
  20. package/lib/providers/pinpoint/index.js +2 -1
  21. package/lib/providers/pinpoint/types/index.d.ts +1 -2
  22. package/lib/providers/pinpoint/types/index.js +0 -3
  23. package/lib/providers/pinpoint/types/inputs.d.ts +5 -1
  24. package/lib/trackers/EventTracker.d.ts +10 -0
  25. package/lib/trackers/EventTracker.js +104 -0
  26. package/lib/trackers/PageViewTracker.d.ts +18 -0
  27. package/lib/trackers/PageViewTracker.js +116 -0
  28. package/lib/trackers/SessionTracker.d.ts +13 -0
  29. package/lib/trackers/SessionTracker.js +73 -0
  30. package/lib/trackers/SessionTracker.native.d.ts +13 -0
  31. package/lib/trackers/SessionTracker.native.js +73 -0
  32. package/lib/trackers/index.d.ts +3 -0
  33. package/lib/trackers/index.js +11 -0
  34. package/lib/tsconfig.tsbuildinfo +1 -1
  35. package/lib/types/index.d.ts +1 -2
  36. package/lib/types/inputs.d.ts +17 -3
  37. package/lib/types/options.d.ts +1 -1
  38. package/lib/types/trackers.d.ts +22 -0
  39. package/lib/utils/eventBuffer/EventBuffer.js +2 -2
  40. package/lib/utils/index.d.ts +2 -0
  41. package/lib/utils/index.js +5 -1
  42. package/lib/utils/trackerConfigHelpers.d.ts +5 -0
  43. package/lib/utils/trackerConfigHelpers.js +15 -0
  44. package/lib/utils/trackerConfigHelpers.native.d.ts +5 -0
  45. package/lib/utils/trackerConfigHelpers.native.js +14 -0
  46. package/lib/utils/trackerHelpers.d.ts +9 -0
  47. package/lib/utils/trackerHelpers.js +44 -0
  48. package/lib-esm/errors/validation.d.ts +2 -0
  49. package/lib-esm/errors/validation.js +8 -0
  50. package/lib-esm/index.d.ts +1 -1
  51. package/lib-esm/index.js +1 -1
  52. package/lib-esm/providers/kinesis/apis/flushEvents.js +2 -1
  53. package/lib-esm/providers/kinesis/apis/record.js +2 -1
  54. package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +2 -1
  55. package/lib-esm/providers/kinesis-firehose/apis/record.js +3 -2
  56. package/lib-esm/providers/personalize/apis/flushEvents.js +2 -1
  57. package/lib-esm/providers/personalize/apis/record.js +2 -1
  58. package/lib-esm/providers/personalize/utils/autoTrackMedia.js +2 -1
  59. package/lib-esm/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
  60. package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +31 -0
  61. package/lib-esm/providers/pinpoint/apis/flushEvents.js +2 -1
  62. package/lib-esm/providers/pinpoint/apis/identifyUser.js +5 -6
  63. package/lib-esm/providers/pinpoint/apis/index.d.ts +1 -0
  64. package/lib-esm/providers/pinpoint/apis/index.js +1 -0
  65. package/lib-esm/providers/pinpoint/apis/record.js +3 -3
  66. package/lib-esm/providers/pinpoint/index.d.ts +2 -2
  67. package/lib-esm/providers/pinpoint/index.js +1 -1
  68. package/lib-esm/providers/pinpoint/types/index.d.ts +1 -2
  69. package/lib-esm/providers/pinpoint/types/index.js +1 -1
  70. package/lib-esm/providers/pinpoint/types/inputs.d.ts +5 -1
  71. package/lib-esm/trackers/EventTracker.d.ts +10 -0
  72. package/lib-esm/trackers/EventTracker.js +101 -0
  73. package/lib-esm/trackers/PageViewTracker.d.ts +18 -0
  74. package/lib-esm/trackers/PageViewTracker.js +113 -0
  75. package/lib-esm/trackers/SessionTracker.d.ts +13 -0
  76. package/lib-esm/trackers/SessionTracker.js +70 -0
  77. package/lib-esm/trackers/SessionTracker.native.d.ts +13 -0
  78. package/lib-esm/trackers/SessionTracker.native.js +70 -0
  79. package/lib-esm/trackers/index.d.ts +3 -0
  80. package/lib-esm/trackers/index.js +5 -0
  81. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  82. package/lib-esm/types/index.d.ts +1 -2
  83. package/lib-esm/types/inputs.d.ts +17 -3
  84. package/lib-esm/types/options.d.ts +1 -1
  85. package/lib-esm/types/trackers.d.ts +22 -0
  86. package/lib-esm/utils/eventBuffer/EventBuffer.js +1 -1
  87. package/lib-esm/utils/index.d.ts +2 -0
  88. package/lib-esm/utils/index.js +2 -0
  89. package/lib-esm/utils/trackerConfigHelpers.d.ts +5 -0
  90. package/lib-esm/utils/trackerConfigHelpers.js +11 -0
  91. package/lib-esm/utils/trackerConfigHelpers.native.d.ts +5 -0
  92. package/lib-esm/utils/trackerConfigHelpers.native.js +10 -0
  93. package/lib-esm/utils/trackerHelpers.d.ts +9 -0
  94. package/lib-esm/utils/trackerHelpers.js +40 -0
  95. package/package.json +5 -4
  96. package/src/errors/validation.ts +8 -0
  97. package/src/index.ts +3 -1
  98. package/src/providers/kinesis/apis/flushEvents.ts +2 -4
  99. package/src/providers/kinesis/apis/record.ts +2 -4
  100. package/src/providers/kinesis-firehose/apis/flushEvents.ts +2 -4
  101. package/src/providers/kinesis-firehose/apis/record.ts +3 -5
  102. package/src/providers/personalize/apis/flushEvents.ts +2 -4
  103. package/src/providers/personalize/apis/record.ts +2 -4
  104. package/src/providers/personalize/utils/autoTrackMedia.ts +2 -1
  105. package/src/providers/pinpoint/apis/configureAutoTrack.ts +49 -0
  106. package/src/providers/pinpoint/apis/flushEvents.ts +2 -4
  107. package/src/providers/pinpoint/apis/identifyUser.ts +6 -3
  108. package/src/providers/pinpoint/apis/index.ts +1 -0
  109. package/src/providers/pinpoint/apis/record.ts +2 -3
  110. package/src/providers/pinpoint/index.ts +6 -2
  111. package/src/providers/pinpoint/types/index.ts +5 -2
  112. package/src/providers/pinpoint/types/inputs.ts +9 -1
  113. package/src/trackers/EventTracker.ts +135 -0
  114. package/src/trackers/PageViewTracker.ts +160 -0
  115. package/src/trackers/SessionTracker.native.ts +106 -0
  116. package/src/trackers/SessionTracker.ts +106 -0
  117. package/src/trackers/index.ts +6 -0
  118. package/src/types/index.ts +4 -13
  119. package/src/types/inputs.ts +26 -3
  120. package/src/types/options.ts +1 -1
  121. package/src/types/trackers.ts +35 -0
  122. package/src/utils/eventBuffer/EventBuffer.ts +1 -1
  123. package/src/utils/index.ts +2 -0
  124. package/src/utils/trackerConfigHelpers.native.ts +18 -0
  125. package/src/utils/trackerConfigHelpers.ts +19 -0
  126. package/src/utils/trackerHelpers.ts +57 -0
  127. package/lib/providers/pinpoint/types/errors.d.ts +0 -9
  128. package/lib/providers/pinpoint/types/errors.js +0 -15
  129. package/lib/types/analytics.d.ts +0 -50
  130. package/lib-esm/providers/pinpoint/types/errors.d.ts +0 -9
  131. package/lib-esm/providers/pinpoint/types/errors.js +0 -12
  132. package/lib-esm/types/analytics.d.ts +0 -50
  133. package/src/providers/pinpoint/types/errors.ts +0 -12
  134. package/src/types/analytics.ts +0 -70
  135. /package/lib/types/{analytics.js → trackers.js} +0 -0
  136. /package/lib-esm/types/{analytics.js → trackers.js} +0 -0
@@ -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
+ });
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Base type for service options.
3
3
  */
4
- export type AnalyticsServiceOptions = any;
4
+ export type AnalyticsServiceOptions = Record<string, unknown>;
@@ -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
+ }
@@ -4,8 +4,8 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.EventBuffer = void 0;
6
6
  var tslib_1 = require("tslib");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var logger = new utils_1.ConsoleLogger('EventBuffer');
7
+ var core_1 = require("@aws-amplify/core");
8
+ var logger = new core_1.ConsoleLogger('EventBuffer');
9
9
  var EventBuffer = /** @class */ (function () {
10
10
  function EventBuffer(config, getAnalyticsClient) {
11
11
  this.list = [];
@@ -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';
@@ -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,5 @@
1
+ import { AnalyticsConfigureAutoTrackInput } from '../types';
2
+ /**
3
+ * Validates tracker configuration.
4
+ */
5
+ export declare const validateTrackerConfiguration: (input: AnalyticsConfigureAutoTrackInput) => void;
@@ -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,5 @@
1
+ import { AnalyticsConfigureAutoTrackInput } from '../types';
2
+ /**
3
+ * Validates tracker configuration.
4
+ */
5
+ export declare const validateTrackerConfiguration: (input: AnalyticsConfigureAutoTrackInput) => void;
@@ -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
  },
@@ -1,3 +1,3 @@
1
- export { record, identifyUser, RecordInput, IdentifyUserInput, flushEvents, } from './providers/pinpoint';
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';
@@ -3,7 +3,8 @@
3
3
  import { resolveConfig } from '../utils/resolveConfig';
4
4
  import { getAnalyticsUserAgentString, resolveCredentials, } from '../../../utils';
5
5
  import { getEventBuffer } from '../utils/getEventBuffer';
6
- import { AnalyticsAction, ConsoleLogger, } from '@aws-amplify/core/internals/utils';
6
+ import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
7
+ import { ConsoleLogger } from '@aws-amplify/core';
7
8
  var logger = new ConsoleLogger('Kinesis');
8
9
  /**
9
10
  * Flushes all buffered Kinesis events to the service.
@@ -4,7 +4,8 @@ import { getEventBuffer } from '../utils/getEventBuffer';
4
4
  import { resolveConfig } from '../utils/resolveConfig';
5
5
  import { getAnalyticsUserAgentString, isAnalyticsEnabled, resolveCredentials, } from '../../../utils';
6
6
  import { fromUtf8 } from '@smithy/util-utf8';
7
- import { AnalyticsAction, ConsoleLogger, } from '@aws-amplify/core/internals/utils';
7
+ import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
8
+ import { ConsoleLogger } from '@aws-amplify/core';
8
9
  var logger = new ConsoleLogger('Kinesis');
9
10
  export var record = function (_a) {
10
11
  var streamName = _a.streamName, partitionKey = _a.partitionKey, data = _a.data;
@@ -2,7 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { getEventBuffer, resolveConfig } from '../utils';
4
4
  import { getAnalyticsUserAgentString, resolveCredentials, } from '../../../utils';
5
- import { AnalyticsAction, ConsoleLogger, } from '@aws-amplify/core/internals/utils';
5
+ import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
6
+ import { ConsoleLogger } from '@aws-amplify/core';
6
7
  var logger = new ConsoleLogger('KinesisFirehose');
7
8
  /**
8
9
  * Flushes all buffered Kinesis events to the service.
@@ -3,8 +3,9 @@
3
3
  import { getEventBuffer, resolveConfig } from '../utils';
4
4
  import { getAnalyticsUserAgentString, isAnalyticsEnabled, resolveCredentials, } from '../../../utils';
5
5
  import { fromUtf8 } from '@smithy/util-utf8';
6
- import { AnalyticsAction, ConsoleLogger as Logger, } from '@aws-amplify/core/internals/utils';
7
- var logger = new Logger('KinesisFirehose');
6
+ import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
7
+ import { ConsoleLogger } from '@aws-amplify/core';
8
+ var logger = new ConsoleLogger('KinesisFirehose');
8
9
  export var record = function (_a) {
9
10
  var streamName = _a.streamName, data = _a.data;
10
11
  if (!isAnalyticsEnabled()) {
@@ -2,7 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { getEventBuffer, resolveConfig } from '../utils';
4
4
  import { getAnalyticsUserAgentString, resolveCredentials, } from '../../../utils';
5
- import { AnalyticsAction, ConsoleLogger, } from '@aws-amplify/core/internals/utils';
5
+ import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
6
+ import { ConsoleLogger } from '@aws-amplify/core';
6
7
  var logger = new ConsoleLogger('Personalize');
7
8
  /**
8
9
  * Flushes all buffered Personalize events to the service.
@@ -3,7 +3,8 @@
3
3
  import { __awaiter, __generator } from "tslib";
4
4
  import { autoTrackMedia, getEventBuffer, resolveCachedSession, resolveConfig, updateCachedSession, } from '../utils';
5
5
  import { getAnalyticsUserAgentString, isAnalyticsEnabled, resolveCredentials, } from '../../../utils';
6
- import { AnalyticsAction, ConsoleLogger, } from '@aws-amplify/core/internals/utils';
6
+ import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
7
+ import { ConsoleLogger } from '@aws-amplify/core';
7
8
  import { IDENTIFY_EVENT_TYPE, MEDIA_AUTO_TRACK_EVENT_TYPE, } from '../utils/constants';
8
9
  var logger = new ConsoleLogger('Personalize');
9
10
  export var record = function (_a) {
@@ -1,7 +1,8 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { __assign, __awaiter, __generator, __rest } from "tslib";
4
- import { ConsoleLogger, isBrowser } from '@aws-amplify/core/internals/utils';
4
+ import { isBrowser } from '@aws-amplify/core/internals/utils';
5
+ import { ConsoleLogger } from '@aws-amplify/core';
5
6
  var HTML5_MEDIA_EVENT;
6
7
  (function (HTML5_MEDIA_EVENT) {
7
8
  HTML5_MEDIA_EVENT["PLAY"] = "play";
@@ -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
+ };
@@ -2,7 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { resolveConfig, resolveCredentials } from '../utils';
4
4
  import { flushEvents as flushEventsCore } from '@aws-amplify/core/internals/providers/pinpoint';
5
- import { AnalyticsAction, ConsoleLogger, } from '@aws-amplify/core/internals/utils';
5
+ import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
6
+ import { ConsoleLogger } from '@aws-amplify/core';
6
7
  import { getAnalyticsUserAgentString } from '../../../utils';
7
8
  var logger = new ConsoleLogger('Analytics');
8
9
  /**
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { __awaiter, __generator } from "tslib";
4
4
  import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
5
- import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
5
+ import { updateEndpoint, } from '@aws-amplify/core/internals/providers/pinpoint';
6
6
  import { getAnalyticsUserAgentString } from '../../../utils';
7
7
  import { resolveConfig, resolveCredentials } from '../utils';
8
8
  /**
@@ -54,14 +54,13 @@ export var identifyUser = function (_a) {
54
54
  var userId = _a.userId, userProfile = _a.userProfile, options = _a.options;
55
55
  return __awaiter(void 0, void 0, void 0, function () {
56
56
  var _b, credentials, identityId, _c, appId, region, userAttributes;
57
- var _d;
58
- return __generator(this, function (_e) {
59
- switch (_e.label) {
57
+ return __generator(this, function (_d) {
58
+ switch (_d.label) {
60
59
  case 0: return [4 /*yield*/, resolveCredentials()];
61
60
  case 1:
62
- _b = _e.sent(), credentials = _b.credentials, identityId = _b.identityId;
61
+ _b = _d.sent(), credentials = _b.credentials, identityId = _b.identityId;
63
62
  _c = resolveConfig(), appId = _c.appId, region = _c.region;
64
- userAttributes = ((_d = options === null || options === void 0 ? void 0 : options.serviceOptions) !== null && _d !== void 0 ? _d : {}).userAttributes;
63
+ userAttributes = (options !== null && options !== void 0 ? options : {}).userAttributes;
65
64
  updateEndpoint({
66
65
  appId: appId,
67
66
  category: 'Analytics',
@@ -1,3 +1,4 @@
1
1
  export { record } from './record';
2
2
  export { identifyUser } from './identifyUser';
3
+ export { configureAutoTrack } from './configureAutoTrack';
3
4
  export { flushEvents } from './flushEvents';
@@ -2,4 +2,5 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  export { record } from './record';
4
4
  export { identifyUser } from './identifyUser';
5
+ export { configureAutoTrack } from './configureAutoTrack';
5
6
  export { flushEvents } from './flushEvents';
@@ -1,12 +1,12 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { Hub } from '@aws-amplify/core';
4
- import { AMPLIFY_SYMBOL, AnalyticsAction, ConsoleLogger as Logger, } from '@aws-amplify/core/internals/utils';
3
+ import { Hub, ConsoleLogger } from '@aws-amplify/core';
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';
8
8
  import { resolveConfig, resolveCredentials } from '../utils';
9
- var logger = new Logger('Analytics');
9
+ var logger = new ConsoleLogger('Analytics');
10
10
  /**
11
11
  * Records an Analytic event to Pinpoint. Events will be buffered and periodically sent to Pinpoint.
12
12
  *
@@ -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,3 +1,3 @@
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 './apis';
3
+ export { record, identifyUser, flushEvents, configureAutoTrack } from './apis';
@@ -1,3 +1,2 @@
1
- export { UpdateEndpointException } from './errors';
2
- export { RecordInput, IdentifyUserInput } from './inputs';
1
+ export { RecordInput, IdentifyUserInput, ConfigureAutoTrackInput, } from './inputs';
3
2
  export { IdentifyUserOptions } from './options';
@@ -1,3 +1,3 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- export { UpdateEndpointException } from './errors';
3
+ export {};
@@ -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
+ }