@aws-amplify/analytics 7.0.16 → 7.0.17-unstable.0d2aa5d.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 (120) hide show
  1. package/dist/cjs/providers/kinesis/apis/flushEvents.js +8 -6
  2. package/dist/cjs/providers/kinesis/apis/flushEvents.js.map +1 -1
  3. package/dist/cjs/providers/kinesis/apis/record.js +7 -7
  4. package/dist/cjs/providers/kinesis/apis/record.js.map +1 -1
  5. package/dist/cjs/providers/kinesis/utils/getEventBuffer.js +2 -2
  6. package/dist/cjs/providers/kinesis/utils/getEventBuffer.js.map +1 -1
  7. package/dist/cjs/providers/kinesis-firehose/apis/flushEvents.js +10 -8
  8. package/dist/cjs/providers/kinesis-firehose/apis/flushEvents.js.map +1 -1
  9. package/dist/cjs/providers/kinesis-firehose/apis/record.js +8 -8
  10. package/dist/cjs/providers/kinesis-firehose/apis/record.js.map +1 -1
  11. package/dist/cjs/providers/kinesis-firehose/utils/getEventBuffer.js +2 -2
  12. package/dist/cjs/providers/kinesis-firehose/utils/getEventBuffer.js.map +1 -1
  13. package/dist/cjs/providers/personalize/apis/flushEvents.js +10 -8
  14. package/dist/cjs/providers/personalize/apis/flushEvents.js.map +1 -1
  15. package/dist/cjs/providers/personalize/apis/record.js +14 -14
  16. package/dist/cjs/providers/personalize/apis/record.js.map +1 -1
  17. package/dist/cjs/providers/personalize/utils/autoTrackMedia.js +8 -8
  18. package/dist/cjs/providers/personalize/utils/autoTrackMedia.js.map +1 -1
  19. package/dist/cjs/providers/personalize/utils/getEventBuffer.js +2 -2
  20. package/dist/cjs/providers/personalize/utils/getEventBuffer.js.map +1 -1
  21. package/dist/cjs/providers/pinpoint/apis/flushEvents.js +20 -16
  22. package/dist/cjs/providers/pinpoint/apis/flushEvents.js.map +1 -1
  23. package/dist/cjs/providers/pinpoint/apis/identifyUser.js +1 -1
  24. package/dist/cjs/providers/pinpoint/apis/identifyUser.js.map +1 -1
  25. package/dist/cjs/trackers/PageViewTracker.js +2 -4
  26. package/dist/cjs/trackers/PageViewTracker.js.map +1 -1
  27. package/dist/cjs/utils/resolveCredentials.js +1 -1
  28. package/dist/cjs/utils/resolveCredentials.js.map +1 -1
  29. package/dist/esm/apis/disable.mjs +1 -1
  30. package/dist/esm/apis/enable.mjs +1 -1
  31. package/dist/esm/providers/kinesis/apis/flushEvents.mjs +5 -3
  32. package/dist/esm/providers/kinesis/apis/flushEvents.mjs.map +1 -1
  33. package/dist/esm/providers/kinesis/apis/record.mjs +3 -3
  34. package/dist/esm/providers/kinesis/apis/record.mjs.map +1 -1
  35. package/dist/esm/providers/kinesis/types/inputs.d.ts +2 -2
  36. package/dist/esm/providers/kinesis/utils/getEventBuffer.mjs +3 -3
  37. package/dist/esm/providers/kinesis/utils/getEventBuffer.mjs.map +1 -1
  38. package/dist/esm/providers/kinesis-firehose/apis/flushEvents.mjs +5 -3
  39. package/dist/esm/providers/kinesis-firehose/apis/flushEvents.mjs.map +1 -1
  40. package/dist/esm/providers/kinesis-firehose/apis/record.mjs +3 -3
  41. package/dist/esm/providers/kinesis-firehose/apis/record.mjs.map +1 -1
  42. package/dist/esm/providers/kinesis-firehose/types/buffer.d.ts +1 -1
  43. package/dist/esm/providers/kinesis-firehose/types/inputs.d.ts +2 -2
  44. package/dist/esm/providers/kinesis-firehose/utils/getEventBuffer.mjs +3 -3
  45. package/dist/esm/providers/kinesis-firehose/utils/getEventBuffer.mjs.map +1 -1
  46. package/dist/esm/providers/personalize/apis/flushEvents.mjs +5 -3
  47. package/dist/esm/providers/personalize/apis/flushEvents.mjs.map +1 -1
  48. package/dist/esm/providers/personalize/apis/record.mjs +3 -3
  49. package/dist/esm/providers/personalize/apis/record.mjs.map +1 -1
  50. package/dist/esm/providers/personalize/types/buffer.d.ts +4 -4
  51. package/dist/esm/providers/personalize/types/inputs.d.ts +2 -2
  52. package/dist/esm/providers/personalize/utils/autoTrackMedia.d.ts +2 -2
  53. package/dist/esm/providers/personalize/utils/autoTrackMedia.mjs +8 -8
  54. package/dist/esm/providers/personalize/utils/autoTrackMedia.mjs.map +1 -1
  55. package/dist/esm/providers/personalize/utils/cachedSession.mjs.map +1 -1
  56. package/dist/esm/providers/personalize/utils/getEventBuffer.mjs +3 -3
  57. package/dist/esm/providers/personalize/utils/getEventBuffer.mjs.map +1 -1
  58. package/dist/esm/providers/pinpoint/apis/configureAutoTrack.mjs +1 -1
  59. package/dist/esm/providers/pinpoint/apis/flushEvents.mjs +18 -14
  60. package/dist/esm/providers/pinpoint/apis/flushEvents.mjs.map +1 -1
  61. package/dist/esm/providers/pinpoint/apis/identifyUser.d.ts +1 -1
  62. package/dist/esm/providers/pinpoint/apis/identifyUser.mjs +2 -2
  63. package/dist/esm/providers/pinpoint/apis/identifyUser.mjs.map +1 -1
  64. package/dist/esm/providers/pinpoint/apis/record.mjs.map +1 -1
  65. package/dist/esm/providers/pinpoint/types/inputs.d.ts +1 -1
  66. package/dist/esm/trackers/PageViewTracker.mjs +2 -4
  67. package/dist/esm/trackers/PageViewTracker.mjs.map +1 -1
  68. package/dist/esm/trackers/SessionTracker.mjs.map +1 -1
  69. package/dist/esm/trackers/SessionTracker.native.mjs.map +1 -1
  70. package/dist/esm/types/inputs.d.ts +3 -3
  71. package/dist/esm/types/kinesis.d.ts +2 -2
  72. package/dist/esm/types/trackers.d.ts +7 -7
  73. package/dist/esm/utils/eventBuffer/types.d.ts +3 -5
  74. package/dist/esm/utils/resolveCredentials.mjs +1 -1
  75. package/dist/esm/utils/resolveCredentials.mjs.map +1 -1
  76. package/dist/esm/utils/userAgent.mjs.map +1 -1
  77. package/package.json +110 -110
  78. package/src/errors/assertValidationError.ts +1 -1
  79. package/src/providers/kinesis/apis/flushEvents.ts +7 -4
  80. package/src/providers/kinesis/apis/record.ts +6 -3
  81. package/src/providers/kinesis/types/buffer.ts +1 -0
  82. package/src/providers/kinesis/types/inputs.ts +2 -2
  83. package/src/providers/kinesis/utils/getEventBuffer.ts +22 -21
  84. package/src/providers/kinesis/utils/resolveConfig.ts +4 -1
  85. package/src/providers/kinesis-firehose/apis/flushEvents.ts +7 -4
  86. package/src/providers/kinesis-firehose/apis/record.ts +6 -3
  87. package/src/providers/kinesis-firehose/types/buffer.ts +2 -1
  88. package/src/providers/kinesis-firehose/types/inputs.ts +2 -2
  89. package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +23 -21
  90. package/src/providers/kinesis-firehose/utils/resolveConfig.ts +4 -1
  91. package/src/providers/personalize/apis/flushEvents.ts +7 -4
  92. package/src/providers/personalize/apis/record.ts +8 -5
  93. package/src/providers/personalize/types/buffer.ts +6 -4
  94. package/src/providers/personalize/types/inputs.ts +2 -2
  95. package/src/providers/personalize/utils/autoTrackMedia.ts +34 -26
  96. package/src/providers/personalize/utils/cachedSession.ts +5 -5
  97. package/src/providers/personalize/utils/getEventBuffer.ts +24 -20
  98. package/src/providers/personalize/utils/resolveConfig.ts +4 -2
  99. package/src/providers/pinpoint/apis/configureAutoTrack.ts +5 -2
  100. package/src/providers/pinpoint/apis/flushEvents.ts +8 -5
  101. package/src/providers/pinpoint/apis/identifyUser.ts +3 -2
  102. package/src/providers/pinpoint/apis/record.ts +4 -2
  103. package/src/providers/pinpoint/types/inputs.ts +3 -1
  104. package/src/providers/pinpoint/utils/resolveConfig.ts +1 -0
  105. package/src/providers/pinpoint/utils/resolveCredentials.ts +3 -1
  106. package/src/trackers/EventTracker.ts +7 -6
  107. package/src/trackers/PageViewTracker.ts +8 -13
  108. package/src/trackers/SessionTracker.native.ts +6 -5
  109. package/src/trackers/SessionTracker.ts +6 -5
  110. package/src/types/inputs.ts +6 -5
  111. package/src/types/kinesis.ts +2 -2
  112. package/src/types/trackers.ts +8 -8
  113. package/src/utils/eventBuffer/EventBuffer.ts +3 -2
  114. package/src/utils/eventBuffer/types.ts +3 -5
  115. package/src/utils/groupBy.ts +3 -2
  116. package/src/utils/resolveCredentials.ts +4 -2
  117. package/src/utils/trackerConfigHelpers.native.ts +2 -2
  118. package/src/utils/trackerConfigHelpers.ts +2 -2
  119. package/src/utils/trackerHelpers.ts +1 -2
  120. package/src/utils/userAgent.ts +1 -1
