@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
@@ -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
  }
@@ -10,6 +10,8 @@ var AnalyticsValidationErrorCode;
10
10
  AnalyticsValidationErrorCode["NoCredentials"] = "NoCredentials";
11
11
  AnalyticsValidationErrorCode["NoEventName"] = "NoEventName";
12
12
  AnalyticsValidationErrorCode["NoRegion"] = "NoRegion";
13
+ AnalyticsValidationErrorCode["InvalidTracker"] = "InvalidTracker";
14
+ AnalyticsValidationErrorCode["UnsupportedPlatform"] = "UnsupportedPlatform";
13
15
  AnalyticsValidationErrorCode["NoTrackingId"] = "NoTrackingId";
14
16
  AnalyticsValidationErrorCode["InvalidFlushSize"] = "InvalidFlushSize";
15
17
  })(AnalyticsValidationErrorCode = exports.AnalyticsValidationErrorCode || (exports.AnalyticsValidationErrorCode = {}));
@@ -26,6 +28,12 @@ exports.validationErrorMap = (_a = {},
26
28
  _a[AnalyticsValidationErrorCode.NoRegion] = {
27
29
  message: 'Missing region.',
28
30
  },
31
+ _a[AnalyticsValidationErrorCode.InvalidTracker] = {
32
+ message: 'Invalid tracker type specified.',
33
+ },
34
+ _a[AnalyticsValidationErrorCode.UnsupportedPlatform] = {
35
+ message: 'Only session tracking is supported on React Native.',
36
+ },
29
37
  _a[AnalyticsValidationErrorCode.InvalidFlushSize] = {
30
38
  message: 'Invalid FlushSize, it should be smaller than BufferSize',
31
39
  },
package/lib/index.d.ts CHANGED
@@ -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/index.js CHANGED
@@ -2,10 +2,11 @@
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.AnalyticsError = exports.disable = exports.enable = exports.flushEvents = exports.identifyUser = exports.record = void 0;
5
+ exports.AnalyticsError = exports.disable = exports.enable = exports.flushEvents = exports.configureAutoTrack = exports.identifyUser = exports.record = void 0;
6
6
  var pinpoint_1 = require("./providers/pinpoint");
7
7
  Object.defineProperty(exports, "record", { enumerable: true, get: function () { return pinpoint_1.record; } });
8
8
  Object.defineProperty(exports, "identifyUser", { enumerable: true, get: function () { return pinpoint_1.identifyUser; } });
9
+ Object.defineProperty(exports, "configureAutoTrack", { enumerable: true, get: function () { return pinpoint_1.configureAutoTrack; } });
9
10
  Object.defineProperty(exports, "flushEvents", { enumerable: true, get: function () { return pinpoint_1.flushEvents; } });
10
11
  var apis_1 = require("./apis");
11
12
  Object.defineProperty(exports, "enable", { enumerable: true, get: function () { return apis_1.enable; } });
@@ -7,7 +7,8 @@ var resolveConfig_1 = require("../utils/resolveConfig");
7
7
  var utils_1 = require("../../../utils");
8
8
  var getEventBuffer_1 = require("../utils/getEventBuffer");
9
9
  var utils_2 = require("@aws-amplify/core/internals/utils");
10
- var logger = new utils_2.ConsoleLogger('Kinesis');
10
+ var core_1 = require("@aws-amplify/core");
11
+ var logger = new core_1.ConsoleLogger('Kinesis');
11
12
  /**
12
13
  * Flushes all buffered Kinesis events to the service.
13
14
  *
@@ -8,7 +8,8 @@ var resolveConfig_1 = require("../utils/resolveConfig");
8
8
  var utils_1 = require("../../../utils");
9
9
  var util_utf8_1 = require("@smithy/util-utf8");
10
10
  var utils_2 = require("@aws-amplify/core/internals/utils");
11
- var logger = new utils_2.ConsoleLogger('Kinesis');
11
+ var core_1 = require("@aws-amplify/core");
12
+ var logger = new core_1.ConsoleLogger('Kinesis');
12
13
  var record = function (_a) {
13
14
  var streamName = _a.streamName, partitionKey = _a.partitionKey, data = _a.data;
14
15
  if (!(0, utils_1.isAnalyticsEnabled)()) {
@@ -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;
@@ -6,7 +6,8 @@ exports.flushEvents = void 0;
6
6
  var utils_1 = require("../utils");
7
7
  var utils_2 = require("../../../utils");
8
8
  var utils_3 = require("@aws-amplify/core/internals/utils");
9
- var logger = new utils_3.ConsoleLogger('KinesisFirehose');
9
+ var core_1 = require("@aws-amplify/core");
10
+ var logger = new core_1.ConsoleLogger('KinesisFirehose');
10
11
  /**
11
12
  * Flushes all buffered Kinesis events to the service.
12
13
  *
@@ -7,7 +7,8 @@ var utils_1 = require("../utils");
7
7
  var utils_2 = require("../../../utils");
8
8
  var util_utf8_1 = require("@smithy/util-utf8");
9
9
  var utils_3 = require("@aws-amplify/core/internals/utils");
10
- var logger = new utils_3.ConsoleLogger('KinesisFirehose');
10
+ var core_1 = require("@aws-amplify/core");
11
+ var logger = new core_1.ConsoleLogger('KinesisFirehose');
11
12
  var record = function (_a) {
12
13
  var streamName = _a.streamName, data = _a.data;
13
14
  if (!(0, utils_2.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;
@@ -6,7 +6,8 @@ exports.flushEvents = void 0;
6
6
  var utils_1 = require("../utils");
7
7
  var utils_2 = require("../../../utils");
8
8
  var utils_3 = require("@aws-amplify/core/internals/utils");
9
- var logger = new utils_3.ConsoleLogger('Personalize');
9
+ var core_1 = require("@aws-amplify/core");
10
+ var logger = new core_1.ConsoleLogger('Personalize');
10
11
  /**
11
12
  * Flushes all buffered Personalize events to the service.
12
13
  *
@@ -3,11 +3,13 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.record = void 0;
6
+ var tslib_1 = require("tslib");
6
7
  var utils_1 = require("../utils");
7
8
  var utils_2 = require("../../../utils");
8
9
  var utils_3 = require("@aws-amplify/core/internals/utils");
10
+ var core_1 = require("@aws-amplify/core");
9
11
  var constants_1 = require("../utils/constants");
10
- var logger = new utils_3.ConsoleLogger('Personalize');
12
+ var logger = new core_1.ConsoleLogger('Personalize');
11
13
  var record = function (_a) {
12
14
  var userId = _a.userId, eventId = _a.eventId, eventType = _a.eventType, properties = _a.properties;
13
15
  if (!(0, utils_2.isAnalyticsEnabled)()) {
@@ -18,52 +20,65 @@ var record = function (_a) {
18
20
  (0, utils_2.resolveCredentials)()
19
21
  .then(function (_a) {
20
22
  var credentials = _a.credentials, identityId = _a.identityId;
21
- var timestamp = Date.now();
22
- var _b = (0, utils_1.resolveCachedSession)(trackingId), cachedSessionId = _b.sessionId, cachedUserId = _b.userId;
23
- if (eventType === constants_1.IDENTIFY_EVENT_TYPE) {
24
- (0, utils_1.updateCachedSession)(typeof properties.userId === 'string' ? properties.userId : '', cachedSessionId, cachedUserId);
25
- }
26
- else if (!!userId) {
27
- (0, utils_1.updateCachedSession)(userId, cachedSessionId, cachedUserId);
28
- }
29
- var _c = (0, utils_1.resolveCachedSession)(trackingId), updatedSessionId = _c.sessionId, updatedUserId = _c.userId;
30
- var eventBuffer = (0, utils_1.getEventBuffer)({
31
- region: region,
32
- flushSize: flushSize,
33
- flushInterval: flushInterval,
34
- bufferSize: bufferSize,
35
- credentials: credentials,
36
- identityId: identityId,
37
- userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_3.AnalyticsAction.Record),
38
- });
39
- if (eventType === constants_1.MEDIA_AUTO_TRACK_EVENT_TYPE) {
40
- (0, utils_1.autoTrackMedia)({
41
- trackingId: trackingId,
42
- sessionId: updatedSessionId,
43
- userId: updatedUserId,
44
- event: {
45
- eventId: eventId,
46
- eventType: eventType,
47
- properties: properties,
48
- },
49
- }, eventBuffer);
50
- }
51
- else {
52
- eventBuffer.append({
53
- trackingId: trackingId,
54
- sessionId: updatedSessionId,
55
- userId: updatedUserId,
56
- event: {
57
- eventId: eventId,
58
- eventType: eventType,
59
- properties: properties,
60
- },
61
- timestamp: timestamp,
23
+ return tslib_1.__awaiter(void 0, void 0, void 0, function () {
24
+ var timestamp, _b, cachedSessionId, cachedUserId, _c, updatedSessionId, updatedUserId, eventBuffer;
25
+ return tslib_1.__generator(this, function (_d) {
26
+ switch (_d.label) {
27
+ case 0:
28
+ timestamp = Date.now();
29
+ return [4 /*yield*/, (0, utils_1.resolveCachedSession)()];
30
+ case 1:
31
+ _b = _d.sent(), cachedSessionId = _b.sessionId, cachedUserId = _b.userId;
32
+ if (eventType === constants_1.IDENTIFY_EVENT_TYPE) {
33
+ (0, utils_1.updateCachedSession)(typeof properties.userId === 'string' ? properties.userId : '', cachedSessionId, cachedUserId);
34
+ }
35
+ else if (!!userId) {
36
+ (0, utils_1.updateCachedSession)(userId, cachedSessionId, cachedUserId);
37
+ }
38
+ return [4 /*yield*/, (0, utils_1.resolveCachedSession)()];
39
+ case 2:
40
+ _c = _d.sent(), updatedSessionId = _c.sessionId, updatedUserId = _c.userId;
41
+ eventBuffer = (0, utils_1.getEventBuffer)({
42
+ region: region,
43
+ flushSize: flushSize,
44
+ flushInterval: flushInterval,
45
+ bufferSize: bufferSize,
46
+ credentials: credentials,
47
+ identityId: identityId,
48
+ userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_3.AnalyticsAction.Record),
49
+ });
50
+ if (eventType === constants_1.MEDIA_AUTO_TRACK_EVENT_TYPE) {
51
+ (0, utils_1.autoTrackMedia)({
52
+ trackingId: trackingId,
53
+ sessionId: updatedSessionId,
54
+ userId: updatedUserId,
55
+ event: {
56
+ eventId: eventId,
57
+ eventType: eventType,
58
+ properties: properties,
59
+ },
60
+ }, eventBuffer);
61
+ }
62
+ else {
63
+ eventBuffer.append({
64
+ trackingId: trackingId,
65
+ sessionId: updatedSessionId,
66
+ userId: updatedUserId,
67
+ event: {
68
+ eventId: eventId,
69
+ eventType: eventType,
70
+ properties: properties,
71
+ },
72
+ timestamp: timestamp,
73
+ });
74
+ }
75
+ if (eventBuffer.length >= bufferSize) {
76
+ eventBuffer.flushAll();
77
+ }
78
+ return [2 /*return*/];
79
+ }
62
80
  });
