@aws-amplify/analytics 7.0.1-api-v6-models.8035dfc.0 → 7.0.1-api-v6-models.3eb7748.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) 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/types/buffer.d.ts +2 -2
  8. package/lib/providers/kinesis-firehose/apis/flushEvents.js +2 -1
  9. package/lib/providers/kinesis-firehose/apis/record.js +2 -1
  10. package/lib/providers/kinesis-firehose/types/buffer.d.ts +2 -2
  11. package/lib/providers/personalize/apis/flushEvents.js +2 -1
  12. package/lib/providers/personalize/apis/record.js +61 -46
  13. package/lib/providers/personalize/types/buffer.d.ts +2 -2
  14. package/lib/providers/personalize/utils/autoTrackMedia.js +2 -1
  15. package/lib/providers/personalize/utils/cachedSession.d.ts +2 -2
  16. package/lib/providers/personalize/utils/cachedSession.js +23 -14
  17. package/lib/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
  18. package/lib/providers/pinpoint/apis/configureAutoTrack.js +35 -0
  19. package/lib/providers/pinpoint/apis/flushEvents.js +2 -1
  20. package/lib/providers/pinpoint/apis/identifyUser.js +4 -5
  21. package/lib/providers/pinpoint/apis/index.d.ts +1 -0
  22. package/lib/providers/pinpoint/apis/index.js +3 -1
  23. package/lib/providers/pinpoint/apis/record.js +1 -1
  24. package/lib/providers/pinpoint/index.d.ts +2 -2
  25. package/lib/providers/pinpoint/index.js +2 -1
  26. package/lib/providers/pinpoint/types/index.d.ts +1 -2
  27. package/lib/providers/pinpoint/types/index.js +0 -3
  28. package/lib/providers/pinpoint/types/inputs.d.ts +5 -1
  29. package/lib/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
  30. package/lib/trackers/EventTracker.d.ts +10 -0
  31. package/lib/trackers/EventTracker.js +104 -0
  32. package/lib/trackers/PageViewTracker.d.ts +18 -0
  33. package/lib/trackers/PageViewTracker.js +116 -0
  34. package/lib/trackers/SessionTracker.d.ts +13 -0
  35. package/lib/trackers/SessionTracker.js +73 -0
  36. package/lib/trackers/SessionTracker.native.d.ts +13 -0
  37. package/lib/trackers/SessionTracker.native.js +73 -0
  38. package/lib/trackers/index.d.ts +3 -0
  39. package/lib/trackers/index.js +11 -0
  40. package/lib/tsconfig.tsbuildinfo +1 -1
  41. package/lib/types/index.d.ts +1 -2
  42. package/lib/types/inputs.d.ts +17 -3
  43. package/lib/types/options.d.ts +1 -1
  44. package/lib/types/trackers.d.ts +22 -0
  45. package/lib/utils/eventBuffer/EventBuffer.js +2 -2
  46. package/lib/utils/index.d.ts +2 -0
  47. package/lib/utils/index.js +5 -1
  48. package/lib/utils/resolveCredentials.d.ts +1 -6
  49. package/lib/utils/trackerConfigHelpers.d.ts +5 -0
  50. package/lib/utils/trackerConfigHelpers.js +15 -0
  51. package/lib/utils/trackerConfigHelpers.native.d.ts +5 -0
  52. package/lib/utils/trackerConfigHelpers.native.js +14 -0
  53. package/lib/utils/trackerHelpers.d.ts +9 -0
  54. package/lib/utils/trackerHelpers.js +44 -0
  55. package/lib-esm/errors/validation.d.ts +2 -0
  56. package/lib-esm/errors/validation.js +8 -0
  57. package/lib-esm/index.d.ts +1 -1
  58. package/lib-esm/index.js +1 -1
  59. package/lib-esm/providers/kinesis/apis/flushEvents.js +2 -1
  60. package/lib-esm/providers/kinesis/apis/record.js +2 -1
  61. package/lib-esm/providers/kinesis/types/buffer.d.ts +2 -2
  62. package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +2 -1
  63. package/lib-esm/providers/kinesis-firehose/apis/record.js +3 -2
  64. package/lib-esm/providers/kinesis-firehose/types/buffer.d.ts +2 -2
  65. package/lib-esm/providers/personalize/apis/flushEvents.js +2 -1
  66. package/lib-esm/providers/personalize/apis/record.js +61 -46
  67. package/lib-esm/providers/personalize/types/buffer.d.ts +2 -2
  68. package/lib-esm/providers/personalize/utils/autoTrackMedia.js +2 -1
  69. package/lib-esm/providers/personalize/utils/cachedSession.d.ts +2 -2
  70. package/lib-esm/providers/personalize/utils/cachedSession.js +24 -15
  71. package/lib-esm/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
  72. package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +31 -0
  73. package/lib-esm/providers/pinpoint/apis/flushEvents.js +2 -1
  74. package/lib-esm/providers/pinpoint/apis/identifyUser.js +5 -6
  75. package/lib-esm/providers/pinpoint/apis/index.d.ts +1 -0
  76. package/lib-esm/providers/pinpoint/apis/index.js +1 -0
  77. package/lib-esm/providers/pinpoint/apis/record.js +3 -3
  78. package/lib-esm/providers/pinpoint/index.d.ts +2 -2
  79. package/lib-esm/providers/pinpoint/index.js +1 -1
  80. package/lib-esm/providers/pinpoint/types/index.d.ts +1 -2
  81. package/lib-esm/providers/pinpoint/types/index.js +1 -1
  82. package/lib-esm/providers/pinpoint/types/inputs.d.ts +5 -1
  83. package/lib-esm/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
  84. package/lib-esm/trackers/EventTracker.d.ts +10 -0
  85. package/lib-esm/trackers/EventTracker.js +101 -0
  86. package/lib-esm/trackers/PageViewTracker.d.ts +18 -0
  87. package/lib-esm/trackers/PageViewTracker.js +113 -0
  88. package/lib-esm/trackers/SessionTracker.d.ts +13 -0
  89. package/lib-esm/trackers/SessionTracker.js +70 -0
  90. package/lib-esm/trackers/SessionTracker.native.d.ts +13 -0
  91. package/lib-esm/trackers/SessionTracker.native.js +70 -0
  92. package/lib-esm/trackers/index.d.ts +3 -0
  93. package/lib-esm/trackers/index.js +5 -0
  94. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  95. package/lib-esm/types/index.d.ts +1 -2
  96. package/lib-esm/types/inputs.d.ts +17 -3
  97. package/lib-esm/types/options.d.ts +1 -1
  98. package/lib-esm/types/trackers.d.ts +22 -0
  99. package/lib-esm/utils/eventBuffer/EventBuffer.js +1 -1
  100. package/lib-esm/utils/index.d.ts +2 -0
  101. package/lib-esm/utils/index.js +2 -0
  102. package/lib-esm/utils/resolveCredentials.d.ts +1 -6
  103. package/lib-esm/utils/trackerConfigHelpers.d.ts +5 -0
  104. package/lib-esm/utils/trackerConfigHelpers.js +11 -0
  105. package/lib-esm/utils/trackerConfigHelpers.native.d.ts +5 -0
  106. package/lib-esm/utils/trackerConfigHelpers.native.js +10 -0
  107. package/lib-esm/utils/trackerHelpers.d.ts +9 -0
  108. package/lib-esm/utils/trackerHelpers.js +40 -0
  109. package/package.json +6 -7
  110. package/src/errors/validation.ts +8 -0
  111. package/src/index.ts +3 -1
  112. package/src/providers/kinesis/apis/flushEvents.ts +2 -4
  113. package/src/providers/kinesis/apis/record.ts +2 -4
  114. package/src/providers/kinesis/types/buffer.ts +2 -2
  115. package/src/providers/kinesis-firehose/apis/flushEvents.ts +2 -4
  116. package/src/providers/kinesis-firehose/apis/record.ts +3 -5
  117. package/src/providers/kinesis-firehose/types/buffer.ts +2 -2
  118. package/src/providers/personalize/apis/flushEvents.ts +2 -4
  119. package/src/providers/personalize/apis/record.ts +5 -7
  120. package/src/providers/personalize/types/buffer.ts +2 -2
  121. package/src/providers/personalize/utils/autoTrackMedia.ts +2 -1
  122. package/src/providers/personalize/utils/cachedSession.ts +8 -7
  123. package/src/providers/pinpoint/apis/configureAutoTrack.ts +49 -0
  124. package/src/providers/pinpoint/apis/flushEvents.ts +2 -4
  125. package/src/providers/pinpoint/apis/identifyUser.ts +6 -3
  126. package/src/providers/pinpoint/apis/index.ts +1 -0
  127. package/src/providers/pinpoint/apis/record.ts +2 -3
  128. package/src/providers/pinpoint/index.ts +6 -2
  129. package/src/providers/pinpoint/types/index.ts +5 -2
  130. package/src/providers/pinpoint/types/inputs.ts +9 -1
  131. package/src/trackers/EventTracker.ts +135 -0
  132. package/src/trackers/PageViewTracker.ts +160 -0
  133. package/src/trackers/SessionTracker.native.ts +106 -0
  134. package/src/trackers/SessionTracker.ts +106 -0
  135. package/src/trackers/index.ts +6 -0
  136. package/src/types/index.ts +4 -13
  137. package/src/types/inputs.ts +26 -3
  138. package/src/types/options.ts +1 -1
  139. package/src/types/trackers.ts +35 -0
  140. package/src/utils/eventBuffer/EventBuffer.ts +1 -1
  141. package/src/utils/index.ts +2 -0
  142. package/src/utils/trackerConfigHelpers.native.ts +18 -0
  143. package/src/utils/trackerConfigHelpers.ts +19 -0
  144. package/src/utils/trackerHelpers.ts +57 -0
  145. package/lib/providers/pinpoint/types/errors.d.ts +0 -9
  146. package/lib/providers/pinpoint/types/errors.js +0 -15
  147. package/lib/types/analytics.d.ts +0 -50
  148. package/lib-esm/providers/pinpoint/types/errors.d.ts +0 -9
  149. package/lib-esm/providers/pinpoint/types/errors.js +0 -12
  150. package/lib-esm/types/analytics.d.ts +0 -50
  151. package/src/providers/pinpoint/types/errors.ts +0 -12
  152. package/src/types/analytics.ts +0 -70
  153. /package/lib/types/{analytics.js → trackers.js} +0 -0
  154. /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