@@ -1,19 +1,16 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import {
5
- AWSCredentials,
6
- haveCredentialsChanged
4
+ import {
5
+ AWSCredentials,
6
+ haveCredentialsChanged,
7
7
  } from '@aws-amplify/core/internals/utils';
8
8
  import {
9
9
  PersonalizeEventsClient,
10
10
  PutEventsCommand,
11
11
  } from '@aws-sdk/client-personalize-events';
12
- import {
13
- EventBuffer,
14
- groupBy,
15
- IAnalyticsClient
16
- } from '../../../utils';
12
+
13
+ import { EventBuffer, IAnalyticsClient, groupBy } from '../../../utils';
17
14
  import { PersonalizeBufferConfig, PersonalizeBufferEvent } from '../types';
18
15
 
19
16
  /**
@@ -25,15 +22,17 @@ import { PersonalizeBufferConfig, PersonalizeBufferEvent } from '../types';
25
22
  * When a new session is initiated, the previous ones should be released.
26
23
  * */
27
24
  const eventBufferMap: Record<string, EventBuffer<PersonalizeBufferEvent>> = {};
28
- const cachedClients: Record<string, [PersonalizeEventsClient, AWSCredentials]> = {};
25
+ const cachedClients: Record<string, [PersonalizeEventsClient, AWSCredentials]> =
26
+ {};
29
27
 
30
28
  const DELIMITER = '#';
31
29
 
32
30
  const createPutEventsCommand = (
33
31
  ids: string,
34
- events: PersonalizeBufferEvent[]
32
+ events: PersonalizeBufferEvent[],
35
33
  ): PutEventsCommand => {
36
34
  const [trackingId, sessionId, userId] = ids.split(DELIMITER);
35
+
37
36
  return new PutEventsCommand({
38
37
  trackingId,
39
38
  sessionId,
@@ -49,7 +48,7 @@ const createPutEventsCommand = (
49
48
 
50
49
  const submitEvents = async (
51
50
  events: PersonalizeBufferEvent[],
52
- client: PersonalizeEventsClient
51
+ client: PersonalizeEventsClient,
53
52
  ): Promise<PersonalizeBufferEvent[]> => {
54
53
  const groupedByIds = Object.entries(
55
54
  groupBy(
@@ -57,15 +56,16 @@ const submitEvents = async (
57
56
  [event.trackingId, event.sessionId, event.userId]
58
57
  .filter(id => !!id)
59
58
  .join(DELIMITER),
60
- events
61
- )
59
+ events,
60
+ ),
62
61
  );
63
62
 
64
63
  const requests = groupedByIds
65
- .map(([ids, events]) => createPutEventsCommand(ids, events))
64
+ .map(([ids, groupedEvents]) => createPutEventsCommand(ids, groupedEvents))
66
65
  .map(command => client.send(command));
67
66
 
68
67
  await Promise.allSettled(requests);
68
+
69
69
  return Promise.resolve([]);
70
70
  };
71
71
 
@@ -79,12 +79,16 @@ export const getEventBuffer = ({
79
79
  userAgentValue,
80
80
  }: PersonalizeBufferConfig): EventBuffer<PersonalizeBufferEvent> => {
81
81
  const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
82
- const [ cachedClient, cachedCredentials ] = cachedClients[sessionIdentityKey] ?? [];
82
+ const [cachedClient, cachedCredentials] =
83
+ cachedClients[sessionIdentityKey] ?? [];
83
84
  let credentialsHaveChanged = false;
84
85
 
85
86
  // Check if credentials have changed for the cached client
86
87
  if (cachedClient) {
87
- credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
88
+ credentialsHaveChanged = haveCredentialsChanged(
89
+ cachedCredentials,
90
+ credentials,
91
+ );
88
92
  }
89
93
 
90
94
  if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
@@ -96,11 +100,11 @@ export const getEventBuffer = ({
96
100
  credentials,
97
101
  customUserAgent: userAgentValue,
98
102
  }),
99
- credentials
103
+ credentials,
100
104
  ];
101
105
  }
102
106
 
103
- const [ personalizeClient ] = cachedClients[sessionIdentityKey];
107
+ const [personalizeClient] = cachedClients[sessionIdentityKey];
104
108
 
105
109
  return events => submitEvents(events, personalizeClient);
106
110
  };
@@ -112,11 +116,11 @@ export const getEventBuffer = ({
112
116
  flushSize,
113
117
  flushInterval,
114
118
  },
115
- getClient
119
+ getClient,
116
120
  );
117
121
 
118
122
  const releaseSessionKeys = Object.keys(eventBufferMap).filter(
119
- key => key !== sessionIdentityKey
123
+ key => key !== sessionIdentityKey,
120
124
  );
121
125
  for (const releaseSessionKey of releaseSessionKeys) {
122
126
  eventBufferMap[releaseSessionKey].flushAll().finally(() => {
@@ -2,10 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { Amplify } from '@aws-amplify/core';
5
+
5
6
  import {
6
7
  AnalyticsValidationErrorCode,
7
8
  assertValidationError,
8
9
  } from '../../../errors';
10
+
9
11
  import {
10
12
  DEFAULT_PERSONALIZE_CONFIG,
11
13
  PERSONALIZE_FLUSH_SIZE_MAX,
@@ -26,12 +28,12 @@ export const resolveConfig = () => {
26
28
  assertValidationError(!!region, AnalyticsValidationErrorCode.NoRegion);
27
29
  assertValidationError(
28
30
  !!trackingId,
29
- AnalyticsValidationErrorCode.NoTrackingId
31
+ AnalyticsValidationErrorCode.NoTrackingId,
30
32
  );
31
33
  assertValidationError(
32
34
  flushSize <= PERSONALIZE_FLUSH_SIZE_MAX,
33
35
  AnalyticsValidationErrorCode.InvalidFlushSize,
34
- `FlushSize for Personalize should be less or equal than ${PERSONALIZE_FLUSH_SIZE_MAX}`
36
+ `FlushSize for Personalize should be less or equal than ${PERSONALIZE_FLUSH_SIZE_MAX}`,
35
37
  );
36
38
 
37
39
  return {
@@ -1,17 +1,20 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { UpdateEndpointException } from '@aws-amplify/core/internals/providers/pinpoint';
5
+
4
6
  import { AnalyticsValidationErrorCode } from '../../../errors';
5
7
  import {
6
- TrackerType,
7
8
  TrackerAttributes,
8
9
  TrackerInterface,
10
+ TrackerType,
9
11
  } from '../../../types/trackers';
10
12
  import {
11
13
  updateProviderTrackers,
12
14
  validateTrackerConfiguration,
13
15
  } from '../../../utils';
14
16
  import { ConfigureAutoTrackInput } from '../types';
17
+
15
18
  import { record } from './record';
16
19
 
17
20
  // Configured Tracker instances for Pinpoint
@@ -20,7 +23,7 @@ const configuredTrackers: Partial<Record<TrackerType, TrackerInterface>> = {};
20
23
  // Callback that will emit an appropriate event to Pinpoint when required by the Tracker
21
24
  const emitTrackingEvent = (
22
25
  eventName: string,
23
- attributes: TrackerAttributes
26
+ attributes: TrackerAttributes,
24
27
  ) => {
25
28
  record({
26
29
  name: eventName,
@@ -1,10 +1,11 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { resolveConfig, resolveCredentials } from '../utils';
5
4
  import { flushEvents as flushEventsCore } from '@aws-amplify/core/internals/providers/pinpoint';
6
5
  import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
7
6
  import { ConsoleLogger } from '@aws-amplify/core';
7
+
8
+ import { resolveConfig, resolveCredentials } from '../utils';
8
9
  import { getAnalyticsUserAgentString } from '../../../utils';
9
10
 
10
11
  const logger = new ConsoleLogger('Analytics');
@@ -20,7 +21,7 @@ export const flushEvents = () => {
20
21
  const { appId, region, bufferSize, flushSize, flushInterval, resendLimit } =
21
22
  resolveConfig();
22
23
  resolveCredentials()
23
- .then(({ credentials, identityId }) =>
24
+ .then(({ credentials, identityId }) => {
24
25
  flushEventsCore({
25
26
  appId,
26
27
  region,
@@ -31,7 +32,9 @@ export const flushEvents = () => {
31
32
  flushInterval,
32
33
  resendLimit,
33
34
  userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
34
- })
35
- )
36
- .catch(e => logger.warn('Failed to flush events', e));
35
+ });
36
+ })
37
+ .catch(e => {
38
+ logger.warn('Failed to flush events', e);
39
+ });
37
40
  };
@@ -3,9 +3,10 @@
3
3
 
4
4
  import { AnalyticsAction } from '@aws-amplify/core/internals/utils';
5
5
  import {
6
- updateEndpoint,
7
6
  UpdateEndpointException,
7
+ updateEndpoint,
8
8
  } from '@aws-amplify/core/internals/providers/pinpoint';
9
+
9
10
  import { AnalyticsValidationErrorCode } from '../../../errors';
10
11
  import { getAnalyticsUserAgentString } from '../../../utils';
11
12
  import { IdentifyUserInput } from '../types';
@@ -16,7 +17,7 @@ import { resolveConfig, resolveCredentials } from '../utils';
16
17
  * profile and activities or actions in your application. Activity can be tracked across devices & platforms by using
17
18
  * the same `userId`.
18
19
  *
19
- * @param {IdentifyUserParameters} params The input object used to construct requests sent to Pinpoint's UpdateEndpoint
20
+ * @param {IdentifyUserInput} params The input object used to construct requests sent to Pinpoint's UpdateEndpoint
20
21
  * API.
21
22
  *
22
23
  * @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
@@ -1,12 +1,13 @@
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, ConsoleLogger } from '@aws-amplify/core';
4
+ import { ConsoleLogger, Hub } from '@aws-amplify/core';
5
5
  import {
6
6
  AMPLIFY_SYMBOL,
7
7
  AnalyticsAction,
8
8
  } from '@aws-amplify/core/internals/utils';
9
9
  import { record as recordCore } from '@aws-amplify/core/internals/providers/pinpoint';
10
+
10
11
  import {
11
12
  AnalyticsValidationErrorCode,
12
13
  assertValidationError,
@@ -54,6 +55,7 @@ export const record = (input: RecordInput): void => {
54
55
 
55
56
  if (!isAnalyticsEnabled()) {
56
57
  logger.debug('Analytics is disabled, event will not be recorded.');
58
+
57
59
  return;
58
60
  }
59
61
 
@@ -65,7 +67,7 @@ export const record = (input: RecordInput): void => {
65
67
  'analytics',
66
68
  { event: 'record', data: input, message: 'Recording Analytics event' },
67
69
  'Analytics',
68
- AMPLIFY_SYMBOL
70
+ AMPLIFY_SYMBOL,
69
71
  );
70
72
  recordCore({
71
73
  appId,
@@ -2,12 +2,14 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';
5
- import { IdentifyUserOptions } from './options';
5
+
6
6
  import {
7
7
  AnalyticsConfigureAutoTrackInput,
8
8
  AnalyticsIdentifyUserInput,
9
9
  } from '../../../types';
10
10
 
11
+ import { IdentifyUserOptions } from './options';
12
+
11
13
  /**
12
14
  * Input type for Pinpoint record API.
13
15
  */
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { Amplify } from '@aws-amplify/core';
5
+
5
6
  import {
6
7
  AnalyticsValidationErrorCode,
7
8
  assertValidationError,
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { fetchAuthSession } from '@aws-amplify/core';
5
+
5
6
  import {
6
7
  AnalyticsValidationErrorCode,
7
8
  assertValidationError,
@@ -14,7 +15,8 @@ export const resolveCredentials = async () => {
14
15
  const { credentials, identityId } = await fetchAuthSession();
15
16
  assertValidationError(
16
17
  !!credentials,
17
- AnalyticsValidationErrorCode.NoCredentials
18
+ AnalyticsValidationErrorCode.NoCredentials,
18
19
  );
20
+
19
21
  return { credentials, identityId };
20
22
  };
@@ -1,14 +1,15 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { ConsoleLogger } from '@aws-amplify/core';
5
+ import { isBrowser } from '@aws-amplify/core/internals/utils';
6
+
4
7
  import {
5
- EventTrackingOptions,
6
8
  DOMEvent,
9
+ EventTrackingOptions,
7
10
  TrackerEventRecorder,
8
11
  TrackerInterface,
9
12
  } from '../types/trackers';
10
- import { ConsoleLogger } from '@aws-amplify/core';
11
- import { isBrowser } from '@aws-amplify/core/internals/utils';
12
13
 
13
14
  const DEFAULT_EVENTS = ['click'] as DOMEvent[];
14
15
  const DEFAULT_SELECTOR_PREFIX = 'data-amplify-analytics-';
@@ -23,7 +24,7 @@ export class EventTracker implements TrackerInterface {
23
24
 
24
25
  constructor(
25
26
  eventRecorder: TrackerEventRecorder,
26
- options?: EventTrackingOptions
27
+ options?: EventTrackingOptions,
27
28
  ) {
28
29
  this.options = {};
29
30
  this.trackerActive = false;
@@ -35,7 +36,7 @@ export class EventTracker implements TrackerInterface {
35
36
 
36
37
  public configure(
37
38
  eventRecorder: TrackerEventRecorder,
38
- options?: EventTrackingOptions
39
+ options?: EventTrackingOptions,
39
40
  ) {
40
41
  this.eventRecorder = eventRecorder;
41
42
 
@@ -120,7 +121,7 @@ export class EventTracker implements TrackerInterface {
120
121
  target: `${target.localName} with id ${target.id}`,
121
122
  },
122
123
  this.options.attributes,
123
- elementAttributes
124
+ elementAttributes,
124
125
  );
125
126
 
126
127
  logger.debug('Recording automatically tracked DOM event', {
@@ -1,13 +1,14 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { ConsoleLogger } from '@aws-amplify/core';
5
+ import { isBrowser } from '@aws-amplify/core/internals/utils';
6
+
4
7
  import {
5
8
  PageViewTrackingOptions,
6
9
  TrackerEventRecorder,
7
10
  TrackerInterface,
8
11
  } from '../types/trackers';
9
- import { ConsoleLogger } from '@aws-amplify/core';
10
- import { isBrowser } from '@aws-amplify/core/internals/utils';
11
12
 
12
13
  const logger = new ConsoleLogger('PageViewTracker');
13
14
 
@@ -32,7 +33,7 @@ export class PageViewTracker implements TrackerInterface {
32
33
 
33
34
  constructor(
34
35
  eventRecorder: TrackerEventRecorder,
35
- options?: PageViewTrackingOptions
36
+ options?: PageViewTrackingOptions,
36
37
  ) {
37
38
  this.options = {};
38
39
  this.trackerActive = true;
@@ -45,7 +46,7 @@ export class PageViewTracker implements TrackerInterface {
45
46
 
46
47
  public configure(
47
48
  eventRecorder: TrackerEventRecorder,
48
- options?: PageViewTrackingOptions
49
+ options?: PageViewTrackingOptions,
49
50
  ) {
50
51
  this.eventRecorder = eventRecorder;
51
52
 
@@ -95,20 +96,14 @@ export class PageViewTracker implements TrackerInterface {
95
96
  // Configure proxies on History APIs
96
97
  this.pushStateProxy = Proxy.revocable(window.history.pushState, {
97
98
  apply: (target, thisArg, args) => {
98
- const proxiedResult = target.apply(thisArg, args as any);
99
-
99
+ target.apply(thisArg, args as any);
100
100
  this.handleLocationChange();
101
-
102
- return proxiedResult;
103
101
  },
104
102
  });
105
103
  this.replaceStateProxy = Proxy.revocable(window.history.replaceState, {
106
104
  apply: (target, thisArg, args) => {
107
- const proxiedResult = target.apply(thisArg, args as any);
108
-
105
+ target.apply(thisArg, args as any);
109
106
  this.handleLocationChange();
110
-
111
- return proxiedResult;
112
107
  },
113
108
  });
114
109
 
@@ -139,7 +134,7 @@ export class PageViewTracker implements TrackerInterface {
139
134
  {
140
135
  url: currentUrl,
141
136
  },
142
- this.options.attributes
137
+ this.options.attributes,
143
138
  );
144
139
 
145
140
  logger.debug('Recording automatically tracked page view event', {
@@ -2,12 +2,13 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import {
5
- sessionListener,
6
- SessionState,
7
5
  SESSION_START_EVENT,
8
6
  SESSION_STOP_EVENT,
7
+ SessionState,
8
+ sessionListener,
9
9
  } from '@aws-amplify/core/internals/utils';
10
10
  import { ConsoleLogger } from '@aws-amplify/core';
11
+
11
12
  import {
12
13
  SessionTrackingOptions,
13
14
  TrackerEventRecorder,
@@ -24,7 +25,7 @@ export class SessionTracker implements TrackerInterface {
24
25
 
25
26
  constructor(
26
27
  eventRecorder: TrackerEventRecorder,
27
- options?: SessionTrackingOptions
28
+ options?: SessionTrackingOptions,
28
29
  ) {
29
30
  this.options = {};
30
31
  this.eventRecorder = eventRecorder;
@@ -37,7 +38,7 @@ export class SessionTracker implements TrackerInterface {
37
38
 
38
39
  public configure(
39
40
  eventRecorder: TrackerEventRecorder,
40
- options?: SessionTrackingOptions
41
+ options?: SessionTrackingOptions,
41
42
  ) {
42
43
  this.eventRecorder = eventRecorder;
43
44
 
@@ -53,7 +54,7 @@ export class SessionTracker implements TrackerInterface {
53
54
  if (!this.sessionTrackingActive) {
54
55
  sessionListener.addStateChangeListener(
55
56
  this.handleStateChange,
56
- !this.initialEventSent
57
+ !this.initialEventSent,
57
58
  );
58
59
 
59
60
  this.sessionTrackingActive = true;
@@ -2,12 +2,13 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import {
5
- sessionListener,
6
- SessionState,
7
5
  SESSION_START_EVENT,
8
6
  SESSION_STOP_EVENT,
7
+ SessionState,
8
+ sessionListener,
9
9
  } from '@aws-amplify/core/internals/utils';
10
10
  import { ConsoleLogger } from '@aws-amplify/core';
11
+
11
12
  import {
12
13
  SessionTrackingOptions,
13
14
  TrackerEventRecorder,
@@ -24,7 +25,7 @@ export class SessionTracker implements TrackerInterface {
24
25
 
25
26
  constructor(
26
27
  eventRecorder: TrackerEventRecorder,
27
- options?: SessionTrackingOptions
28
+ options?: SessionTrackingOptions,
28
29
  ) {
29
30
  this.options = {};
30
31
  this.eventRecorder = eventRecorder;
@@ -37,7 +38,7 @@ export class SessionTracker implements TrackerInterface {
37
38
 
38
39
  public configure(
39
40
  eventRecorder: TrackerEventRecorder,
40
- options?: SessionTrackingOptions
41
+ options?: SessionTrackingOptions,
41
42
  ) {
42
43
  this.eventRecorder = eventRecorder;
43
44
 
@@ -53,7 +54,7 @@ export class SessionTracker implements TrackerInterface {
53
54
  if (!this.sessionTrackingActive) {
54
55
  sessionListener.addStateChangeListener(
55
56
  this.handleStateChange,
56
- !this.initialEventSent
57
+ !this.initialEventSent,
57
58
  );
58
59
 
59
60
  this.sessionTrackingActive = true;
@@ -2,19 +2,20 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { UserProfile } from '@aws-amplify/core';
5
+
5
6
  import { AnalyticsServiceOptions } from './options';
6
7
  import {
7
- SessionTrackingOptions,
8
- PageViewTrackingOptions,
9
8
  EventTrackingOptions,
9
+ PageViewTrackingOptions,
10
+ SessionTrackingOptions,
10
11
  } from './trackers';
11
12
 
12
13
  /**
13
14
  * Input type for `identifyUser`.
14
15
  */
15
- export type AnalyticsIdentifyUserInput<
16
+ export interface AnalyticsIdentifyUserInput<
16
17
  ServiceOptions extends AnalyticsServiceOptions = AnalyticsServiceOptions,
17
- > = {
18
+ > {
18
19
  /**
19
20
  * A User ID associated to the current device.
20
21
  */
@@ -29,7 +30,7 @@ export type AnalyticsIdentifyUserInput<
29
30
  * Options to be passed to the API.
30
31
  */
31
32
  options?: ServiceOptions;
32
- };
33
+ }
33
34
 
34
35
  /**
35
36
  * Input type for `configureAutoTrack`.
@@ -1,10 +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
- export type KinesisStream = {
4
+ export interface KinesisStream {
5
5
  region: string;
6
6
  streamName: string;
7
- };
7
+ }
8
8
 
9
9
  export type KinesisShard = KinesisStream & {
10
10
  partitionKey: string;
@@ -1,22 +1,22 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- export type SessionTrackingOptions = {
4
+ export interface SessionTrackingOptions {
5
5
  attributes?: TrackerAttributes;
6
- };
6
+ }
7
7
 
8
- export type PageViewTrackingOptions = {
8
+ export interface PageViewTrackingOptions {
9
9
  attributes?: TrackerAttributes;
10
10
  eventName?: string;
11
- urlProvider?: () => string;
11
+ urlProvider?(): string;
12
12
  appType?: 'multiPage' | 'singlePage';
13
- };
13
+ }
14
14
 
15
- export type EventTrackingOptions = {
15
+ export interface EventTrackingOptions {
16
16
  attributes?: TrackerAttributes;
17
17
  events?: DOMEvent[];
18
18
  selectorPrefix?: string;
19
- };
19
+ }
20
20
 
21
21
  export type TrackerType = 'event' | 'pageView' | 'session';
22
22
 
@@ -24,7 +24,7 @@ export type TrackerAttributes = Record<string, string>;
24
24
 
25
25
  export type TrackerEventRecorder = (
26
26
  eventName: string,
27
- attributes: TrackerAttributes
27
+ attributes: TrackerAttributes,
28
28
  ) => void;
29
29
 
30
30
  export type DOMEvent = keyof GlobalEventHandlersEventMap;
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { ConsoleLogger } from '@aws-amplify/core';
5
+
5
6
  import { EventBufferConfig, IAnalyticsClient } from './';
6
7
 
7
8
  const logger = new ConsoleLogger('EventBuffer');
@@ -15,7 +16,7 @@ export class EventBuffer<T> {
15
16
 
16
17
  constructor(
17
18
  config: EventBufferConfig,
18
- getAnalyticsClient: () => IAnalyticsClient<T>
19
+ getAnalyticsClient: () => IAnalyticsClient<T>,
19
20
  ) {
20
21
  this.list = [];
21
22
  this.config = config;
@@ -27,7 +28,7 @@ export class EventBuffer<T> {
27
28
  for (const event of events) {
28
29
  if (this.list.length + 1 > this.config.bufferSize) {
29
30
  logger.debug(
30
- `Exceed ${typeof event} event buffer limits, event dropped`
31
+ `Exceed ${typeof event} event buffer limits, event dropped`,
31
32
  );
32
33
  continue;
33
34
  }
@@ -1,12 +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
- export interface IAnalyticsClient<T> {
5
- (events: T[]): Promise<T[]>;
6
- }
4
+ export type IAnalyticsClient<T> = (events: T[]) => Promise<T[]>;
7
5
 
8
- export type EventBufferConfig = {
6
+ export interface EventBufferConfig {
9
7
  flushSize: number;
10
8
  flushInterval: number;
11
9
  bufferSize: number;
12
- };
10
+ }
@@ -3,13 +3,14 @@
3
3
 
4
4
  export const groupBy = <T>(
5
5
  getGroupId: (x: T) => string,
6
- list: T[]
6
+ list: T[],
7
7
  ): Record<string, T[]> => {
8
8
  return list.reduce(
9
9
  (result, current) => {
10
10
  const groupId = getGroupId(current);
11
+
11
12
  return { ...result, [groupId]: [...(result[groupId] ?? []), current] };
12
13
  },
13
- {} as Record<string, T[]>
14
+ {} as Record<string, T[]>,
14
15
  );
15
16
  };
@@ -1,14 +1,16 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { AnalyticsValidationErrorCode, assertValidationError } from '../errors';
5
4
  import { fetchAuthSession } from '@aws-amplify/core';
6
5
 
6
+ import { AnalyticsValidationErrorCode, assertValidationError } from '../errors';
7
+
7
8
  export const resolveCredentials = async () => {
8
9
  const { credentials, identityId } = await fetchAuthSession();
9
10
  assertValidationError(
10
11
  !!credentials,
11
- AnalyticsValidationErrorCode.NoCredentials
12
+ AnalyticsValidationErrorCode.NoCredentials,
12
13
  );
14
+
13
15
  return { credentials, identityId };
14
16
  };