63
- }
64
- if (eventBuffer.length >= bufferSize) {
65
- eventBuffer.flushAll();
66
- }
81
+ });
67
82
  })
68
83
  .catch(function (e) {
69
84
  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
  };
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.autoTrackMedia = void 0;
6
6
  var tslib_1 = require("tslib");
7
7
  var utils_1 = require("@aws-amplify/core/internals/utils");
8
+ var core_1 = require("@aws-amplify/core");
8
9
  var HTML5_MEDIA_EVENT;
9
10
  (function (HTML5_MEDIA_EVENT) {
10
11
  HTML5_MEDIA_EVENT["PLAY"] = "play";
@@ -24,7 +25,7 @@ var EVENT_TYPE;
24
25
  EVENT_TYPE["PAUSE"] = "Pause";
25
26
  EVENT_TYPE["TIME_WATCHED"] = "TimeWatched";
26
27
  })(EVENT_TYPE || (EVENT_TYPE = {}));
27
- var logger = new utils_1.ConsoleLogger('MediaAutoTrack');
28
+ var logger = new core_1.ConsoleLogger('MediaAutoTrack');
28
29
  var startIframeAutoTracking = function (element, recordEvent) {
29
30
  var isPlaying = false;
30
31
  var player;
@@ -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;
@@ -3,9 +3,9 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.updateCachedSession = exports.resolveCachedSession = void 0;
6
+ var tslib_1 = require("tslib");
6
7
  var core_1 = require("@aws-amplify/core");
7
8
  var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var uuid_1 = require("uuid");
9
9
  var PERSONALIZE_CACHE_USERID = '_awsct_uid';
10
10
  var PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
11
11
  var DEFAULT_CACHE_PREFIX = 'personalize';
@@ -21,18 +21,27 @@ var setCache = function (key, value) {
21
21
  expires: expiredAt.getTime(),
22
22
  });
23
23
  };