+ }
@@ -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/internals/utils';
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) {
@@ -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';
@@ -5,3 +5,5 @@ export { groupBy } from './groupBy';
5
5
  export { EventBuffer, } from './eventBuffer';
6
6
  export { enableAnalytics, disableAnalytics, isAnalyticsEnabled, } from './statusHelpers';
7
7
  export { getAnalyticsUserAgent, getAnalyticsUserAgentString, } from './userAgent';
8
+ export { updateProviderTrackers } from './trackerHelpers';
9
+ export { validateTrackerConfiguration } from './trackerConfigHelpers';
@@ -1,9 +1,4 @@
1
1
  export declare const resolveCredentials: () => Promise<{
2
- credentials: {
3
- accessKeyId: string;
4
- secretAccessKey: string;
5
- sessionToken?: string | undefined;
6
- expiration?: Date | undefined;
7
- };
2
+ credentials: import("@aws-amplify/core/lib-esm/libraryUtils").AWSCredentials;
8
3
  identityId: string | undefined;
9
4
  }>;
@@ -0,0 +1,5 @@
1
+ import { AnalyticsConfigureAutoTrackInput } from '../types';
2
+ /**
3
+ * Validates tracker configuration.
4
+ */
5
+ export declare const validateTrackerConfiguration: (input: AnalyticsConfigureAutoTrackInput) => void;
@@ -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,5 @@
1
+ import { AnalyticsConfigureAutoTrackInput } from '../types';
2
+ /**
3
+ * Validates tracker configuration.
4
+ */
5
+ export declare const validateTrackerConfiguration: (input: AnalyticsConfigureAutoTrackInput) => void;
@@ -0,0 +1,10 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { AnalyticsValidationErrorCode, assertValidationError } from '../errors';
4
+ /**
5
+ * Validates tracker configuration.
6
+ */
7
+ export var validateTrackerConfiguration = function (input) {
8
+ // React Native only supports session tracking
9
+ assertValidationError(input.type === 'session', AnalyticsValidationErrorCode.UnsupportedPlatform);
10
+ };
@@ -0,0 +1,9 @@
1
+ import { TrackerEventRecorder, TrackerInterface, TrackerType } from '../types/trackers';
2
+ import { ConfigureAutoTrackInput } from '../providers/pinpoint';
3
+ /**
4
+ * Updates a provider's trackers as appropriate for the provided auto-track configuration.
5
+ *
6
+ * @remark
7
+ * This utility will mutate the provider's configured trackers via `providerTrackers`.
8
+ */
9
+ export declare const updateProviderTrackers: (input: ConfigureAutoTrackInput, providerEventRecorder: TrackerEventRecorder, providerTrackers: Partial<Record<TrackerType, TrackerInterface>>) => void;
@@ -0,0 +1,40 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { EventTracker, PageViewTracker, SessionTracker } from '../trackers';
4
+ /**
5
+ * Updates a provider's trackers as appropriate for the provided auto-track configuration.
6
+ *
7
+ * @remark
8
+ * This utility will mutate the provider's configured trackers via `providerTrackers`.
9
+ */
10
+ export var updateProviderTrackers = function (input, providerEventRecorder, providerTrackers) {
11
+ var trackerInstance;
12
+ var trackerType = input.type;
13
+ var currentTracker = providerTrackers[trackerType];
14
+ // Check if the tracker was disabled & should be cleaned up
15
+ if (!input.enable) {
16
+ if (currentTracker) {
17
+ currentTracker.cleanup();
18
+ delete providerTrackers[trackerType];
19
+ }
20
+ return;
21
+ }
22
+ // Re-configure the existing tracker, or create & configure an instance if it doesn't exist yet
23
+ if (currentTracker) {
24
+ currentTracker.configure(providerEventRecorder, input.options);
25
+ return;
26
+ }
27
+ // Create a new tracker instance for the type
28
+ if (trackerType === 'event') {
29
+ trackerInstance = new EventTracker(providerEventRecorder, input.options);
30
+ }
31
+ else if (trackerType === 'pageView') {
32
+ trackerInstance = new PageViewTracker(providerEventRecorder, input.options);
33
+ }
34
+ else if (trackerType === 'session') {
35
+ trackerInstance = new SessionTracker(providerEventRecorder, input.options);
36
+ }
37
+ if (trackerInstance) {
38
+ providerTrackers[trackerType] = trackerInstance;
39
+ }
40
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/analytics",
3
- "version": "7.0.1-api-v6-models.8035dfc.0+8035dfc",
3
+ "version": "7.0.1-api-v6-models.3eb7748.0+3eb7748",
4
4
  "description": "Analytics category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -96,16 +96,15 @@
96
96
  "@aws-sdk/client-kinesis": "3.398.0",
97
97
  "@aws-sdk/client-personalize-events": "3.398.0",
98
98
  "@smithy/util-utf8": "2.0.0",
99
- "tslib": "^2.5.0",
100
- "uuid": "^9.0.0"
99
+ "tslib": "^2.5.0"
101
100
  },
102
101
  "peerDependencies": {
103
- "@aws-amplify/core": "6.0.1-api-v6-models.8035dfc.0+8035dfc"
102
+ "@aws-amplify/core": "6.0.1-api-v6-models.3eb7748.0+3eb7748"
104
103
  },
105
104
  "devDependencies": {
106
- "@aws-amplify/core": "6.0.1-api-v6-models.8035dfc.0+8035dfc",
105
+ "@aws-amplify/core": "6.0.1-api-v6-models.3eb7748.0+3eb7748",
106
+ "@aws-amplify/react-native": "1.0.1-api-v6-models.3eb7748.0+3eb7748",
107
107
  "@aws-sdk/types": "3.398.0",
108
- "@types/uuid": "^9.0.0",
109
108
  "typescript": "5.0.2"
110
109
  },
111
110
  "jest": {
@@ -152,5 +151,5 @@
152
151
  "<rootDir>/src/setupTests.ts"
153
152
  ]
154
153
  },
