@aws-amplify/analytics 7.0.1-console-preview.f63250a.0 → 7.0.1-console-preview.e8aa063.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 (254) hide show
  1. package/lib/errors/AnalyticsError.d.ts +7 -0
  2. package/lib/errors/AnalyticsError.js +23 -0
  3. package/lib/errors/assertValidationError.d.ts +5 -0
  4. package/lib/errors/assertValidationError.js +17 -0
  5. package/lib/errors/index.d.ts +3 -0
  6. package/lib/errors/index.js +12 -0
  7. package/lib/errors/validation.d.ts +9 -0
  8. package/lib/errors/validation.js +31 -0
  9. package/lib/index.d.ts +0 -3
  10. package/lib/index.js +0 -15
  11. package/lib/providers/pinpoint/apis/identifyUser.d.ts +10 -0
  12. package/lib/providers/pinpoint/apis/identifyUser.js +44 -0
  13. package/lib/providers/pinpoint/apis/index.d.ts +2 -0
  14. package/lib/providers/pinpoint/apis/index.js +9 -0
  15. package/lib/providers/pinpoint/apis/record.d.ts +11 -0
  16. package/lib/providers/pinpoint/apis/record.js +44 -0
  17. package/lib/providers/pinpoint/index.d.ts +1 -1
  18. package/lib/providers/pinpoint/index.js +1 -7
  19. package/lib/providers/pinpoint/types/errors.d.ts +9 -0
  20. package/lib/providers/pinpoint/types/errors.js +15 -0
  21. package/lib/providers/pinpoint/types/index.d.ts +2 -0
  22. package/lib/providers/pinpoint/types/index.js +7 -0
  23. package/lib/providers/pinpoint/types/parameters.d.ts +18 -0
  24. package/lib/providers/pinpoint/utils/index.d.ts +2 -0
  25. package/lib/providers/pinpoint/utils/index.js +9 -0
  26. package/lib/providers/pinpoint/utils/resolveConfig.d.ts +7 -0
  27. package/lib/providers/pinpoint/utils/resolveConfig.js +18 -0
  28. package/lib/providers/pinpoint/utils/resolveCredentials.d.ts +12 -0
  29. package/lib/providers/pinpoint/utils/resolveCredentials.js +24 -0
  30. package/lib/setupTests.js +1 -0
  31. package/lib/tsconfig.tsbuildinfo +1 -1
  32. package/{lib-esm/types/Analytics.d.ts → lib/types/analytics.d.ts} +0 -8
  33. package/lib/types/index.d.ts +1 -3
  34. package/lib/types/index.js +1 -3
  35. package/lib/utils/{UserAgent.d.ts → userAgent.d.ts} +1 -1
  36. package/lib/utils/{UserAgent.js → userAgent.js} +5 -5
  37. package/lib-esm/errors/AnalyticsError.d.ts +7 -0
  38. package/lib-esm/errors/AnalyticsError.js +20 -0
  39. package/lib-esm/errors/assertValidationError.d.ts +5 -0
  40. package/lib-esm/errors/assertValidationError.js +13 -0
  41. package/lib-esm/errors/index.d.ts +3 -0
  42. package/lib-esm/errors/index.js +5 -0
  43. package/lib-esm/errors/validation.d.ts +9 -0
  44. package/lib-esm/errors/validation.js +28 -0
  45. package/lib-esm/index.d.ts +0 -3
  46. package/lib-esm/index.js +0 -12
  47. package/lib-esm/providers/pinpoint/apis/identifyUser.d.ts +10 -0
  48. package/lib-esm/providers/pinpoint/apis/identifyUser.js +40 -0
  49. package/lib-esm/providers/pinpoint/apis/index.d.ts +2 -0
  50. package/{src/types/providers/index.ts → lib-esm/providers/pinpoint/apis/index.js} +2 -1
  51. package/lib-esm/providers/pinpoint/apis/record.d.ts +11 -0
  52. package/lib-esm/providers/pinpoint/apis/record.js +40 -0
  53. package/lib-esm/providers/pinpoint/index.d.ts +1 -1
  54. package/lib-esm/providers/pinpoint/index.js +1 -6
  55. package/lib-esm/providers/pinpoint/types/errors.d.ts +9 -0
  56. package/lib-esm/providers/pinpoint/types/errors.js +12 -0
  57. package/lib-esm/providers/pinpoint/types/index.d.ts +2 -0
  58. package/lib-esm/{types/providers → providers/pinpoint/types}/index.js +1 -1
  59. package/lib-esm/providers/pinpoint/types/parameters.d.ts +18 -0
  60. package/lib-esm/providers/pinpoint/utils/index.d.ts +2 -0
  61. package/lib-esm/{utils/AppUtils.js → providers/pinpoint/utils/index.js} +2 -4
  62. package/lib-esm/providers/pinpoint/utils/resolveConfig.d.ts +7 -0
  63. package/lib-esm/providers/pinpoint/utils/resolveConfig.js +14 -0
  64. package/lib-esm/providers/pinpoint/utils/resolveCredentials.d.ts +12 -0
  65. package/lib-esm/providers/pinpoint/utils/resolveCredentials.js +20 -0
  66. package/lib-esm/setupTests.js +1 -0
  67. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  68. package/{lib/types/Analytics.d.ts → lib-esm/types/analytics.d.ts} +0 -8
  69. package/lib-esm/types/index.d.ts +1 -3
  70. package/lib-esm/types/index.js +1 -3
  71. package/lib-esm/utils/{UserAgent.d.ts → userAgent.d.ts} +1 -1
  72. package/lib-esm/utils/{UserAgent.js → userAgent.js} +1 -1
  73. package/package.json +11 -29
  74. package/src/errors/AnalyticsError.ts +18 -0
  75. package/src/errors/assertValidationError.ts +19 -0
  76. package/src/errors/index.ts +6 -0
  77. package/src/errors/validation.ts +31 -0
  78. package/src/index.ts +0 -15
  79. package/src/providers/pinpoint/apis/identifyUser.ts +35 -0
  80. package/src/{utils/AppUtils.ts → providers/pinpoint/apis/index.ts} +2 -4
  81. package/src/providers/pinpoint/apis/record.ts +50 -0
  82. package/src/providers/pinpoint/index.ts +1 -3
  83. package/src/providers/pinpoint/types/errors.ts +12 -0
  84. package/src/providers/pinpoint/types/index.ts +5 -0
  85. package/src/providers/pinpoint/types/parameters.ts +24 -0
  86. package/src/providers/pinpoint/utils/index.ts +5 -0
  87. package/src/providers/pinpoint/utils/resolveConfig.ts +18 -0
  88. package/src/providers/pinpoint/utils/resolveCredentials.ts +20 -0
  89. package/src/types/{Analytics.ts → analytics.ts} +1 -10
  90. package/src/types/index.ts +1 -3
  91. package/src/utils/{UserAgent.ts → userAgent.ts} +1 -1
  92. package/lib/Analytics.d.ts +0 -87
  93. package/lib/Analytics.js +0 -354
  94. package/lib/providers/AWSKinesisFirehoseProvider.d.ts +0 -12
  95. package/lib/providers/AWSKinesisFirehoseProvider.js +0 -82
  96. package/lib/providers/AWSKinesisProvider.d.ts +0 -43
  97. package/lib/providers/AWSKinesisProvider.js +0 -240
  98. package/lib/providers/AWSPinpointProvider.d.ts +0 -67
  99. package/lib/providers/AWSPinpointProvider.js +0 -576
  100. package/lib/providers/AmazonPersonalizeHelper/DataType.d.ts +0 -40
  101. package/lib/providers/AmazonPersonalizeHelper/MediaAutoTrack.d.ts +0 -20
  102. package/lib/providers/AmazonPersonalizeHelper/MediaAutoTrack.js +0 -156
  103. package/lib/providers/AmazonPersonalizeHelper/SessionInfoManager.d.ts +0 -17
  104. package/lib/providers/AmazonPersonalizeHelper/SessionInfoManager.js +0 -96
  105. package/lib/providers/AmazonPersonalizeHelper/index.d.ts +0 -3
  106. package/lib/providers/AmazonPersonalizeHelper/index.js +0 -7
  107. package/lib/providers/AmazonPersonalizeProvider.d.ts +0 -76
  108. package/lib/providers/AmazonPersonalizeProvider.js +0 -331
  109. package/lib/providers/EventBuffer.d.ts +0 -28
  110. package/lib/providers/EventBuffer.js +0 -209
  111. package/lib/providers/index.d.ts +0 -4
  112. package/lib/providers/index.js +0 -14
  113. package/lib/trackers/EventTracker.d.ts +0 -9
  114. package/lib/trackers/EventTracker.js +0 -99
  115. package/lib/trackers/PageViewTracker.d.ts +0 -12
  116. package/lib/trackers/PageViewTracker.js +0 -158
  117. package/lib/trackers/SessionTracker-rn.d.ts +0 -12
  118. package/lib/trackers/SessionTracker-rn.js +0 -134
  119. package/lib/trackers/SessionTracker.d.ts +0 -14
  120. package/lib/trackers/SessionTracker.js +0 -163
  121. package/lib/trackers/index.d.ts +0 -3
  122. package/lib/trackers/index.js +0 -11
  123. package/lib/trackers/reactnative.d.ts +0 -8
  124. package/lib/trackers/reactnative.js +0 -19
  125. package/lib/types/Analytics.js +0 -2
  126. package/lib/types/Provider.d.ts +0 -10
  127. package/lib/types/providers/AWSKinesisProvider.d.ts +0 -6
  128. package/lib/types/providers/AWSKinesisProvider.js +0 -2
  129. package/lib/types/providers/AWSPinpointProvider.d.ts +0 -50
  130. package/lib/types/providers/AWSPinpointProvider.js +0 -2
  131. package/lib/types/providers/AmazonPersonalizeProvider.d.ts +0 -7
  132. package/lib/types/providers/AmazonPersonalizeProvider.js +0 -2
  133. package/lib/types/providers/index.d.ts +0 -1
  134. package/lib/types/providers/index.js +0 -6
  135. package/lib/utils/AppUtils.d.ts +0 -2
  136. package/lib/utils/AppUtils.js +0 -9
  137. package/lib/utils/AppUtils.native.d.ts +0 -2
  138. package/lib/utils/AppUtils.native.js +0 -10
  139. package/lib/utils/MethodEmbed.d.ts +0 -11
  140. package/lib/utils/MethodEmbed.js +0 -43
  141. package/lib/vendor/dom-utils/closest.d.ts +0 -12
  142. package/lib/vendor/dom-utils/closest.js +0 -27
  143. package/lib/vendor/dom-utils/delegate.d.ts +0 -18
  144. package/lib/vendor/dom-utils/delegate.js +0 -51
  145. package/lib/vendor/dom-utils/dispatch.d.ts +0 -17
  146. package/lib/vendor/dom-utils/dispatch.js +0 -51
  147. package/lib/vendor/dom-utils/get-attributes.d.ts +0 -11
  148. package/lib/vendor/dom-utils/get-attributes.js +0 -28
  149. package/lib/vendor/dom-utils/index.d.ts +0 -7
  150. package/lib/vendor/dom-utils/index.js +0 -17
  151. package/lib/vendor/dom-utils/matches.d.ts +0 -11
  152. package/lib/vendor/dom-utils/matches.js +0 -69
  153. package/lib/vendor/dom-utils/parents.d.ts +0 -10
  154. package/lib/vendor/dom-utils/parents.js +0 -22
  155. package/lib/vendor/dom-utils/parse-url.d.ts +0 -9
  156. package/lib/vendor/dom-utils/parse-url.js +0 -59
  157. package/lib-esm/Analytics.d.ts +0 -87
  158. package/lib-esm/Analytics.js +0 -351
  159. package/lib-esm/providers/AWSKinesisFirehoseProvider.d.ts +0 -12
  160. package/lib-esm/providers/AWSKinesisFirehoseProvider.js +0 -79
  161. package/lib-esm/providers/AWSKinesisProvider.d.ts +0 -43
  162. package/lib-esm/providers/AWSKinesisProvider.js +0 -237
  163. package/lib-esm/providers/AWSPinpointProvider.d.ts +0 -67
  164. package/lib-esm/providers/AWSPinpointProvider.js +0 -573
  165. package/lib-esm/providers/AmazonPersonalizeHelper/DataType.d.ts +0 -40
  166. package/lib-esm/providers/AmazonPersonalizeHelper/MediaAutoTrack.d.ts +0 -20
  167. package/lib-esm/providers/AmazonPersonalizeHelper/MediaAutoTrack.js +0 -153
  168. package/lib-esm/providers/AmazonPersonalizeHelper/SessionInfoManager.d.ts +0 -17
  169. package/lib-esm/providers/AmazonPersonalizeHelper/SessionInfoManager.js +0 -92
  170. package/lib-esm/providers/AmazonPersonalizeHelper/index.d.ts +0 -3
  171. package/lib-esm/providers/AmazonPersonalizeHelper/index.js +0 -2
  172. package/lib-esm/providers/AmazonPersonalizeProvider.d.ts +0 -76
  173. package/lib-esm/providers/AmazonPersonalizeProvider.js +0 -328
  174. package/lib-esm/providers/EventBuffer.d.ts +0 -28
  175. package/lib-esm/providers/EventBuffer.js +0 -207
  176. package/lib-esm/providers/index.d.ts +0 -4
  177. package/lib-esm/providers/index.js +0 -7
  178. package/lib-esm/trackers/EventTracker.d.ts +0 -9
  179. package/lib-esm/trackers/EventTracker.js +0 -96
  180. package/lib-esm/trackers/PageViewTracker.d.ts +0 -12
  181. package/lib-esm/trackers/PageViewTracker.js +0 -155
  182. package/lib-esm/trackers/SessionTracker-rn.d.ts +0 -12
  183. package/lib-esm/trackers/SessionTracker-rn.js +0 -131
  184. package/lib-esm/trackers/SessionTracker.d.ts +0 -14
  185. package/lib-esm/trackers/SessionTracker.js +0 -160
  186. package/lib-esm/trackers/index.d.ts +0 -3
  187. package/lib-esm/trackers/index.js +0 -5
  188. package/lib-esm/trackers/reactnative.d.ts +0 -8
  189. package/lib-esm/trackers/reactnative.js +0 -14
  190. package/lib-esm/types/Analytics.js +0 -1
  191. package/lib-esm/types/Provider.d.ts +0 -10
  192. package/lib-esm/types/providers/AWSKinesisProvider.d.ts +0 -6
  193. package/lib-esm/types/providers/AWSKinesisProvider.js +0 -1
  194. package/lib-esm/types/providers/AWSPinpointProvider.d.ts +0 -50
  195. package/lib-esm/types/providers/AWSPinpointProvider.js +0 -1
  196. package/lib-esm/types/providers/AmazonPersonalizeProvider.d.ts +0 -7
  197. package/lib-esm/types/providers/AmazonPersonalizeProvider.js +0 -1
  198. package/lib-esm/types/providers/index.d.ts +0 -1
  199. package/lib-esm/utils/AppUtils.d.ts +0 -2
  200. package/lib-esm/utils/AppUtils.native.d.ts +0 -2
  201. package/lib-esm/utils/AppUtils.native.js +0 -7
  202. package/lib-esm/utils/MethodEmbed.d.ts +0 -11
  203. package/lib-esm/utils/MethodEmbed.js +0 -40
  204. package/lib-esm/vendor/dom-utils/closest.d.ts +0 -12
  205. package/lib-esm/vendor/dom-utils/closest.js +0 -23
  206. package/lib-esm/vendor/dom-utils/delegate.d.ts +0 -18
  207. package/lib-esm/vendor/dom-utils/delegate.js +0 -47
  208. package/lib-esm/vendor/dom-utils/dispatch.d.ts +0 -17
  209. package/lib-esm/vendor/dom-utils/dispatch.js +0 -47
  210. package/lib-esm/vendor/dom-utils/get-attributes.d.ts +0 -11
  211. package/lib-esm/vendor/dom-utils/get-attributes.js +0 -24
  212. package/lib-esm/vendor/dom-utils/index.d.ts +0 -7
  213. package/lib-esm/vendor/dom-utils/index.js +0 -7
  214. package/lib-esm/vendor/dom-utils/matches.d.ts +0 -11
  215. package/lib-esm/vendor/dom-utils/matches.js +0 -65
  216. package/lib-esm/vendor/dom-utils/parents.d.ts +0 -10
  217. package/lib-esm/vendor/dom-utils/parents.js +0 -18
  218. package/lib-esm/vendor/dom-utils/parse-url.d.ts +0 -9
  219. package/lib-esm/vendor/dom-utils/parse-url.js +0 -55
  220. package/src/Analytics.ts +0 -446
  221. package/src/providers/AWSKinesisFirehoseProvider.ts +0 -105
  222. package/src/providers/AWSKinesisProvider.ts +0 -250
  223. package/src/providers/AWSPinpointProvider.ts +0 -685
  224. package/src/providers/AmazonPersonalizeHelper/DataType.ts +0 -49
  225. package/src/providers/AmazonPersonalizeHelper/MediaAutoTrack.ts +0 -196
  226. package/src/providers/AmazonPersonalizeHelper/SessionInfoManager.ts +0 -121
  227. package/src/providers/AmazonPersonalizeHelper/index.ts +0 -11
  228. package/src/providers/AmazonPersonalizeProvider.ts +0 -398
  229. package/src/providers/EventBuffer.ts +0 -257
  230. package/src/providers/index.ts +0 -8
  231. package/src/trackers/EventTracker.ts +0 -115
  232. package/src/trackers/PageViewTracker.ts +0 -157
  233. package/src/trackers/SessionTracker-rn.ts +0 -134
  234. package/src/trackers/SessionTracker.ts +0 -179
  235. package/src/trackers/index.ts +0 -5
  236. package/src/trackers/reactnative.ts +0 -13
  237. package/src/types/Provider.ts +0 -26
  238. package/src/types/providers/AWSKinesisProvider.ts +0 -8
  239. package/src/types/providers/AWSPinpointProvider.ts +0 -60
  240. package/src/types/providers/AmazonPersonalizeProvider.ts +0 -9
  241. package/src/utils/AppUtils.native.ts +0 -9
  242. package/src/utils/MethodEmbed.ts +0 -49
  243. package/src/vendor/dom-utils/closest.ts +0 -25
  244. package/src/vendor/dom-utils/delegate.ts +0 -51
  245. package/src/vendor/dom-utils/dispatch.ts +0 -59
  246. package/src/vendor/dom-utils/get-attributes.ts +0 -26
  247. package/src/vendor/dom-utils/index.ts +0 -7
  248. package/src/vendor/dom-utils/matches.ts +0 -68
  249. package/src/vendor/dom-utils/parents.ts +0 -19
  250. package/src/vendor/dom-utils/parse-url.ts +0 -66
  251. /package/lib/{types/Provider.js → providers/pinpoint/types/parameters.js} +0 -0
  252. /package/lib/{providers/AmazonPersonalizeHelper/DataType.js → types/analytics.js} +0 -0
  253. /package/lib-esm/{types/Provider.js → providers/pinpoint/types/parameters.js} +0 -0
  254. /package/lib-esm/{providers/AmazonPersonalizeHelper/DataType.js → types/analytics.js} +0 -0