24
- var resolveCachedSession = function (trackingId) {
25
- var sessionId = getCache(PERSONALIZE_CACHE_SESSIONID);
26
- if (!sessionId) {
27
- sessionId = (0, uuid_1.v4)();
28
- setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
29
- }
30
- var userId = getCache(PERSONALIZE_CACHE_USERID);
31
- return {
32
- sessionId: sessionId,
33
- userId: userId,
34
- };
35
- };
24
+ var resolveCachedSession = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
25
+ var sessionId, userId;
26
+ return tslib_1.__generator(this, function (_a) {
27
+ switch (_a.label) {
28
+ case 0: return [4 /*yield*/, getCache(PERSONALIZE_CACHE_SESSIONID)];
29
+ case 1:
30
+ sessionId = _a.sent();
31
+ if (!sessionId) {
32
+ sessionId = (0, utils_1.amplifyUuid)();
33
+ setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
34
+ }
35
+ return [4 /*yield*/, getCache(PERSONALIZE_CACHE_USERID)];
36
+ case 2:
37
+ userId = _a.sent();
38
+ return [2 /*return*/, {
39
+ sessionId: sessionId,
40
+ userId: userId,
41
+ }];
42
+ }
43
+ });
44
+ }); };
36
45
  exports.resolveCachedSession = resolveCachedSession;