155
- "gitHead": "8035dfc20dda8f7b4d116616e89e72d889ceb5f1"
154
+ "gitHead": "3eb7748aee2fcdea705c93904d1f30ff596649fa"
156
155
  }
@@ -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
- flushEvents,
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
- AnalyticsAction,
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
- AnalyticsAction,
15
- ConsoleLogger,
16
- } from '@aws-amplify/core/internals/utils';
13
+ import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
14
+ import { ConsoleLogger } from '@aws-amplify/core';
17
15
 
18
16
  const logger = new ConsoleLogger('Kinesis');
19
17
 
@@ -1,8 +1,8 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { AWSCredentials } from '@aws-amplify/core/internals/utils';
4
5
  import { EventBufferConfig } from '../../../utils';
5
- import { Credentials } from '@aws-sdk/types';
6
6
  import { KinesisShard } from '../../../types';
7
7
 
8
8
  export type KinesisBufferEvent = KinesisShard & {
@@ -13,7 +13,7 @@ export type KinesisBufferEvent = KinesisShard & {
13
13
 
14
14
  export type KinesisEventBufferConfig = EventBufferConfig & {
15
15
  region: string;
16
- credentials: Credentials;
16
+ credentials: AWSCredentials;
17
17
  identityId?: string;
18
18
  resendLimit?: number;
19
19
  userAgentValue?: string;
@@ -6,10 +6,8 @@ import {
6
6
  getAnalyticsUserAgentString,
7
7
  resolveCredentials,
8
8
  } from '../../../utils';
9
- import {
10
- AnalyticsAction,
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
- AnalyticsAction,
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 Logger('KinesisFirehose');
15
+ const logger = new ConsoleLogger('KinesisFirehose');
18
16
 
19
17
  export const record = ({ streamName, data }: RecordInput): void => {
20
18
  if (!isAnalyticsEnabled()) {
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { EventBufferConfig } from '../../../utils';
5
5
  import { KinesisStream } from '../../../types';
6
- import { Credentials } from '@aws-sdk/types';
6
+ import { AWSCredentials } from '@aws-amplify/core/internals/utils';
7
7
 
8
8
  export type KinesisFirehoseBufferEvent = KinesisStream & {
9
9
  event: Uint8Array;
@@ -13,7 +13,7 @@ export type KinesisFirehoseBufferEvent = KinesisStream & {
13
13
 
14
14
  export type KinesisFirehoseEventBufferConfig = EventBufferConfig & {
15
15
  region: string;
16
- credentials: Credentials;
16
+ credentials: AWSCredentials;
17
17
  identityId?: string;
18
18
  resendLimit?: number;
19
19
  userAgentValue?: string;
@@ -6,10 +6,8 @@ import {
6
6
  getAnalyticsUserAgentString,
7
7
  resolveCredentials,
8
8
  } from '../../../utils';
9
- import {
10
- AnalyticsAction,
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
- AnalyticsAction,
19
- ConsoleLogger,
20
- } from '@aws-amplify/core/internals/utils';
17
+ import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
18
+ import { ConsoleLogger } from '@aws-amplify/core';
21
19
  import {
22
20
  IDENTIFY_EVENT_TYPE,
23
21
  MEDIA_AUTO_TRACK_EVENT_TYPE,
@@ -39,10 +37,10 @@ export const record = ({
39
37
  const { region, trackingId, bufferSize, flushSize, flushInterval } =
40
38
  resolveConfig();
41
39
  resolveCredentials()
42
- .then(({ credentials, identityId }) => {
40
+ .then(async ({ credentials, identityId }) => {
43
41
  const timestamp = Date.now();
44
42
  const { sessionId: cachedSessionId, userId: cachedUserId } =
45
- resolveCachedSession(trackingId);
43
+ await resolveCachedSession();
46
44
  if (eventType === IDENTIFY_EVENT_TYPE) {
47
45
  updateCachedSession(
48
46
  typeof properties.userId === 'string' ? properties.userId : '',
@@ -54,7 +52,7 @@ export const record = ({
54
52
  }
55
53
 
56
54
  const { sessionId: updatedSessionId, userId: updatedUserId } =
57
- resolveCachedSession(trackingId);
55
+ await resolveCachedSession();
58
56
 
59
57
  const eventBuffer = getEventBuffer({
60
58
  region,
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { PersonalizeEvent } from './';
5
5
  import { EventBufferConfig } from '../../../utils';
6
- import { Credentials } from '@aws-sdk/types';
6
+ import { AWSCredentials } from '@aws-amplify/core/internals/utils';
7
7
 
8
8
  export type PersonalizeBufferEvent = {
9
9
  trackingId: string;
@@ -15,7 +15,7 @@ export type PersonalizeBufferEvent = {
15
15
 
16
16
  export type PersonalizeBufferConfig = EventBufferConfig & {
17
17
  region: string;
18
- credentials: Credentials;
18
+ credentials: AWSCredentials;
19
19
  identityId?: string;
20
20
  userAgentValue?: string;
21
21
  };
@@ -3,7 +3,8 @@
3
3
 
4
4
  import { EventBuffer } from '../../../utils';
5
5
  import { PersonalizeBufferEvent, PersonalizeEvent } from '../types';
6
- import { ConsoleLogger, isBrowser } from '@aws-amplify/core/internals/utils';
6
+ import { isBrowser } from '@aws-amplify/core/internals/utils';
7
+ import { ConsoleLogger } from '@aws-amplify/core';
7
8
 
8
9
  enum HTML5_MEDIA_EVENT {
9
10
  'PLAY' = 'play',
@@ -2,8 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { Cache } from '@aws-amplify/core';
5
- import { isBrowser } from '@aws-amplify/core/internals/utils';
6
- import { v4 as uuid } from 'uuid';
5
+ import { isBrowser, amplifyUuid } from '@aws-amplify/core/internals/utils';
7
6
 
8
7
  const PERSONALIZE_CACHE_USERID = '_awsct_uid';
9
8
  const PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
@@ -27,14 +26,16 @@ const setCache = (key: string, value: unknown) => {
27
26
  });
28
27
  };
29
28
 
30
- export const resolveCachedSession = (trackingId: string) => {
31
- let sessionId: string | undefined = getCache(PERSONALIZE_CACHE_SESSIONID);
29
+ export const resolveCachedSession = async () => {
30
+ let sessionId: string | undefined = await getCache(
31
+ PERSONALIZE_CACHE_SESSIONID
32
+ );
32
33
  if (!sessionId) {
33
- sessionId = uuid();
34
+ sessionId = amplifyUuid();
34
35
  setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
35
36
  }
36
37
 
37
- const userId: string | undefined = getCache(PERSONALIZE_CACHE_USERID);
38
+ const userId: string | undefined = await getCache(PERSONALIZE_CACHE_USERID);
38
39
 
39
40
  return {
40
41
  sessionId,
@@ -58,7 +59,7 @@ export const updateCachedSession = (
58
59
  !!currentSessionId && !currentUserId && !!newUserId;
59
60
 
60
61
  if (isRequireNewSession) {
61
- const newSessionId = uuid();
62
+ const newSessionId = amplifyUuid();
62
63
  setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
63
64
  setCache(PERSONALIZE_CACHE_USERID, newUserId);
64
65
  } else if (isRequireUpdateSession) {
@@ -0,0 +1,49 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AnalyticsValidationErrorCode } from '../../../errors';
5
+ import {
6
+ TrackerType,
7
+ TrackerAttributes,
8
+ TrackerInterface,
9
+ } from '../../../types/trackers';
10
+ import {
11
+ updateProviderTrackers,
12
+ validateTrackerConfiguration,
13
+ } from '../../../utils';
14
+ import { ConfigureAutoTrackInput } from '../types';
15
+ import { record } from './record';
16
+
17
+ // Configured Tracker instances for Pinpoint
18
+ const configuredTrackers: Partial<Record<TrackerType, TrackerInterface>> = {};
19
+
20
+ // Callback that will emit an appropriate event to Pinpoint when required by the Tracker
21
+ const emitTrackingEvent = (
22
+ eventName: string,
23
+ attributes: TrackerAttributes
24
+ ) => {
25
+ record({
26
+ name: eventName,
27
+ attributes,
28
+ });
29
+ };
30
+
31
+ /**
32
+ * Configures automatic event tracking for Pinpoint. This API will automatically transmit an analytic event when
33
+ * configured events are detected within your application. This can include: DOM element events (via the `event`
34
+ * tracker), session events (via the `session` tracker), and page view events (via the `pageView` tracker).
35
+ *
36
+ * @remark Only session tracking is currently supported on React Native.
37
+ *
38
+ * @param {ConfigureAutoTrackInput} params The input object to configure auto track behavior.
39
+ *
40
+ * @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
41
+ * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
42
+ * configuration is incorrect.
43
+ */
44
+ export const configureAutoTrack = (input: ConfigureAutoTrackInput): void => {
45
+ validateTrackerConfiguration(input);
46
+
47
+ // Initialize or update this provider's trackers
48
+ updateProviderTrackers(input, emitTrackingEvent, configuredTrackers);
49
+ };
@@ -3,10 +3,8 @@
3
3
 
4
4
  import { resolveConfig, resolveCredentials } from '../utils';
5
5
  import { flushEvents as flushEventsCore } from '@aws-amplify/core/internals/providers/pinpoint';
6
- import {
7
- AnalyticsAction,
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 { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
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, UpdateEndpointException } from '../types';
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?.serviceOptions ?? {};
66
+ const { userAttributes } = options ?? {};
64
67
  updateEndpoint({
65
68
  appId,
66
69
  category: 'Analytics',
@@ -3,4 +3,5 @@
3
3
 
4
4
  export { record } from './record';
5
5
  export { identifyUser } from './identifyUser';
6
+ export { configureAutoTrack } from './configureAutoTrack';
6
7
  export { flushEvents } from './flushEvents';
@@ -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 Logger('Analytics');
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 { RecordInput, IdentifyUserInput } from './types/inputs';
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 { UpdateEndpointException } from './errors';
5
- export { RecordInput, IdentifyUserInput } from './inputs';
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 { AnalyticsIdentifyUserInput } from '../../../types';
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;