@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
+ }
@@ -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; } });
@@ -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,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;
@@ -1,5 +1,5 @@
1
+ import { AWSCredentials } from '@aws-amplify/core/internals/utils';
1
2
  import { EventBufferConfig } from '../../../utils';
2
- import { Credentials } from '@aws-sdk/types';
3
3
  import { KinesisShard } from '../../../types';
4
4
  export type KinesisBufferEvent = KinesisShard & {
5
5
  event: Uint8Array;
@@ -8,7 +8,7 @@ export type KinesisBufferEvent = KinesisShard & {
8
8
  };
9
9
  export type KinesisEventBufferConfig = EventBufferConfig & {
10
10
  region: string;
11
- credentials: Credentials;
11
+ credentials: AWSCredentials;
12
12
  identityId?: string;
13
13
  resendLimit?: number;
14
14
  userAgentValue?: string;
@@ -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()) {
@@ -1,6 +1,6 @@
1
1
  import { EventBufferConfig } from '../../../utils';
2
2
  import { KinesisStream } from '../../../types';
3
- import { Credentials } from '@aws-sdk/types';
3
+ import { AWSCredentials } from '@aws-amplify/core/internals/utils';
4
4
  export type KinesisFirehoseBufferEvent = KinesisStream & {
5
5
  event: Uint8Array;
6
6
  retryCount: number;
@@ -8,7 +8,7 @@ export type KinesisFirehoseBufferEvent = KinesisStream & {
8
8
  };
9
9
  export type KinesisFirehoseEventBufferConfig = EventBufferConfig & {
10
10
  region: string;
11
- credentials: Credentials;
11
+ credentials: AWSCredentials;
12
12
  identityId?: string;
13
13
  resendLimit?: number;
14
14
  userAgentValue?: string;
@@ -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.
@@ -1,8 +1,10 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ import { __awaiter, __generator } from "tslib";
3
4
  import { autoTrackMedia, getEventBuffer, resolveCachedSession, resolveConfig, updateCachedSession, } from '../utils';
4
5
  import { getAnalyticsUserAgentString, isAnalyticsEnabled, resolveCredentials, } from '../../../utils';
5
- 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';
6
8
  import { IDENTIFY_EVENT_TYPE, MEDIA_AUTO_TRACK_EVENT_TYPE, } from '../utils/constants';
7
9
  var logger = new ConsoleLogger('Personalize');
8
10
  export var record = function (_a) {
@@ -15,52 +17,65 @@ export var record = function (_a) {
15
17
  resolveCredentials()
16
18
  .then(function (_a) {
17
19
  var credentials = _a.credentials, identityId = _a.identityId;
18
- var timestamp = Date.now();
19
- var _b = resolveCachedSession(trackingId), cachedSessionId = _b.sessionId, cachedUserId = _b.userId;
20
- if (eventType === IDENTIFY_EVENT_TYPE) {
21
- updateCachedSession(typeof properties.userId === 'string' ? properties.userId : '', cachedSessionId, cachedUserId);
22
- }
23
- else if (!!userId) {
24
- updateCachedSession(userId, cachedSessionId, cachedUserId);
25
- }
26
- var _c = resolveCachedSession(trackingId), updatedSessionId = _c.sessionId, updatedUserId = _c.userId;
27
- var eventBuffer = getEventBuffer({
28
- region: region,
29
- flushSize: flushSize,
30
- flushInterval: flushInterval,
31
- bufferSize: bufferSize,
32
- credentials: credentials,
33
- identityId: identityId,
34
- userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
35
- });
36
- if (eventType === MEDIA_AUTO_TRACK_EVENT_TYPE) {
37
- autoTrackMedia({
38
- trackingId: trackingId,
39
- sessionId: updatedSessionId,
40
- userId: updatedUserId,
41
- event: {
42
- eventId: eventId,
43
- eventType: eventType,
44
- properties: properties,
45
- },
46
- }, eventBuffer);
47
- }
48
- else {
49
- eventBuffer.append({
50
- trackingId: trackingId,
51
- sessionId: updatedSessionId,
52
- userId: updatedUserId,
53
- event: {
54
- eventId: eventId,
55
- eventType: eventType,
56
- properties: properties,
57
- },
58
- timestamp: timestamp,
20
+ return __awaiter(void 0, void 0, void 0, function () {
21
+ var timestamp, _b, cachedSessionId, cachedUserId, _c, updatedSessionId, updatedUserId, eventBuffer;
22
+ return __generator(this, function (_d) {
23
+ switch (_d.label) {
24
+ case 0:
25
+ timestamp = Date.now();
26
+ return [4 /*yield*/, resolveCachedSession()];
27
+ case 1:
28
+ _b = _d.sent(), cachedSessionId = _b.sessionId, cachedUserId = _b.userId;
29
+ if (eventType === IDENTIFY_EVENT_TYPE) {
30
+ updateCachedSession(typeof properties.userId === 'string' ? properties.userId : '', cachedSessionId, cachedUserId);
31
+ }
32
+ else if (!!userId) {
33
+ updateCachedSession(userId, cachedSessionId, cachedUserId);
34
+ }
35
+ return [4 /*yield*/, resolveCachedSession()];
36
+ case 2:
37
+ _c = _d.sent(), updatedSessionId = _c.sessionId, updatedUserId = _c.userId;
38
+ eventBuffer = getEventBuffer({
39
+ region: region,
40
+ flushSize: flushSize,
41
+ flushInterval: flushInterval,
42
+ bufferSize: bufferSize,
43
+ credentials: credentials,
44
+ identityId: identityId,
45
+ userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
46
+ });
47
+ if (eventType === MEDIA_AUTO_TRACK_EVENT_TYPE) {
48
+ autoTrackMedia({
49
+ trackingId: trackingId,
50
+ sessionId: updatedSessionId,
51
+ userId: updatedUserId,
52
+ event: {
53
+ eventId: eventId,
54
+ eventType: eventType,
55
+ properties: properties,
56
+ },
57
+ }, eventBuffer);
58
+ }
59
+ else {
60
+ eventBuffer.append({
61
+ trackingId: trackingId,
62
+ sessionId: updatedSessionId,
63
+ userId: updatedUserId,
64
+ event: {
65
+ eventId: eventId,
66
+ eventType: eventType,
67
+ properties: properties,
68
+ },
69
+ timestamp: timestamp,
70
+ });
71
+ }
72
+ if (eventBuffer.length >= bufferSize) {
73
+ eventBuffer.flushAll();
74
+ }
75
+ return [2 /*return*/];
76
+ }
59
77
  });
60
- }
61
- if (eventBuffer.length >= bufferSize) {
62
- eventBuffer.flushAll();
63
- }
78
+ });
64
79
  })
65
80
  .catch(function (e) {
66
81
  logger.warn('Failed to record event.', e);
@@ -1,6 +1,6 @@
1
1
  import { PersonalizeEvent } from './';
2
2
  import { EventBufferConfig } from '../../../utils';
3
- import { Credentials } from '@aws-sdk/types';
3
+ import { AWSCredentials } from '@aws-amplify/core/internals/utils';
4
4
  export type PersonalizeBufferEvent = {
5
5
  trackingId: string;
6
6
  sessionId?: string;
@@ -10,7 +10,7 @@ export type PersonalizeBufferEvent = {
10
10
  };
11
11
  export type PersonalizeBufferConfig = EventBufferConfig & {
12
12
  region: string;
13
- credentials: Credentials;
13
+ credentials: AWSCredentials;
14
14
  identityId?: string;
15
15
  userAgentValue?: string;
16
16
  };
@@ -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";
@@ -1,5 +1,5 @@
1
- export declare const resolveCachedSession: (trackingId: string) => {
1
+ export declare const resolveCachedSession: () => Promise<{
2
2
  sessionId: string;
3
3
  userId: string | undefined;
4
- };
4
+ }>;
5
5
  export declare const updateCachedSession: (newUserId?: string, currentSessionId?: string, currentUserId?: string) => void;
@@ -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
+ import { __awaiter, __generator } from "tslib";
3
4
  import { Cache } from '@aws-amplify/core';
4
- import { isBrowser } from '@aws-amplify/core/internals/utils';
5
- import { v4 as uuid } from 'uuid';
5
+ import { isBrowser, amplifyUuid } from '@aws-amplify/core/internals/utils';
6
6
  var PERSONALIZE_CACHE_USERID = '_awsct_uid';
7
7
  var PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
8
8
  var DEFAULT_CACHE_PREFIX = 'personalize';
@@ -18,18 +18,27 @@ var setCache = function (key, value) {
18
18
  expires: expiredAt.getTime(),
19
19
  });
20
20
  };
21
- export var resolveCachedSession = function (trackingId) {
22
- var sessionId = getCache(PERSONALIZE_CACHE_SESSIONID);
23
- if (!sessionId) {
24
- sessionId = uuid();
25
- setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
26
- }
27
- var userId = getCache(PERSONALIZE_CACHE_USERID);
28
- return {
29
- sessionId: sessionId,
30
- userId: userId,
31
- };
32
- };
21
+ export var resolveCachedSession = function () { return __awaiter(void 0, void 0, void 0, function () {
22
+ var sessionId, userId;
23
+ return __generator(this, function (_a) {
24
+ switch (_a.label) {
25
+ case 0: return [4 /*yield*/, getCache(PERSONALIZE_CACHE_SESSIONID)];
26
+ case 1:
27
+ sessionId = _a.sent();
28
+ if (!sessionId) {
29
+ sessionId = amplifyUuid();
30
+ setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
31
+ }
32
+ return [4 /*yield*/, getCache(PERSONALIZE_CACHE_USERID)];
33
+ case 2:
34
+ userId = _a.sent();
35
+ return [2 /*return*/, {
36
+ sessionId: sessionId,
37
+ userId: userId,
38
+ }];
39
+ }
40
+ });
41
+ }); };
33
42
  export var updateCachedSession = function (newUserId, currentSessionId, currentUserId) {
34
43
  var isNoCachedSession = !currentSessionId;
35
44
  var isSignOutCase = !newUserId && !currentUserId;
@@ -37,7 +46,7 @@ export var updateCachedSession = function (newUserId, currentSessionId, currentU
37
46
  var isRequireNewSession = isNoCachedSession || isSignOutCase || isSwitchUserCase;
38
47
  var isRequireUpdateSession = !!currentSessionId && !currentUserId && !!newUserId;
39
48
  if (isRequireNewSession) {
40
- var newSessionId = uuid();
49
+ var newSessionId = amplifyUuid();
41
50
  setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
42
51
  setCache(PERSONALIZE_CACHE_USERID, newUserId);
43
52
  }
@@ -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
+ };