@@ -1,115 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { delegate } from '../vendor/dom-utils';
5
- import { EventTrackOpts } from '../types';
6
- import { ConsoleLogger as Logger, browserOrNode } from '@aws-amplify/core';
7
-
8
- const logger = new Logger('EventTracker');
9
-
10
- const defaultOpts: EventTrackOpts = {
11
- enable: false,
12
- events: ['click'],
13
- selectorPrefix: 'data-amplify-analytics-',
14
- provider: 'AWSPinpoint',
15
- };
16
-
17
- export class EventTracker {
18
- private _tracker;
19
- private _config: EventTrackOpts;
20
- private _delegates;
21
-
22
- constructor(tracker, opts) {
23
- if (!browserOrNode().isBrowser || !window.addEventListener) {
24
- logger.debug('not in the supported web environment');
25
- return;
26
- }
27
-
28
- this._config = Object.assign({}, defaultOpts, opts);
29
- this._tracker = tracker;
30
- this._delegates = {};
31
- this._trackFunc = this._trackFunc.bind(this);
32
-
33
- logger.debug('initialize pageview tracker with opts', this._config);
34
-
35
- this.configure(this._config);
36
- }
37
-
38
- configure(opts?: EventTrackOpts) {
39
- Object.assign(this._config, opts);
40
-
41
- if (!this._config.enable) {
42
- Object.keys(this._delegates).forEach(key => {
43
- if (typeof this._delegates[key].destroy === 'function')
44
- this._delegates[key].destroy();
45
- });
46
- this._delegates = {};
47
- } else if (
48
- this._config.enable &&
49
- Object.keys(this._delegates).length === 0
50
- ) {
51
- const selector = '[' + this._config.selectorPrefix + 'on]';
52
- this._config.events.forEach(evt => {
53
- this._delegates[evt] = delegate(
54
- document,
55
- evt,
56
- selector,
57
- this._trackFunc,
58
- { composed: true, useCapture: true }
59
- );
60
- });
61
- }
62
-
63
- return this._config;
64
- }
65
-
66
- private async _trackFunc(event, element) {
67
- // the events specifed in 'amplify-analytics-on' selector
68
- const customAttrs = {};
69
- const events = element
70
- .getAttribute(this._config.selectorPrefix + 'on')
71
- .split(/\s*,\s*/);
72
- const eventName = element.getAttribute(
73
- this._config.selectorPrefix + 'name'
74
- );
75
-
76
- const attrs = element.getAttribute(this._config.selectorPrefix + 'attrs');
77
- if (attrs) {
78
- attrs.split(/\s*,\s*/).forEach(attr => {
79
- const tmp = attr.trim().split(/\s*:\s*/);
80
- customAttrs[tmp[0]] = tmp[1];
81
- });
82
- }
83
-
84
- const defaultAttrs =
85
- typeof this._config.attributes === 'function'
86
- ? await this._config.attributes()
87
- : this._config.attributes;
88
-
89
- const attributes = Object.assign(
90
- {
91
- type: event.type,
92
- target: `${event.target.localName} with id ${event.target.id}`,
93
- },
94
- defaultAttrs,
95
- customAttrs
96
- );
97
-
98
- logger.debug('events needed to be recorded', events);
99
- logger.debug('attributes needed to be attached', customAttrs);
100
- if (events.indexOf(event.type) < 0) {
101
- logger.debug(`event ${event.type} is not selected to be recorded`);
102
- return;
103
- }
104
-
105
- this._tracker(
106
- {
107
- name: eventName || 'event',
108
- attributes,
109
- },
110
- this._config.provider
111
- ).catch(e => {
112
- logger.debug(`Failed to record the ${event.type} event', ${e}`);
113
- });
114
- }
115
- }
@@ -1,157 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { pageViewTrackOpts } from '../types';
5
- import { MethodEmbed } from '../utils/MethodEmbed';
6
- import { ConsoleLogger as Logger, browserOrNode } from '@aws-amplify/core';
7
-
8
- const logger = new Logger('PageViewTracker');
9
- const PREV_URL_KEY = 'aws-amplify-analytics-prevUrl';
10
-
11
- const getUrl = () => {
12
- if (!browserOrNode().isBrowser) return '';
13
- else return window.location.origin + window.location.pathname;
14
- };
15
-
16
- const defaultOpts: pageViewTrackOpts = {
17
- enable: false,
18
- provider: 'AWSPinpoint',
19
- getUrl,
20
- };
21
-
22
- export class PageViewTracker {
23
- private _config: pageViewTrackOpts;
24
- private _tracker;
25
- private _hasEnabled;
26
-
27
- constructor(tracker, opts) {
28
- logger.debug('initialize pageview tracker with opts', opts);
29
- this._config = Object.assign({}, defaultOpts, opts);
30
- this._tracker = tracker;
31
- this._hasEnabled = false;
32
- this._trackFunc = this._trackFunc.bind(this);
33
-
34
- if (this._config.type === 'SPA') {
35
- this._pageViewTrackSPA();
36
- } else {
37
- this._pageViewTrackDefault();
38
- }
39
- }
40
-
41
- public configure(opts?: pageViewTrackOpts) {
42
- Object.assign(this._config, opts);
43
-
44
- // if spa, need to remove those listeners if disabled
45
- if (this._config.type === 'SPA') {
46
- this._pageViewTrackSPA();
47
- }
48
-
49
- return this._config;
50
- }
51
-
52
- private _isSameUrl() {
53
- const prevUrl = sessionStorage.getItem(PREV_URL_KEY);
54
- const curUrl = this._config.getUrl();
55
-
56
- if (prevUrl === curUrl) {
57
- logger.debug('the url is same');
58
- return true;
59
- } else return false;
60
- }
61
-
62
- private async _pageViewTrackDefault() {
63
- if (
64
- !browserOrNode().isBrowser ||
65
- !window.addEventListener ||
66
- !window.sessionStorage
67
- ) {
68
- logger.debug('not in the supported web enviroment');
69
- return;
70
- }
71
- const url = this._config.getUrl();
72
- const customAttrs =
73
- typeof this._config.attributes === 'function'
74
- ? await this._config.attributes()
75
- : this._config.attributes;
76
- const attributes = Object.assign(
77
- {
78
- url,
79
- },
80
- customAttrs
81
- );
82
-
83
- if (this._config.enable && !this._isSameUrl()) {
84
- this._tracker(
85
- {
86
- name: this._config.eventName || 'pageView',
87
- attributes,
88
- },
89
- this._config.provider
90
- ).catch(e => {
91
- logger.debug('Failed to record the page view event', e);
92
- });
93
- sessionStorage.setItem(PREV_URL_KEY, url);
94
- }
95
- }
96
-
97
- private async _trackFunc() {
98
- if (
99
- !browserOrNode().isBrowser ||
100
- !window.addEventListener ||
101
- !history.pushState ||
102
- !window.sessionStorage
103
- ) {
104
- logger.debug('not in the supported web enviroment');
105
- return;
106
- }
107
-
108
- const url = this._config.getUrl();
109
- const customAttrs =
110
- typeof this._config.attributes === 'function'
111
- ? await this._config.attributes()
112
- : this._config.attributes;
113
- const attributes = Object.assign(
114
- {
115
- url,
116
- },
117
- customAttrs
118
- );
119
-
120
- if (!this._isSameUrl()) {
121
- this._tracker(
122
- {
123
- name: this._config.eventName || 'pageView',
124
- attributes,
125
- },
126
- this._config.provider
127
- ).catch(e => {
128
- logger.debug('Failed to record the page view event', e);
129
- });
130
- sessionStorage.setItem(PREV_URL_KEY, url);
131
- }
132
- }
133
-
134
- private _pageViewTrackSPA() {
135
- if (
136
- !browserOrNode().isBrowser ||
137
- !window.addEventListener ||
138
- !history.pushState
139
- ) {
140
- logger.debug('not in the supported web enviroment');
141
- return;
142
- }
143
-
144
- if (this._config.enable && !this._hasEnabled) {
145
- MethodEmbed.add(history, 'pushState', this._trackFunc);
146
- MethodEmbed.add(history, 'replaceState', this._trackFunc);
147
- window.addEventListener('popstate', this._trackFunc);
148
- this._trackFunc();
149
- this._hasEnabled = true;
150
- } else {
151
- MethodEmbed.remove(history, 'pushState');
152
- MethodEmbed.remove(history, 'replaceState');
153
- window.removeEventListener('popstate', this._trackFunc);
154
- this._hasEnabled = false;
155
- }
156
- }
157
- }
@@ -1,134 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // the session tracker for react native
5
-
6
- import { ConsoleLogger as Logger } from '@aws-amplify/core';
7
- import { SessionTrackOpts } from '../types';
8
- import { AppState } from 'react-native';
9
-
10
- const logger = new Logger('SessionTracker');
11
-
12
- const defaultOpts: SessionTrackOpts = {
13
- enable: false,
14
- provider: 'AWSPinpoint',
15
- };
16
-
17
- let initialEventSent = false;
18
-
19
- export class SessionTracker {
20
- private _tracker;
21
- private _hasEnabled;
22
- private _config: SessionTrackOpts;
23
- private _currentState;
24
-
25
- constructor(tracker, opts) {
26
- this._config = Object.assign({}, defaultOpts, opts);
27
- this._tracker = tracker;
28
-
29
- this._hasEnabled = false;
30
- this._trackFunc = this._trackFunc.bind(this);
31
- this._currentState = AppState.currentState;
32
- this.configure(this._config);
33
- }
34
-
35
- private _envCheck() {
36
- if (!AppState) {
37
- logger.debug('not in the supported react native environment');
38
- return false;
39
- }
40
- return true;
41
- }
42
-
43
- private async _trackFunc(nextAppState) {
44
- const customAttrs =
45
- typeof this._config.attributes === 'function'
46
- ? await this._config.attributes()
47
- : this._config.attributes;
48
- const attributes = Object.assign({}, customAttrs);
49
-
50
- if (
51
- this._currentState.match(/inactive|background/) &&
52
- nextAppState === 'active'
53
- ) {
54
- logger.debug('App has come to the foreground, recording start session');
55
- this._tracker(
56
- {
57
- name: '_session.start',
58
- attributes,
59
- immediate: false,
60
- },
61
- this._config.provider
62
- ).catch(e => {
63
- logger.debug('record session start event failed.', e);
64
- });
65
- }
66
- if (
67
- this._currentState.match(/active/) &&
68
- nextAppState.match(/inactive|background/)
69
- ) {
70
- logger.debug(
71
- 'App has come to inactive/background, recording stop session'
72
- );
73
- this._tracker(
74
- {
75
- name: '_session.stop',
76
- attributes,
77
- immediate: false,
78
- },
79
- this._config.provider
80
- ).catch(e => {
81
- logger.debug('record session stop event failed.', e);
82
- });
83
- }
84
-
85
- this._currentState = nextAppState;
86
- }
87
-
88
- // to keep configure a synchronized function
89
- private async _sendInitialEvent() {
90
- if (initialEventSent) {
91
- logger.debug('the start session has been sent when the page is loaded');
92
- return;
93
- } else {
94
- initialEventSent = true;
95
- }
96
-
97
- const customAttrs =
98
- typeof this._config.attributes === 'function'
99
- ? await this._config.attributes()
100
- : this._config.attributes;
101
- const attributes = Object.assign({}, customAttrs);
102
-
103
- this._tracker(
104
- {
105
- name: '_session.start',
106
- attributes,
107
- immediate: false,
108
- },
109
- this._config.provider
110
- ).catch(e => {
111
- logger.debug('record session start event failed.', e);
112
- });
113
- }
114
-
115
- configure(opts?: SessionTrackOpts) {
116
- if (!this._envCheck()) {
117
- return this._config;
118
- }
119
-
120
- Object.assign(this._config, opts);
121
- if (this._config.enable && !this._hasEnabled) {
122
- // send a start session as soon as it's enabled
123
- this._sendInitialEvent();
124
- // listen on events
125
- AppState.addEventListener('change', this._trackFunc, false);
126
- this._hasEnabled = true;
127
- } else if (!this._config.enable && this._hasEnabled) {
128
- AppState.removeEventListener('change', this._trackFunc, false);
129
- this._hasEnabled = false;
130
- }
131
-
132
- return this._config;
133
- }
134
- }
@@ -1,179 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // the session tracker for web
5
-
6
- import {
7
- ConsoleLogger as Logger,
8
- Hub,
9
- Constants,
10
- browserOrNode,
11
- } from '@aws-amplify/core';
12
- import { SessionTrackOpts } from '../types';
13
-
14
- const logger = new Logger('SessionTracker');
15
-
16
- const defaultOpts: SessionTrackOpts = {
17
- enable: false,
18
- provider: 'AWSPinpoint',
19
- };
20
-
21
- let initialEventSent = false;
22
-
23
- export class SessionTracker {
24
- private _tracker;
25
- private _hasEnabled;
26
- private _config: SessionTrackOpts;
27
-
28
- private _hidden;
29
- private _visibilityChange;
30
-
31
- constructor(tracker, opts) {
32
- this._config = Object.assign({}, defaultOpts, opts);
33
- this._tracker = tracker;
34
-
35
- this._hasEnabled = false;
36
- this._trackFunc = this._trackFunc.bind(this);
37
- this._trackBeforeUnload = this._trackBeforeUnload.bind(this);
38
-
39
- this.configure(this._config);
40
- }
41
-
42
- private _envCheck() {
43
- if (!browserOrNode().isBrowser) {
44
- return false;
45
- }
46
-
47
- if (!document || !document.addEventListener) {
48
- logger.debug('not in the supported web environment');
49
- return false;
50
- }
51
-
52
- if (typeof document.hidden !== 'undefined') {
53
- this._hidden = 'hidden';
54
- this._visibilityChange = 'visibilitychange';
55
- } else if (typeof document['msHidden'] !== 'undefined') {
56
- this._hidden = 'msHidden';
57
- this._visibilityChange = 'msvisibilitychange';
58
- } else if (typeof document['webkitHidden'] !== 'undefined') {
59
- this._hidden = 'webkitHidden';
60
- this._visibilityChange = 'webkitvisibilitychange';
61
- } else {
62
- logger.debug('not in the supported web environment');
63
- return false;
64
- }
65
- return true;
66
- }
67
-
68
- private async _trackFunc() {
69
- const customAttrs =
70
- typeof this._config.attributes === 'function'
71
- ? await this._config.attributes()
72
- : this._config.attributes;
73
-
74
- const attributes = Object.assign({}, customAttrs);
75
-
76
- if (document.visibilityState === this._hidden) {
77
- this._tracker(
78
- {
79
- name: '_session.stop',
80
- attributes,
81
- },
82
- this._config.provider
83
- ).catch(e => {
84
- logger.debug('record session stop event failed.', e);
85
- });
86
- } else {
87
- this._tracker(
88
- {
89
- name: '_session.start',
90
- attributes,
91
- },
92
- this._config.provider
93
- ).catch(e => {
94
- logger.debug('record session start event failed.', e);
95
- });
96
- }
97
- }
98
-
99
- private _trackBeforeUnload(event) {
100
- // before unload callback cannot be async => https://github.com/aws-amplify/amplify-js/issues/2088
101
-
102
- const customAttrs =
103
- typeof this._config.attributes === 'function'
104
- ? Promise.resolve(this._config.attributes())
105
- : Promise.resolve(this._config.attributes);
106
-
107
- customAttrs.then(custom => {
108
- const attributes = Object.assign({}, custom);
109
-
110
- this._tracker(
111
- {
112
- name: '_session.stop',
113
- attributes,
114
- immediate: true,
115
- },
116
- this._config.provider
117
- ).catch(e => {
118
- logger.debug('record session stop event failed.', e);
119
- });
120
- });
121
- }
122
-
123
- // to keep configure a synchronized function
124
- private async _sendInitialEvent() {
125
- if (initialEventSent) {
126
- logger.debug('the start session has been sent when the page is loaded');
127
- return;
128
- } else {
129
- initialEventSent = true;
130
- }
131
-
132
- const customAttrs =
133
- typeof this._config.attributes === 'function'
134
- ? await this._config.attributes()
135
- : this._config.attributes;
136
-
137
- const attributes = Object.assign({}, customAttrs);
138
-
139
- this._tracker(
140
- {
141
- name: '_session.start',
142
- attributes,
143
- },
144
- this._config.provider
145
- ).catch(e => {
146
- logger.debug('record session start event failed.', e);
147
- });
148
- }
149
-
150
- configure(opts?: SessionTrackOpts) {
151
- if (!this._envCheck()) {
152
- return this._config;
153
- }
154
-
155
- Object.assign(this._config, opts);
156
- if (this._config.enable && !this._hasEnabled) {
157
- // send a start session as soon as it's enabled
158
- this._sendInitialEvent();
159
- // listen on events
160
- document.addEventListener(this._visibilityChange, this._trackFunc, false);
161
- window.addEventListener('beforeunload', this._trackBeforeUnload, false);
162
- this._hasEnabled = true;
163
- } else if (!this._config.enable && this._hasEnabled) {
164
- document.removeEventListener(
165
- this._visibilityChange,
166
- this._trackFunc,
167
- false
168
- );
169
- window.removeEventListener(
170
- 'beforeunload',
171
- this._trackBeforeUnload,
172
- false
173
- );
174
- this._hasEnabled = false;
175
- }
176
-
177
- return this._config;
178
- }
179
- }
@@ -1,5 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- export { PageViewTracker } from './PageViewTracker';
4
- export { EventTracker } from './EventTracker';
5
- export { SessionTracker } from './SessionTracker';
@@ -1,13 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { SessionTracker } from './SessionTracker-rn';
4
-
5
- class EventTracker {
6
- constructor(tracker, opts) {}
7
- }
8
-
9
- class PageViewTracker {
10
- constructor(tracker, opts) {}
11
- }
12
-
13
- export { EventTracker, PageViewTracker, SessionTracker };
@@ -1,26 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- export interface PromiseHandlers {
5
- resolve: Function;
6
- reject: Function;
7
- }
8
-
9
- // CAUTION: The AnalyticsProvider interface is publicly available and allows customers to implement their own custom
10
- // analytics providers. Exercise caution when modifying this class as additive changes to this interface can break
11
- // customers when not marked as optional.
12
- export interface AnalyticsProvider {
13
- // you need to implement those methods
14
-
15
- // configure your provider
16
- configure(config: object): object;
17
-
18
- // record events and returns true if succeeds
19
- record(params: object, handlers?: PromiseHandlers): Promise<boolean>;
20
-
21
- // return 'Analytics';
22
- getCategory(): string;
23
-
24
- // return the name of you provider
25
- getProviderName(): string;
26
- }
@@ -1,8 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- export interface KinesisAnalyticsEvent {
4
- data: object | string;
5
- partitionKey: string;
6
- streamName: string;
7
- immediate?: boolean;
8
- }
@@ -1,60 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { PromiseHandlers } from '../Provider';
4
-
5
- export type Event = {
6
- eventId: string;
7
- name: string;
8
- attributes: string;
9
- metrics: string;
10
- session: object;
11
- immediate: boolean;
12
- };
13
-
14
- export type EventConfig = {
15
- appId: string;
16
- endpointId: string;
17
- region: string;
18
- resendLimit: number;
19
- };
20
-
21
- export type EventParams = {
22
- event: Event;
23
- timestamp: string;
24
- config: EventConfig;
25
- credentials: object;
26
- resendLimit: number;
27
- };
28
-
29
- export type EventObject = {
30
- params: EventParams;
31
- handlers: PromiseHandlers;
32
- };
33
-
34
- export type EventMap = {
35
- [key: string]: EventObject;
36
- };
37
-
38
- export type EventBuffer = Array<EventMap>;
39
- export type EndpointBuffer = Array<EventObject>;
40
-
41
- export type PutEventsResponse = {
42
- EventsResponse: {
43
- Results?: {
44
- [endpointId: string]: {
45
- EventsItemResponse?: {
46
- [eventId: string]: {
47
- StatusCode?: number;
48
- Message?: string;
49
- };
50
- };
51
- };
52
- };
53
- };
54
- };
55
-
56
- export type EndpointFailureData = {
57
- err: any;
58
- update_params: any;
59
- endpointObject: EventObject;
60
- };
@@ -1,9 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- export interface PersonalizeAnalyticsEvent {
4
- eventType?: string;
5
- userId?: string;
6
- properties?: {
7
- [key: string]: string;
8
- };
9
- }