37
46
  var updateCachedSession = function (newUserId, currentSessionId, currentUserId) {
38
47
  var isNoCachedSession = !currentSessionId;
@@ -41,7 +50,7 @@ var updateCachedSession = function (newUserId, currentSessionId, currentUserId)
41
50
  var isRequireNewSession = isNoCachedSession || isSignOutCase || isSwitchUserCase;
42
51
  var isRequireUpdateSession = !!currentSessionId && !currentUserId && !!newUserId;
43
52
  if (isRequireNewSession) {
44
- var newSessionId = (0, uuid_1.v4)();
53
+ var newSessionId = (0, utils_1.amplifyUuid)();
45
54
  setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
46
55
  setCache(PERSONALIZE_CACHE_USERID, newUserId);
47
56
  }
@@ -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,35 @@
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.configureAutoTrack = void 0;
6
+ var utils_1 = require("../../../utils");
7
+ var record_1 = require("./record");
8
+ // Configured Tracker instances for Pinpoint
9
+ var configuredTrackers = {};
10
+ // Callback that will emit an appropriate event to Pinpoint when required by the Tracker
11
+ var emitTrackingEvent = function (eventName, attributes) {
12
+ (0, record_1.record)({
13
+ name: eventName,
14
+ attributes: attributes,
15
+ });
16
+ };
17
+ /**
18
+ * Configures automatic event tracking for Pinpoint. This API will automatically transmit an analytic event when
19
+ * configured events are detected within your application. This can include: DOM element events (via the `event`
20
+ * tracker), session events (via the `session` tracker), and page view events (via the `pageView` tracker).
21
+ *
22
+ * @remark Only session tracking is currently supported on React Native.
23
+ *
24
+ * @param {ConfigureAutoTrackInput} params The input object to configure auto track behavior.
25
+ *
26
+ * @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
27
+ * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
28
+ * configuration is incorrect.
29
+ */
30
+ var configureAutoTrack = function (input) {
31
+ (0, utils_1.validateTrackerConfiguration)(input);
32
+ // Initialize or update this provider's trackers
33
+ (0, utils_1.updateProviderTrackers)(input, emitTrackingEvent, configuredTrackers);
34
+ };
35
+ exports.configureAutoTrack = configureAutoTrack;
@@ -6,8 +6,9 @@ exports.flushEvents = void 0;
6
6
  var utils_1 = require("../utils");
7
7
  var pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
8
8
  var utils_2 = require("@aws-amplify/core/internals/utils");
9
+ var core_1 = require("@aws-amplify/core");
9
10
  var utils_3 = require("../../../utils");
10
- var logger = new utils_2.ConsoleLogger('Analytics');
11
+ var logger = new core_1.ConsoleLogger('Analytics');
11
12
  /**
12
13
  * Flushes all buffered Pinpoint events to the service.
13
14
  *
@@ -57,14 +57,13 @@ var identifyUser = function (_a) {
57
57
  var userId = _a.userId, userProfile = _a.userProfile, options = _a.options;
58
58
  return tslib_1.__awaiter(void 0, void 0, void 0, function () {
59
59
  var _b, credentials, identityId, _c, appId, region, userAttributes;
60
- var _d;
61
- return tslib_1.__generator(this, function (_e) {
62
- switch (_e.label) {
60
+ return tslib_1.__generator(this, function (_d) {
61
+ switch (_d.label) {
63
62
  case 0: return [4 /*yield*/, (0, utils_3.resolveCredentials)()];
