@aws-amplify/analytics 7.0.1-console-preview.f63250a.0 → 7.0.1-console-preview.5dc0b68.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,153 +0,0 @@
1
- var HTML5_MEDIA_EVENT;
2
- (function (HTML5_MEDIA_EVENT) {
3
- HTML5_MEDIA_EVENT["PLAY"] = "play";
4
- HTML5_MEDIA_EVENT["PAUSE"] = "pause";
5
- HTML5_MEDIA_EVENT["ENDED"] = "Ended";
6
- })(HTML5_MEDIA_EVENT || (HTML5_MEDIA_EVENT = {}));
7
- var MEDIA_TYPE;
8
- (function (MEDIA_TYPE) {
9
- MEDIA_TYPE["IFRAME"] = "IFRAME";
10
- MEDIA_TYPE["VIDEO"] = "VIDEO";
11
- MEDIA_TYPE["AUDIO"] = "AUDIO";
12
- })(MEDIA_TYPE || (MEDIA_TYPE = {}));
13
- var EVENT_TYPE;
14
- (function (EVENT_TYPE) {
15
- EVENT_TYPE["PLAY"] = "Play";
16
- EVENT_TYPE["ENDED"] = "Ended";
17
- EVENT_TYPE["PAUSE"] = "Pause";
18
- EVENT_TYPE["TIME_WATCHED"] = "TimeWatched";
19
- })(EVENT_TYPE || (EVENT_TYPE = {}));
20
- var MediaAutoTrack = /** @class */ (function () {
21
- function MediaAutoTrack(params, provider) {
22
- var _a;
23
- this.eventActionMapping = (_a = {},
24
- _a[EVENT_TYPE.ENDED] = this.endedEventAction.bind(this),
25
- _a[EVENT_TYPE.PLAY] = this.playEventAction.bind(this),
26
- _a[EVENT_TYPE.PAUSE] = this.pauseEventAction.bind(this),
27
- _a);
28
- var eventData = params.eventData;
29
- this._params = params;
30
- this._mediaElement = document.getElementById(eventData.properties['domElementId']);
31
- this._started = false;
32
- this._provider = provider;
33
- var mediaTrackFunMapping = {
34
- IFRAME: this._iframeMediaTracker,
35
- VIDEO: this._html5MediaTracker,
36
- AUDIO: this._html5MediaTracker,
37
- };
38
- mediaTrackFunMapping[this._mediaElement.tagName].bind(this)();
39
- this._initYoutubeFrame();
40
- }
41
- MediaAutoTrack.prototype._initYoutubeFrame = function () {
42
- this._youTubeIframeLoader = {
43
- src: 'https://www.youtube.com/iframe_api',
44
- loading: false,
45
- loaded: false,
46
- listeners: [],
47
- load: function (callback) {
48
- var _this = this;
49
- this.listeners.push(callback);
50
- if (this.loaded) {
51
- setTimeout(function () {
52
- _this.done();
53
- });
54
- return;
55
- }
56
- if (this.loading) {
57
- return;
58
- }
59
- this.loading = true;
60
- window['onYouTubeIframeAPIReady'] = function () {
61
- _this.loaded = true;
62
- _this.done();
63
- };
64
- var script = document.createElement('script');
65
- script.type = 'text/javascript';
66
- script.src = this.src;
67
- document.body.appendChild(script);
68
- },
69
- done: function () {
70
- delete window['onYouTubeIframeAPIReady'];
71
- while (this.listeners.length) {
72
- this.listeners.pop()(window['YT']);
73
- }
74
- },
75
- };
76
- };
77
- MediaAutoTrack.prototype._iframeMediaTracker = function () {
78
- var that = this;
79
- setInterval(function () {
80
- if (that._started) {
81
- that.recordEvent(MEDIA_TYPE.IFRAME, EVENT_TYPE.TIME_WATCHED);
82
- }
83
- }, 3 * 1000);
84
- this._youTubeIframeLoader.load(function (YT) {
85
- that._iframePlayer = new YT.Player(that._mediaElement.id, {
86
- events: { onStateChange: that._onPlayerStateChange.bind(that) },
87
- });
88
- });
89
- };
90
- MediaAutoTrack.prototype._onPlayerStateChange = function (event) {
91
- var iframeEventMapping = {
92
- 0: EVENT_TYPE.ENDED,
93
- 1: EVENT_TYPE.PLAY,
94
- 2: EVENT_TYPE.PAUSE,
95
- };
96
- var eventType = iframeEventMapping[event.data];
97
- if (eventType) {
98
- this.eventActionMapping[eventType](MEDIA_TYPE.IFRAME);
99
- }
100
- };
101
- MediaAutoTrack.prototype._html5MediaTracker = function () {
102
- var that = this;
103
- setInterval(function () {
104
- if (that._started) {
105
- that.recordEvent(MEDIA_TYPE.VIDEO, EVENT_TYPE.TIME_WATCHED);
106
- }
107
- }, 3 * 1000);
108
- this._mediaElement.addEventListener(HTML5_MEDIA_EVENT.PLAY, function () {
109
- that.eventActionMapping[EVENT_TYPE.PLAY](MEDIA_TYPE.VIDEO);
110
- }, false);
111
- this._mediaElement.addEventListener(HTML5_MEDIA_EVENT.PAUSE, function () {
112
- that.eventActionMapping[EVENT_TYPE.PAUSE](MEDIA_TYPE.VIDEO);
113
- }, false);
114
- this._mediaElement.addEventListener(HTML5_MEDIA_EVENT.ENDED, function () {
115
- that.eventActionMapping[EVENT_TYPE.ENDED](MEDIA_TYPE.VIDEO);
116
- }, false);
117
- };
118
- MediaAutoTrack.prototype.playEventAction = function (mediaType) {
119
- this._started = true;
120
- this.recordEvent(mediaType, EVENT_TYPE.PLAY);
121
- };
122
- MediaAutoTrack.prototype.pauseEventAction = function (mediaType) {
123
- this._started = false;
124
- this.recordEvent(mediaType, EVENT_TYPE.PAUSE);
125
- };
126
- MediaAutoTrack.prototype.endedEventAction = function (mediaType) {
127
- this._started = false;
128
- this.recordEvent(mediaType, EVENT_TYPE.ENDED);
129
- };
130
- MediaAutoTrack.prototype.recordEvent = function (mediaType, eventType) {
131
- var newParams = Object.assign({}, this._params);
132
- var eventData = newParams.eventData;
133
- eventData.eventType = eventType;
134
- var currentPlayTime;
135
- if (mediaType === MEDIA_TYPE.VIDEO) {
136
- currentPlayTime = this._mediaElement.currentTime;
137
- eventData.properties.duration = this._mediaElement.duration;
138
- }
139
- else {
140
- currentPlayTime = this._financial(this._iframePlayer.getCurrentTime());
141
- eventData.properties.duration = this._financial(this._iframePlayer.getDuration());
142
- }
143
- var percentage = parseFloat(currentPlayTime) / parseFloat(eventData.properties.duration);
144
- eventData.properties.eventValue = Number(percentage.toFixed(4));
145
- delete eventData.properties.domElementId;
146
- this._provider.putToBuffer(newParams);
147
- };
148
- MediaAutoTrack.prototype._financial = function (x) {
149
- return Number.parseFloat(x).toFixed(4);
150
- };
151
- return MediaAutoTrack;
152
- }());
153
- export { MediaAutoTrack };
@@ -1,17 +0,0 @@
1
- import { SessionInfo } from './DataType';
2
- export declare class SessionInfoManager {
3
- private _isBrowser;
4
- private _cache;
5
- private _timer;
6
- private _timerKey;
7
- constructor(prefixKey?: string);
8
- private _refreshTimer;
9
- private storeValue;
10
- private retrieveValue;
11
- private _getCachePrefix;
12
- getTimerKey(): any;
13
- updateSessionInfo(userId: string, sessionInfo: SessionInfo): void;
14
- private _isRequireUpdateSessionInfo;
15
- retrieveSessionInfo(trackingId: string): SessionInfo;
16
- private _isRequireNewSession;
17
- }
@@ -1,92 +0,0 @@
1
- import isEmpty from 'lodash/isEmpty';
2
- import isEqual from 'lodash/isEqual';
3
- import { v1 as uuid } from 'uuid';
4
- import { ConsoleLogger as Logger, browserOrNode, Cache } from '@aws-amplify/core';
5
- var PERSONALIZE_CACHE = '_awsct';
6
- var PERSONALIZE_CACHE_USERID = '_awsct_uid';
7
- var PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
8
- var DEFAULT_CACHE_PREFIX = 'personalize';
9
- var TIMER_INTERVAL = 30 * 1000;
10
- var DELIMITER = '.';
11
- var CACHE_EXPIRY_IN_DAYS = 7;
12
- var logger = new Logger('AmazonPersonalizeProvider');
13
- var SessionInfoManager = /** @class */ (function () {
14
- function SessionInfoManager(prefixKey) {
15
- if (prefixKey === void 0) { prefixKey = ''; }
16
- this._isBrowser = browserOrNode().isBrowser;
17
- this._timerKey = uuid().substr(0, 15);
18
- this._refreshTimer();
19
- }
20
- SessionInfoManager.prototype._refreshTimer = function () {
21
- if (this._timer) {
22
- clearInterval(this._timer);
23
- }
24
- var that = this;
25
- this._timer = setInterval(function () {
26
- that._timerKey = uuid().substr(0, 15);
27
- }, TIMER_INTERVAL);
28
- };
29
- SessionInfoManager.prototype.storeValue = function (key, value) {
30
- var today = new Date();
31
- var expire = new Date();
32
- expire.setTime(today.getTime() + 3600000 * 24 * CACHE_EXPIRY_IN_DAYS);
33
- Cache.setItem(this._getCachePrefix(key), value, {
34
- expires: expire.getTime(),
35
- });
36
- };
37
- SessionInfoManager.prototype.retrieveValue = function (key) {
38
- return Cache.getItem(this._getCachePrefix(key));
39
- };
40
- SessionInfoManager.prototype._getCachePrefix = function (key) {
41
- if (this._isBrowser) {
42
- return key + DELIMITER + window.location.host;
43
- }
44
- return DEFAULT_CACHE_PREFIX;
45
- };
46
- SessionInfoManager.prototype.getTimerKey = function () {
47
- return this._timerKey;
48
- };
49
- SessionInfoManager.prototype.updateSessionInfo = function (userId, sessionInfo) {
50
- var existUserId = sessionInfo.userId;
51
- var existSessionId = sessionInfo.sessionId;
52
- if (this._isRequireNewSession(userId, existUserId, existSessionId)) {
53
- var newSessionId = uuid();
54
- this.storeValue(PERSONALIZE_CACHE_USERID, userId);
55
- this.storeValue(PERSONALIZE_CACHE_SESSIONID, newSessionId);
56
- sessionInfo.sessionId = newSessionId;
57
- }
58
- else if (this._isRequireUpdateSessionInfo(userId, existUserId, existSessionId)) {
59
- this.storeValue(PERSONALIZE_CACHE_USERID, userId);
60
- }
61
- sessionInfo.userId = userId;
62
- };
63
- SessionInfoManager.prototype._isRequireUpdateSessionInfo = function (userId, cachedSessionUserId, cachedSessionSessionId) {
64
- // anonymouse => sign in : hasSession && s_userId == null && curr_userId !=null
65
- var isNoCachedSession = isEmpty(cachedSessionSessionId);
66
- return (!isNoCachedSession && isEmpty(cachedSessionUserId) && !isEmpty(userId));
67
- };
68
- SessionInfoManager.prototype.retrieveSessionInfo = function (trackingId) {
69
- var sessionInfo = {};
70
- sessionInfo.trackingId = trackingId;
71
- sessionInfo.sessionId = this.retrieveValue(PERSONALIZE_CACHE_SESSIONID);
72
- sessionInfo.userId = this.retrieveValue(PERSONALIZE_CACHE_USERID);
73
- if (isEmpty(sessionInfo.sessionId)) {
74
- sessionInfo.sessionId = uuid();
75
- this.storeValue(PERSONALIZE_CACHE_SESSIONID, sessionInfo.sessionId);
76
- }
77
- this.storeValue(PERSONALIZE_CACHE, trackingId);
78
- return sessionInfo;
79
- };
80
- SessionInfoManager.prototype._isRequireNewSession = function (userId, cachedSessionUserId, cachedSessionSessionId) {
81
- // new session => 1. no cached session info 2. signOut: s_userId !=null && curr_userId ==null
82
- // 3. switch account: s_userId !=null && curr_userId !=null && s_userId != curr_userId
83
- var isNoCachedSession = isEmpty(cachedSessionSessionId);
84
- var isSignoutCase = isEmpty(userId) && !isEmpty(cachedSessionUserId);
85
- var isSwitchUserCase = !isEmpty(userId) &&
86
- !isEmpty(cachedSessionUserId) &&
87
- !isEqual(userId, cachedSessionUserId);
88
- return isNoCachedSession || isSignoutCase || isSwitchUserCase;
89
- };
90
- return SessionInfoManager;
91
- }());
92
- export { SessionInfoManager };
@@ -1,3 +0,0 @@
1
- export { EventData, RecordEventListPayload, RecordEventPayload, RequestParams, SessionInfo, } from './DataType';
2
- export { SessionInfoManager } from './SessionInfoManager';
3
- export { MediaAutoTrack } from './MediaAutoTrack';
@@ -1,2 +0,0 @@
1
- export { SessionInfoManager } from './SessionInfoManager';
2
- export { MediaAutoTrack } from './MediaAutoTrack';
@@ -1,76 +0,0 @@
1
- import { AnalyticsProvider } from '../types';
2
- export declare class AmazonPersonalizeProvider implements AnalyticsProvider {
3
- private _config;
4
- private _personalize;
5
- private _buffer;
6
- private _timer;
7
- private _sessionInfo;
8
- private _sessionManager;
9
- private _isBrowser;
10
- constructor(config?: any);
11
- private _setupTimer;
12
- /**
13
- * Record event
14
- * @param eventType - type of the event action. e.g. "Click"
15
- * @param properties - properties of the event
16
- * @return Promise
17
- */
18
- record(params: any): Promise<boolean>;
19
- private loadElement;
20
- private isElementFullyLoaded;
21
- /**
22
- * get the category of the plugin
23
- */
24
- getCategory(): string;
25
- /**
26
- * get provider name of the plugin
27
- */
28
- getProviderName(): string;
29
- /**
30
- * configure the plugin
31
- * @param {Object} config - configuration
32
- */
33
- configure(config: any): object;
34
- /**
35
- * Generate the requestParams from customer input params and sessionInfo
36
- * @private
37
- * @param eventData - customer input for event data
38
- * @param api - api name
39
- * @return RequestParams - wrapper object with all information required for make request
40
- */
41
- private generateRequestParams;
42
- /**
43
- * record an event
44
- * @param {Object} params - the params of an event
45
- */
46
- private _sendEvents;
47
- /**
48
- * Put event into buffer
49
- * @private
50
- * @param params - params for the event recording
51
- */
52
- private putToBuffer;
53
- /**
54
- * flush the buffer and batch sending the request
55
- * @private
56
- * @param eventsParams - the buffer for cache the payload
57
- */
58
- private _sendFromBuffer;
59
- /**
60
- * Generate the record payload for single event
61
- * @private
62
- * @param params - RequestParams
63
- */
64
- private _generateSingleRecordPayload;
65
- /**
66
- * Initialize the personalize client
67
- * @private
68
- * @param params - RequestParams
69
- */
70
- private _init;
71
- /**
72
- * check if current credentials exists
73
- * @private
74
- */
75
- private _getCredentials;
76
- }
@@ -1,328 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { __awaiter, __generator } from "tslib";
4
- import { ConsoleLogger as Logger, Credentials, browserOrNode, AnalyticsAction, } from '@aws-amplify/core';
5
- import { PersonalizeEventsClient, PutEventsCommand, } from '@aws-sdk/client-personalize-events';
6
- import { SessionInfoManager, MediaAutoTrack, } from './AmazonPersonalizeHelper';
7
- import get from 'lodash/get';
8
- import isEmpty from 'lodash/isEmpty';
9
- import isEqual from 'lodash/isEqual';
10
- import { getAnalyticsUserAgent } from '../utils/UserAgent';
11
- var logger = new Logger('AmazonPersonalizeProvider');
12
- // events buffer
13
- var FLUSH_SIZE = 5;
14
- var FLUSH_SIZE_THRESHHOLD = 10;
15
- var FLUSH_INTERVAL = 5 * 1000; // 5s
16
- var IDENTIFY_EVENT = 'Identify';
17
- var AmazonPersonalizeProvider = /** @class */ (function () {
18
- function AmazonPersonalizeProvider(config) {
19
- this._buffer = [];
20
- this._config = config ? config : {};
21
- this._config.flushSize =
22
- this._config.flushSize > 0 &&
23
- this._config.flushSize <= FLUSH_SIZE_THRESHHOLD
24
- ? this._config.flushSize
25
- : FLUSH_SIZE;
26
- this._config.flushInterval = this._config.flushInterval || FLUSH_INTERVAL;
27
- this._sessionManager = new SessionInfoManager();
28
- if (!isEmpty(this._config.trackingId)) {
29
- this._sessionInfo = this._sessionManager.retrieveSessionInfo(this._config.trackingId);
30
- }
31
- this._isBrowser = browserOrNode().isBrowser;
32
- // flush event buffer
33
- this._setupTimer();
34
- }
35
- AmazonPersonalizeProvider.prototype._setupTimer = function () {
36
- if (this._timer) {
37
- clearInterval(this._timer);
38
- }
39
- var flushInterval = this._config.flushInterval;
40
- var that = this;
41
- this._timer = setInterval(function () {
42
- that._sendFromBuffer();
43
- }, flushInterval);
44
- };
45
- /**
46
- * Record event
47
- * @param eventType - type of the event action. e.g. "Click"
48
- * @param properties - properties of the event
49
- * @return Promise
50
- */
51
- AmazonPersonalizeProvider.prototype.record = function (params) {
52
- return __awaiter(this, void 0, void 0, function () {
53
- var credentials, _a, eventType, properties, requestParams, isLoaded;
54
- return __generator(this, function (_b) {
55
- switch (_b.label) {
56
- case 0: return [4 /*yield*/, this._getCredentials()];
57
- case 1:
58
- credentials = _b.sent();
59
- if (!credentials)
60
- return [2 /*return*/, Promise.resolve(false)];
61
- Object.assign(params, {
62
- config: this._config,
63
- credentials: credentials,
64
- sentAt: new Date(),
65
- });
66
- _a = params.event, eventType = _a.eventType, properties = _a.properties;
67
- if (eventType === IDENTIFY_EVENT) {
68
- this._sessionManager.updateSessionInfo(properties && properties.userId ? properties.userId : '', this._sessionInfo);
69
- return [2 /*return*/];
70
- }
71
- else if (!isEmpty(params.event.userId)) {
72
- this._sessionManager.updateSessionInfo(params.event.userId, this._sessionInfo);
73
- }
74
- requestParams = this.generateRequestParams(params, this._sessionInfo);
75
- if (!(eventType === 'MediaAutoTrack')) return [3 /*break*/, 7];
76
- if (!this._isBrowser) return [3 /*break*/, 5];
77
- if (!!isEmpty(get(requestParams, 'eventData.properties.domElementId', null))) return [3 /*break*/, 3];
78
- return [4 /*yield*/, this.isElementFullyLoaded(this.loadElement, requestParams.eventData.properties['domElementId'], 500, 5)];
79
- case 2:
80
- isLoaded = _b.sent();
81
- if (isLoaded) {
82
- new MediaAutoTrack(requestParams, this);
83
- }
84
- else {
85
- logger.debug('Cannot find the media element.');
86
- }
87
- return [3 /*break*/, 4];
88
- case 3:
89
- logger.debug("Missing domElementId field in 'properties' for MediaAutoTrack event type.");
90
- _b.label = 4;
91
- case 4: return [3 /*break*/, 6];
92
- case 5:
93
- logger.debug('MediaAutoTrack only for browser');
94
- _b.label = 6;
95
- case 6: return [2 /*return*/];
96
- case 7: return [2 /*return*/, this.putToBuffer(requestParams)];
97
- }
98
- });
99
- });
100
- };
101
- AmazonPersonalizeProvider.prototype.loadElement = function (domId) {
102
- return new Promise(function (resolve, reject) {
103
- if (document.getElementById(domId) &&
104
- document.getElementById(domId).clientHeight) {
105
- return resolve(true);
106
- }
107
- else {
108
- return reject(true);
109
- }
110
- });
111
- };
112
- AmazonPersonalizeProvider.prototype.isElementFullyLoaded = function (operation, params, delay, times) {
113
- var _this = this;
114
- var wait = function (ms) { return new Promise(function (r) { return setTimeout(r, ms); }); };
115
- return new Promise(function (resolve, reject) {
116
- return operation(params)
117
- .then(resolve)
118
- .catch(function (reason) {
119
- if (times - 1 > 0) {
120
- return wait(delay)
121
- .then(_this.isElementFullyLoaded.bind(null, operation, params, delay, times - 1))
122
- .then(resolve)
123
- .catch(reject);
124
- }
125
- return reject(reason);
126
- });
127
- });
128
- };
129
- /**
130
- * get the category of the plugin
131
- */
132
- AmazonPersonalizeProvider.prototype.getCategory = function () {
133
- return 'Analytics';
134
- };
135
- /**
136
- * get provider name of the plugin
137
- */
138
- AmazonPersonalizeProvider.prototype.getProviderName = function () {
139
- return 'AmazonPersonalize';
140
- };
141
- /**
142
- * configure the plugin
143
- * @param {Object} config - configuration
144
- */
145
- AmazonPersonalizeProvider.prototype.configure = function (config) {
146
- logger.debug('configure Analytics', config);
147
- var conf = config ? config : {};
148
- this._config = Object.assign({}, this._config, conf);
149
- if (!isEmpty(this._config.trackingId)) {
150
- this._sessionInfo = this._sessionManager.retrieveSessionInfo(this._config.trackingId);
151
- }
152
- this._setupTimer();
153
- return this._config;
154
- };
155
- /**
156
- * Generate the requestParams from customer input params and sessionInfo
157
- * @private
158
- * @param eventData - customer input for event data
159
- * @param api - api name
160
- * @return RequestParams - wrapper object with all information required for make request
161
- */
162
- AmazonPersonalizeProvider.prototype.generateRequestParams = function (params, sessionInfo) {
163
- var requestParams = {};
164
- var _a = params.event, eventType = _a.eventType, properties = _a.properties;
165
- requestParams.eventData = { eventType: eventType, properties: properties };
166
- requestParams.sessionInfo = sessionInfo;
167
- requestParams.sentAt = params.sentAt;
168
- requestParams.credentials = params.credentials;
169
- requestParams.config = params.config;
170
- return requestParams;
171
- };
172
- /**
173
- * record an event
174
- * @param {Object} params - the params of an event
175
- */
176
- AmazonPersonalizeProvider.prototype._sendEvents = function (group) {
177
- var groupLen = group.length;
178
- if (groupLen === 0) {
179
- logger.debug('events array is empty, directly return');
180
- return;
181
- }
182
- var _a = group[0], config = _a.config, credentials = _a.credentials, sessionInfo = _a.sessionInfo;
183
- var initClients = this._init(config, credentials);
184
- if (!initClients)
185
- return false;
186
- if (groupLen > 0) {
187
- var events = [];
188
- for (var i = 0; i < groupLen; i += 1) {
189
- var params = group.shift();
190
- var eventPayload = this._generateSingleRecordPayload(params, sessionInfo);
191
- events.push(eventPayload);
192
- }
193
- var payload_1 = {};
194
- payload_1.trackingId = sessionInfo.trackingId;
195
- payload_1.sessionId = sessionInfo.sessionId;
196
- payload_1.userId = sessionInfo.userId;
197
- payload_1.eventList = [];
198
- events.forEach(function (event) {
199
- // @ts-ignore
200
- payload_1.eventList.push(event);
201
- });
202
- var command = new PutEventsCommand(payload_1);
203
- this._personalize.send(command, function (err) {
204
- if (err)
205
- logger.debug('Failed to call putEvents in Personalize', err);
206
- else
207
- logger.debug('Put events');
208
- });
209
- }
210
- };
211
- /**
212
- * Put event into buffer
213
- * @private
214
- * @param params - params for the event recording
215
- */
216
- AmazonPersonalizeProvider.prototype.putToBuffer = function (params) {
217
- if (this._buffer.length < this._config.flushSize) {
218
- this._buffer.push(params);
219
- }
220
- else {
221
- this._buffer.push(params);
222
- this._sendFromBuffer();
223
- }
224
- return Promise.resolve(true);
225
- };
226
- /**
227
- * flush the buffer and batch sending the request
228
- * @private
229
- * @param eventsParams - the buffer for cache the payload
230
- */
231
- AmazonPersonalizeProvider.prototype._sendFromBuffer = function () {
232
- var _this = this;
233
- var size = this._buffer.length;
234
- if (size <= 0)
235
- return;
236
- var eventsGroups = [];
237
- var preCred = null;
238
- var group = [];
239
- for (var i = 0; i < size; i += 1) {
240
- var currRequestParams = this._buffer.shift();
241
- var cred = currRequestParams.credentials;
242
- var sessionInfo = currRequestParams.sessionInfo;
243
- if (i === 0) {
244
- group.push(currRequestParams);
245
- preCred = cred;
246
- }
247
- else {
248
- if (isEqual(sessionInfo, this._sessionInfo) &&
249
- cred.sessionToken === preCred.sessionToken &&
250
- cred.identityId === preCred.identityId) {
251
- logger.debug('no change for cred, put event in the same group');
252
- group.push(currRequestParams);
253
- }
254
- else {
255
- eventsGroups.push(group);
256
- group = [];
257
- group.push(currRequestParams);
258
- preCred = cred;
259
- this._sessionInfo = sessionInfo;
260
- }
261
- }
262
- }
263
- eventsGroups.push(group);
264
- eventsGroups.map(function (group) {
265
- _this._sendEvents(group);
266
- });
267
- };
268
- /**
269
- * Generate the record payload for single event
270
- * @private
271
- * @param params - RequestParams
272
- */
273
- AmazonPersonalizeProvider.prototype._generateSingleRecordPayload = function (params, sessionInfo) {
274
- var eventData = params.eventData, sentAt = params.sentAt;
275
- var trackPayload = {};
276
- trackPayload.sentAt = sentAt;
277
- trackPayload.properties =
278
- eventData.properties && JSON.stringify(eventData.properties);
279
- trackPayload.eventId =
280
- this._sessionManager.getTimerKey() + sessionInfo.sessionId;
281
- trackPayload.eventType = eventData.eventType;
282
- return trackPayload;
283
- };
284
- /**
285
- * Initialize the personalize client
286
- * @private
287
- * @param params - RequestParams
288
- */
289
- AmazonPersonalizeProvider.prototype._init = function (config, credentials) {
290
- logger.debug('init clients');
291
- if (this._personalize &&
292
- this._config.credentials &&
293
- this._config.credentials.sessionToken === credentials.sessionToken &&
294
- this._config.credentials.identityId === credentials.identityId) {
295
- logger.debug('no change for analytics config, directly return from init');
296
- return true;
297
- }
298
- this._config.credentials = credentials;
299
- var region = config.region;
300
- logger.debug('initialize personalize with credentials', credentials);
301
- this._personalize = new PersonalizeEventsClient({
302
- region: region,
303
- credentials: credentials,
304
- customUserAgent: getAnalyticsUserAgent(AnalyticsAction.Record),
305
- });
306
- return true;
307
- };
308
- /**
309
- * check if current credentials exists
310
- * @private
311
- */
312
- AmazonPersonalizeProvider.prototype._getCredentials = function () {
313
- var that = this;
314
- return Credentials.get()
315
- .then(function (credentials) {
316
- if (!credentials)
317
- return null;
318
- logger.debug('set credentials for analytics', that._config.credentials);
319
- return Credentials.shear(credentials);
320
- })
321
- .catch(function (err) {
322
- logger.debug('ensure credentials error', err);
323
- return null;
324
- });
325
- };
326
- return AmazonPersonalizeProvider;
327
- }());
328
- export { AmazonPersonalizeProvider };