64
63
  case 1:
65
- _b = _e.sent(), credentials = _b.credentials, identityId = _b.identityId;
64
+ _b = _d.sent(), credentials = _b.credentials, identityId = _b.identityId;
66
65
  _c = (0, utils_3.resolveConfig)(), appId = _c.appId, region = _c.region;
67
- userAttributes = ((_d = options === null || options === void 0 ? void 0 : options.serviceOptions) !== null && _d !== void 0 ? _d : {}).userAttributes;
66
+ userAttributes = (options !== null && options !== void 0 ? options : {}).userAttributes;
68
67
  (0, pinpoint_1.updateEndpoint)({
69
68
  appId: appId,
70
69
  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,10 +2,12 @@
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.flushEvents = exports.identifyUser = exports.record = void 0;
5
+ exports.flushEvents = exports.configureAutoTrack = exports.identifyUser = exports.record = void 0;
6
6
  var record_1 = require("./record");
7
7
  Object.defineProperty(exports, "record", { enumerable: true, get: function () { return record_1.record; } });
8
8
  var identifyUser_1 = require("./identifyUser");
9
9
  Object.defineProperty(exports, "identifyUser", { enumerable: true, get: function () { return identifyUser_1.identifyUser; } });
10
+ var configureAutoTrack_1 = require("./configureAutoTrack");
11
+ Object.defineProperty(exports, "configureAutoTrack", { enumerable: true, get: function () { return configureAutoTrack_1.configureAutoTrack; } });
10
12
  var flushEvents_1 = require("./flushEvents");
11
13
  Object.defineProperty(exports, "flushEvents", { enumerable: true, get: function () { return flushEvents_1.flushEvents; } });
@@ -9,7 +9,7 @@ var pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
9
9
  var errors_1 = require("../../../errors");
10
10
  var utils_2 = require("../../../utils");
11
11
  var utils_3 = require("../utils");
12
- var logger = new utils_1.ConsoleLogger('Analytics');
12
+ var logger = new core_1.ConsoleLogger('Analytics');
13
13
  /**
14
14
  * Records an Analytic event to Pinpoint. Events will be buffered and periodically sent to Pinpoint.
15
15
  *
@@ -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';
@@ -2,8 +2,9 @@
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.flushEvents = exports.identifyUser = exports.record = void 0;
5
+ exports.configureAutoTrack = exports.flushEvents = exports.identifyUser = exports.record = void 0;
6
6
  var apis_1 = require("./apis");
7
7
  Object.defineProperty(exports, "record", { enumerable: true, get: function () { return apis_1.record; } });
8
8
  Object.defineProperty(exports, "identifyUser", { enumerable: true, get: function () { return apis_1.identifyUser; } });
9
9
  Object.defineProperty(exports, "flushEvents", { enumerable: true, get: function () { return apis_1.flushEvents; } });
10
+ Object.defineProperty(exports, "configureAutoTrack", { enumerable: true, get: function () { return apis_1.configureAutoTrack; } });
@@ -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';
@@ -2,6 +2,3 @@
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.UpdateEndpointException = void 0;
6
- var errors_1 = require("./errors");
7
- Object.defineProperty(exports, "UpdateEndpointException", { enumerable: true, get: function () { return errors_1.UpdateEndpointException; } });
@@ -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;
@@ -2,11 +2,6 @@
2
2
  * @internal
3
3
  */
4
4
  export declare const resolveCredentials: () => Promise<{
5
- credentials: {
6
- accessKeyId: string;
7
- secretAccessKey: string;
8
- sessionToken?: string | undefined;
9
- expiration?: Date | undefined;
10
- };
5
+ credentials: import("@aws-amplify/core/lib-esm/libraryUtils").AWSCredentials;
11
6
  identityId: string | undefined;
12
7
  }>;
@@ -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
+ }