@crimson-education/browser-logger 2.0.2-cognito.1 → 2.0.2

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 (57) hide show
  1. package/README.md +137 -4
  2. package/lib/index.d.ts +69 -13
  3. package/lib/index.d.ts.map +1 -1
  4. package/lib/index.js +130 -57
  5. package/lib/index.js.map +1 -1
  6. package/lib/reporters/amplifyReporter.d.ts +40 -14
  7. package/lib/reporters/amplifyReporter.d.ts.map +1 -1
  8. package/lib/reporters/amplifyReporter.js +4 -11
  9. package/lib/reporters/amplifyReporter.js.map +1 -1
  10. package/lib/reporters/amplifyReporter.test.js +0 -11
  11. package/lib/reporters/amplifyReporter.test.js.map +1 -1
  12. package/lib/reporters/datadogReporter.d.ts +58 -10
  13. package/lib/reporters/datadogReporter.d.ts.map +1 -1
  14. package/lib/reporters/datadogReporter.js +26 -18
  15. package/lib/reporters/datadogReporter.js.map +1 -1
  16. package/lib/reporters/gtmReporter.d.ts +3 -2
  17. package/lib/reporters/gtmReporter.d.ts.map +1 -1
  18. package/lib/reporters/gtmReporter.js +24 -5
  19. package/lib/reporters/gtmReporter.js.map +1 -1
  20. package/lib/reporters/index.d.ts +3 -28
  21. package/lib/reporters/index.d.ts.map +1 -1
  22. package/lib/reporters/index.js +17 -0
  23. package/lib/reporters/index.js.map +1 -1
  24. package/lib/types/index.d.ts +3 -0
  25. package/lib/types/index.d.ts.map +1 -0
  26. package/lib/types/index.js +19 -0
  27. package/lib/types/index.js.map +1 -0
  28. package/lib/{types.d.ts → types/logger.d.ts} +4 -15
  29. package/lib/types/logger.d.ts.map +1 -0
  30. package/lib/{types.js → types/logger.js} +1 -1
  31. package/lib/types/logger.js.map +1 -0
  32. package/lib/types/reporter.d.ts +103 -0
  33. package/lib/types/reporter.d.ts.map +1 -0
  34. package/lib/types/reporter.js +3 -0
  35. package/lib/types/reporter.js.map +1 -0
  36. package/lib/utils.d.ts +5 -1
  37. package/lib/utils.d.ts.map +1 -1
  38. package/lib/utils.js +8 -3
  39. package/lib/utils.js.map +1 -1
  40. package/lib/utils.test.d.ts +2 -0
  41. package/lib/utils.test.d.ts.map +1 -0
  42. package/lib/utils.test.js +19 -0
  43. package/lib/utils.test.js.map +1 -0
  44. package/package.json +9 -6
  45. package/src/index.ts +148 -57
  46. package/src/reporters/amplifyReporter.test.ts +1 -14
  47. package/src/reporters/amplifyReporter.ts +53 -23
  48. package/src/reporters/datadogReporter.ts +93 -17
  49. package/src/reporters/gtmReporter.ts +39 -7
  50. package/src/reporters/index.ts +3 -32
  51. package/src/types/index.ts +2 -0
  52. package/src/{types.ts → types/logger.ts} +3 -13
  53. package/src/types/reporter.ts +107 -0
  54. package/src/utils.test.ts +18 -0
  55. package/src/utils.ts +16 -1
  56. package/lib/types.d.ts.map +0 -1
  57. package/lib/types.js.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Crimson Education Browser Logger
2
2
 
3
- An abstract logger and reporting utility for browser environments
3
+ An abstract logger and reporting utility for browser environments.
4
+
5
+ This library contains a number of reporters that is will send analytics to.
6
+
7
+ These must be enabled by calling `Logger.init()`, as seen below.
4
8
 
5
9
  ## Install
6
10
 
@@ -16,15 +20,19 @@ yarn add @crimson-education/browser-logger
16
20
 
17
21
  ## Usage
18
22
 
19
- ### Initialise
23
+ ### Initialize
20
24
 
21
25
  ```ts
22
26
  import * as Logger from '@crimson-education/browser-logger';
27
+ import { config } from '../configuration';
23
28
 
24
29
  Logger.init({
25
- service: 'browser-project',
30
+ service: 'test-project',
26
31
  environment: config.environment,
27
32
  version: config.version,
33
+ defaultMetadata: {
34
+ application: 'test',
35
+ },
28
36
 
29
37
  datadog: {
30
38
  applicationId: config.datadogApplicationId,
@@ -32,16 +40,24 @@ Logger.init({
32
40
  site: config.datadogSite,
33
41
  proxyUrl: config.datadogTunnelProxyUrl,
34
42
  version: config.datadogVersion,
43
+
44
+ sampleRate: config.environment === 'production' ? 50 : 0,
45
+ replaySampleRate: config.environment === 'production' ? 50 : 0,
46
+
35
47
  forwardConsoleLogs: true,
36
48
  trackInteractions: true,
49
+ trackFrustrations: true,
50
+ allowedTracingOrigins: ['https://my.api.domain']
37
51
  },
38
52
 
39
53
  amplify: {
40
54
  region: config.awsRegion,
41
55
  identityPoolId: config.pinpointIdentityPoolId,
42
56
  analyticsAppId: config.pinpointAnalyticsAppId,
43
- autoTrackPageViews: true,
57
+
44
58
  autoTrackEvents: true,
59
+ autoTrackPageViews: true,
60
+ autoTrackSessions: true,
45
61
  }
46
62
  });
47
63
 
@@ -70,6 +86,123 @@ logger.info('WOW!', {
70
86
  });
71
87
  ```
72
88
 
89
+ ### Reporters
90
+
91
+ #### Datadog
92
+
93
+ To configure Datadog, this requires at least `applicationId`, `clientToken` and `site` (As we use an EU instance).
94
+
95
+ ```ts
96
+ import { config } from '../configuration';
97
+ import * as Logger from '@crimson-education/browser-logger';
98
+
99
+ Logger.init({
100
+ ...
101
+ datadog: {
102
+ applicationId: config.datadogApplicationId,
103
+ clientToken: config.datadogClientToken,
104
+ site: config.datadogSite,
105
+ proxyUrl: config.datadogTunnelProxyUrl,
106
+ version: config.datadogVersion,
107
+
108
+ sampleRate: config.environment === 'production' ? 50 : 0,
109
+ replaySampleRate: config.environment === 'production' ? 50 : 0,
110
+
111
+ forwardConsoleLogs: true,
112
+ trackInteractions: true,
113
+ allowedTracingOrigins: ['https://my.api.domain']
114
+ }
115
+ });
116
+ ```
117
+
118
+ Check out the [`DatadogReporterConfig`](https://github.com/crimson-education/browser-logger/blob/main/src/reporters/datadogReporter.ts) for all of the configuration you can apply to Datadog reporting.
119
+
120
+ #### Amplify/Pinpoint
121
+
122
+ To configure Amplify, this requires at least `region`, `identityPoolId` and `analyticsAppId`.
123
+
124
+ > **Note**: If you are setting up Browser Logger in a project that uses AWS Cognito or other AWS Amplify Features, you will want to set `identityPoolId` to false. This disables the reporter's call to Auth.configure, as you will have used that to configure your App already.
125
+ >
126
+ > You will need to set identityPoolId in your Auth.configure function yourself, otherwise Pinpoint won't work.
127
+
128
+ Auto `Auth.configure`:
129
+ ```ts
130
+ import { config } from '../configuration';
131
+ import * as Logger from '@crimson-education/browser-logger';
132
+
133
+ Logger.init({
134
+ ...
135
+ amplify: {
136
+ region: config.amplifyAwsRegion,
137
+ analyticsAppId: config.pinpointAnalyticsAppId,
138
+ identityPoolId: config.amplifyIdentityPoolId,
139
+
140
+ autoTrackEvents: true,
141
+ autoTrackPageViews: true,
142
+ autoTrackSessions: true,
143
+ }
144
+ });
145
+ ```
146
+
147
+ Manual `Auth.configure`:
148
+ ```ts
149
+ import { Auth } from '@aws-amplify/auth';
150
+ import { config } from '../configuration';
151
+ import * as Logger from '@crimson-education/browser-logger';
152
+
153
+ Auth.configure({
154
+ region: config.cognitoRegion,
155
+ userPoolId: config.cognitoUserPoolId,
156
+ userPoolWebClientId: config.cognitoClientId,
157
+ identityPoolId: config.amplifyIdentityPoolId,
158
+ });
159
+
160
+ Logger.init({
161
+ ...
162
+ amplify: {
163
+ region: config.amplifyAwsRegion,
164
+ analyticsAppId: config.pinpointAnalyticsAppId,
165
+ identityPoolId: false,
166
+
167
+ autoTrackEvents: true,
168
+ autoTrackPageViews: true,
169
+ autoTrackSessions: true,
170
+ }
171
+ });
172
+ ```
173
+
174
+ Check out the [`AmplifyReporterConfig`](https://github.com/crimson-education/browser-logger/blob/main/src/reporters/amplifyReporter.ts) for all of the configuration you can apply to Amplify reporting.
175
+
176
+ #### Google Tag Manager
177
+
178
+ To configure GTM, you will need to have loaded the GTM script into your App.
179
+ See: https://support.google.com/tagmanager/answer/6103696?hl=en
180
+
181
+ ```ts
182
+ import { config } from '../configuration';
183
+ import * as Logger from '@crimson-education/browser-logger';
184
+
185
+ // No configuration
186
+ Logger.init({
187
+ ...
188
+ gtm: true,
189
+ });
190
+
191
+ // With configuration
192
+ Logger.init({
193
+ ...
194
+ gtm: {
195
+ ignoreBreadcrumbCategories: ['fetch']
196
+ },
197
+ });
198
+ ```
199
+
200
+ Check out the [`GTMReporterConfig`](https://github.com/crimson-education/browser-logger/blob/main/src/reporters/gtmReporter.ts) for all of the configuration you can apply to Google Tag Manager reporting.
201
+
202
+ ### Functions
203
+
204
+ See the [src/index.ts](./src/index.ts) file for all exported functions of the Logger.
205
+
73
206
  ### Improve Session Tracking with Component names
74
207
 
75
208
  You can improve the name of components in analytics tools like Datadog and Amplify use, instead of the content of a component.
package/lib/index.d.ts CHANGED
@@ -1,26 +1,82 @@
1
- import { ILogger, Metadata, ReportError, ReportUser, ServiceInfo } from './types';
2
- import { ReporterBreadcrumb, ReporterEvent, TrackedReporterEvent } from './reporters';
3
- import { DatadogReporterConfig } from './reporters/datadogReporter';
4
- import { AmplifyReporterConfig } from './reporters/amplifyReporter';
1
+ import { ILogger, Metadata, ReporterBreadcrumb, ReporterEvent, ReporterFilters, ReportError, ReportUser, ServiceInfo, TrackedReporterEvent } from './types';
2
+ import { DatadogReporterConfig, GTMReporterConfig, AmplifyReporterConfig } from './reporters';
5
3
  export * from './types';
6
4
  export declare let logger: ILogger | null;
5
+ export declare type ReporterType = 'datadog' | 'gtm' | 'amplify';
7
6
  export declare type ReporterConfig = ServiceInfo & {
8
7
  datadog?: DatadogReporterConfig;
9
8
  amplify?: AmplifyReporterConfig;
10
- gtm?: boolean;
9
+ gtm?: true | GTMReporterConfig;
11
10
  };
11
+ /**
12
+ * Initializes the logger and reporters.
13
+ * @param config Reporter config options.
14
+ */
12
15
  export declare function init(config: ReporterConfig): void;
16
+ /**
17
+ * Tracks an Analytics event.
18
+ */
13
19
  export declare function trackEvent(event: ReporterEvent): void;
14
- export declare function addBreadcrumb(breadcrumb: ReporterBreadcrumb): void;
15
- export declare function addMetadata(metadata: Metadata): void;
16
- export declare function setUser(user: ReportUser | null): void;
17
- export declare function setRouteName(routeName: string): void;
18
- export declare function setPageName(pageName: string): void;
19
- export declare function reportError(error: ReportError, metadata?: Metadata): void;
20
- export declare function recordSession(): void;
21
- export declare function recordSessionStop(): void;
20
+ /**
21
+ * Tracks an Analytics event, recording the time since the last event, if available.
22
+ */
22
23
  export declare function trackEventSinceLastAction(event: ReporterEvent): void;
24
+ /**
25
+ * Gets the last tracked event, if available.
26
+ */
23
27
  export declare function getLastTrackedEvent(): TrackedReporterEvent | null;
28
+ /**
29
+ * Breadcrumbs to create a trail of events that happened prior to an issue.
30
+ * These events are very similar to traditional logs, but can record more rich structured data.
31
+ */
32
+ export declare function addBreadcrumb(breadcrumb: ReporterBreadcrumb): void;
33
+ /**
34
+ * Adds global metadata to all events.
35
+ * @param metadata Metadata to add.
36
+ * @param filters Optional filters to specify which reporters to add metadata to.
37
+ */
38
+ export declare function addMetadata(metadata: Metadata, filters?: ReporterFilters): void;
39
+ /**
40
+ * Sets the user information in Analytics.
41
+ * @param user User information, or null to clear.
42
+ * @param filters Optional filters to specify which reporters to set the user for.
43
+ */
44
+ export declare function setUser(user: ReportUser | null, filters?: ReporterFilters): void;
45
+ /**
46
+ * Sets the route name in Analytics.
47
+ * Some Analytics services use this differentiate SPA Route vs Page changes.
48
+ * @param routeName Name of the Route.
49
+ * @param filters Optional filters to specify which reporters to set the route name for.
50
+ */
51
+ export declare function setRouteName(routeName: string, filters?: ReporterFilters): void;
52
+ /**
53
+ * Sets the page name in Analytics.
54
+ * @param pageName Name of the Page.
55
+ * @param filters Optional filters to specify which reporters to set the page name for.
56
+ */
57
+ export declare function setPageName(pageName: string, filters?: ReporterFilters): void;
58
+ /**
59
+ * Reports an Error in Reporters that support error tracking.
60
+ * @param error Error data.
61
+ * @param metadata Metadata to add to the error.
62
+ * @param filters Optional filters to specify which reporters to report the error to.
63
+ */
64
+ export declare function reportError(error: ReportError, metadata?: Metadata, filters?: ReporterFilters): void;
65
+ /**
66
+ * Starts a session recording in Analytics, e.g. RUM Session Replay
67
+ * @param filters Optional filters to specify which reporters to start a session recording for.
68
+ */
69
+ export declare function recordSession(filters?: ReporterFilters): void;
70
+ /**
71
+ * Stops a session recording in Analytics, e.g. RUM Session Replay
72
+ * @param filters Optional filters to specify which reporters to stop a session recording for.
73
+ */
74
+ export declare function recordSessionStop(filters?: ReporterFilters): void;
75
+ /**
76
+ * Creates a Logger instance.
77
+ * @param name Name of the Logger.
78
+ * @param options Logger configuration options.
79
+ */
24
80
  export declare function createLogger(name?: string, options?: {
25
81
  metadata?: Metadata;
26
82
  }): ILogger;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAa,kBAAkB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEjG,OAAO,EAAkC,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpG,OAAO,EAAmB,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAErF,cAAc,SAAS,CAAC;AAExB,eAAO,IAAI,MAAM,EAAE,OAAO,GAAG,IAAW,CAAC;AAEzC,oBAAY,cAAc,GAAG,WAAW,GAAG;IAEzC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAGhC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAGhC,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAMF,wBAAgB,IAAI,CAAC,MAAM,EAAE,cAAc,QAuB1C;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAIrD;AAED,wBAAgB,aAAa,CAAC,UAAU,EAAE,kBAAkB,GAAG,IAAI,CAIlE;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAIpD;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,IAAI,CAIrD;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAIpD;AAED,wBAAgB,WAAW,CAAC,QAAQ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EG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAgBpE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,oBAAoB,GAAG,IAAI,CAOjE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,kBAAkB,GAAG,IAAI,CAIlE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAI/E;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAIhF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAI/E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAI7E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAIpG;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAI7D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAIjE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAE,GAAG,OAAO,CAUtF"}
package/lib/index.js CHANGED
@@ -14,124 +14,197 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createLogger = exports.getLastTrackedEvent = exports.trackEventSinceLastAction = exports.recordSessionStop = exports.recordSession = exports.reportError = exports.setPageName = exports.setRouteName = exports.setUser = exports.addMetadata = exports.addBreadcrumb = exports.trackEvent = exports.init = exports.logger = void 0;
17
+ exports.createLogger = exports.recordSessionStop = exports.recordSession = exports.reportError = exports.setPageName = exports.setRouteName = exports.setUser = exports.addMetadata = exports.addBreadcrumb = exports.getLastTrackedEvent = exports.trackEventSinceLastAction = exports.trackEvent = exports.init = exports.logger = void 0;
18
18
  const utils_1 = require("./utils");
19
- const datadogReporter_1 = require("./reporters/datadogReporter");
20
- const gtmReporter_1 = require("./reporters/gtmReporter");
21
- const amplifyReporter_1 = require("./reporters/amplifyReporter");
19
+ const reporters_1 = require("./reporters");
22
20
  __exportStar(require("./types"), exports);
23
21
  exports.logger = null;
24
- const reporters = [];
22
+ const reporters = {};
25
23
  let initialized = false;
26
24
  let ddInitialized = false;
25
+ /**
26
+ * Initializes the logger and reporters.
27
+ * @param config Reporter config options.
28
+ */
27
29
  function init(config) {
28
30
  initialized = true;
29
31
  if (config.datadog) {
30
- reporters.push((0, datadogReporter_1.datadogReporter)(config, config.datadog));
32
+ reporters['datadog'] = (0, reporters_1.datadogReporter)(config, config.datadog);
31
33
  ddInitialized = true;
32
34
  }
33
35
  if (config.amplify) {
34
- reporters.push((0, amplifyReporter_1.amplifyReporter)(config, config.amplify));
36
+ reporters['amplify'] = (0, reporters_1.amplifyReporter)(config, config.amplify);
35
37
  }
36
38
  if (config.gtm) {
37
- reporters.push((0, gtmReporter_1.gtmReporter)());
39
+ reporters['gtm'] = (0, reporters_1.gtmReporter)(config, typeof config.gtm === 'boolean' ? {} : config.gtm);
38
40
  }
39
41
  if (config.defaultMetadata) {
40
- for (const reporter of reporters) {
42
+ for (const reporter of Object.values(reporters)) {
41
43
  reporter.addMetadata(config.defaultMetadata);
42
44
  }
43
45
  }
44
46
  exports.logger = createLogger('Reporter');
45
47
  }
46
48
  exports.init = init;
49
+ /**
50
+ * Gets reporters, optionally with filters.
51
+ * @param filters Filters to remove or specify specific reporters.
52
+ * @returns Selected reporters, or all registered reporters.
53
+ */
54
+ function getReporters(filters) {
55
+ let result = Object.entries(reporters);
56
+ if (filters === null || filters === void 0 ? void 0 : filters.excludeReporters) {
57
+ result = result.filter(([key]) => { var _a; return !((_a = filters === null || filters === void 0 ? void 0 : filters.excludeReporters) === null || _a === void 0 ? void 0 : _a.includes(key)); });
58
+ }
59
+ if (filters === null || filters === void 0 ? void 0 : filters.toReporters) {
60
+ result = result.filter(([key]) => { var _a; return (_a = filters === null || filters === void 0 ? void 0 : filters.toReporters) === null || _a === void 0 ? void 0 : _a.includes(key); });
61
+ }
62
+ return result.map(([, reporter]) => reporter);
63
+ }
64
+ /**
65
+ * Tracks an Analytics event.
66
+ */
47
67
  function trackEvent(event) {
48
- for (const reporter of reporters) {
68
+ for (const reporter of getReporters(event)) {
49
69
  reporter.trackEvent(event);
50
70
  }
51
71
  }
52
72
  exports.trackEvent = trackEvent;
73
+ /**
74
+ * Tracks an Analytics event, recording the time since the last event, if available.
75
+ */
76
+ function trackEventSinceLastAction(event) {
77
+ const lastEvent = getLastTrackedEvent();
78
+ if (lastEvent) {
79
+ const duration = new Date().getTime() - lastEvent.occurred.getTime();
80
+ trackEvent({
81
+ ...event,
82
+ metadata: {
83
+ ...event.metadata,
84
+ lastEventName: lastEvent.message,
85
+ timeSinceLastEvent: duration,
86
+ },
87
+ });
88
+ }
89
+ else {
90
+ trackEvent(event);
91
+ }
92
+ sessionStorage.setItem('loggerLastEvent', JSON.stringify({ ...event, occurred: new Date() }));
93
+ }
94
+ exports.trackEventSinceLastAction = trackEventSinceLastAction;
95
+ /**
96
+ * Gets the last tracked event, if available.
97
+ */
98
+ function getLastTrackedEvent() {
99
+ const eventStr = sessionStorage.getItem('loggerLastEvent');
100
+ if (!eventStr)
101
+ return null;
102
+ const event = JSON.parse(eventStr);
103
+ event.occurred = new Date(event.occurred);
104
+ return event;
105
+ }
106
+ exports.getLastTrackedEvent = getLastTrackedEvent;
107
+ /**
108
+ * Breadcrumbs to create a trail of events that happened prior to an issue.
109
+ * These events are very similar to traditional logs, but can record more rich structured data.
110
+ */
53
111
  function addBreadcrumb(breadcrumb) {
54
- for (const reporter of reporters) {
112
+ for (const reporter of getReporters(breadcrumb)) {
55
113
  reporter.addBreadcrumb(breadcrumb);
56
114
  }
57
115
  }
58
116
  exports.addBreadcrumb = addBreadcrumb;
59
- function addMetadata(metadata) {
60
- for (const reporter of reporters) {
117
+ /**
118
+ * Adds global metadata to all events.
119
+ * @param metadata Metadata to add.
120
+ * @param filters Optional filters to specify which reporters to add metadata to.
121
+ */
122
+ function addMetadata(metadata, filters) {
123
+ for (const reporter of getReporters(filters)) {
61
124
  reporter.addMetadata(metadata);
62
125
  }
63
126
  }
64
127
  exports.addMetadata = addMetadata;
65
- function setUser(user) {
66
- for (const reporter of reporters) {
128
+ /**
129
+ * Sets the user information in Analytics.
130
+ * @param user User information, or null to clear.
131
+ * @param filters Optional filters to specify which reporters to set the user for.
132
+ */
133
+ function setUser(user, filters) {
134
+ for (const reporter of getReporters(filters)) {
67
135
  reporter.setUser(user);
68
136
  }
69
137
  }
70
138
  exports.setUser = setUser;
71
- function setRouteName(routeName) {
72
- for (const reporter of reporters) {
139
+ /**
140
+ * Sets the route name in Analytics.
141
+ * Some Analytics services use this differentiate SPA Route vs Page changes.
142
+ * @param routeName Name of the Route.
143
+ * @param filters Optional filters to specify which reporters to set the route name for.
144
+ */
145
+ function setRouteName(routeName, filters) {
146
+ for (const reporter of getReporters(filters)) {
73
147
  reporter.setRouteName(routeName);
74
148
  }
75
149
  }
76
150
  exports.setRouteName = setRouteName;
77
- function setPageName(pageName) {
78
- for (const reporter of reporters) {
151
+ /**
152
+ * Sets the page name in Analytics.
153
+ * @param pageName Name of the Page.
154
+ * @param filters Optional filters to specify which reporters to set the page name for.
155
+ */
156
+ function setPageName(pageName, filters) {
157
+ for (const reporter of getReporters(filters)) {
79
158
  reporter.setPageName(pageName);
80
159
  }
81
160
  }
82
161
  exports.setPageName = setPageName;
83
- function reportError(error, metadata) {
84
- for (const reporter of reporters) {
85
- reporter.reportError(error, metadata);
162
+ /**
163
+ * Reports an Error in Reporters that support error tracking.
164
+ * @param error Error data.
165
+ * @param metadata Metadata to add to the error.
166
+ * @param filters Optional filters to specify which reporters to report the error to.
167
+ */
168
+ function reportError(error, metadata, filters) {
169
+ var _a;
170
+ for (const reporter of getReporters(filters)) {
171
+ (_a = reporter.reportError) === null || _a === void 0 ? void 0 : _a.call(reporter, error, metadata);
86
172
  }
87
173
  }
88
174
  exports.reportError = reportError;
89
- function recordSession() {
90
- for (const reporter of reporters) {
91
- reporter.recordSession();
175
+ /**
176
+ * Starts a session recording in Analytics, e.g. RUM Session Replay
177
+ * @param filters Optional filters to specify which reporters to start a session recording for.
178
+ */
179
+ function recordSession(filters) {
180
+ var _a;
181
+ for (const reporter of getReporters(filters)) {
182
+ (_a = reporter.recordSession) === null || _a === void 0 ? void 0 : _a.call(reporter);
92
183
  }
93
184
  }
94
185
  exports.recordSession = recordSession;
95
- function recordSessionStop() {
96
- for (const reporter of reporters) {
97
- reporter.recordSessionStop();
186
+ /**
187
+ * Stops a session recording in Analytics, e.g. RUM Session Replay
188
+ * @param filters Optional filters to specify which reporters to stop a session recording for.
189
+ */
190
+ function recordSessionStop(filters) {
191
+ var _a;
192
+ for (const reporter of getReporters(filters)) {
193
+ (_a = reporter.recordSessionStop) === null || _a === void 0 ? void 0 : _a.call(reporter);
98
194
  }
99
195
  }
100
196
  exports.recordSessionStop = recordSessionStop;
101
- function trackEventSinceLastAction(event) {
102
- const lastEvent = getLastTrackedEvent();
103
- if (lastEvent) {
104
- const duration = new Date().getTime() - lastEvent.occurred.getTime();
105
- trackEvent({
106
- ...event,
107
- metadata: {
108
- ...event.metadata,
109
- lastEventName: lastEvent.message,
110
- timeSinceLastEvent: duration,
111
- },
112
- });
113
- }
114
- else {
115
- trackEvent(event);
116
- }
117
- sessionStorage.setItem('loggerLastEvent', JSON.stringify({ ...event, occurred: new Date() }));
118
- }
119
- exports.trackEventSinceLastAction = trackEventSinceLastAction;
120
- function getLastTrackedEvent() {
121
- const eventStr = sessionStorage.getItem('loggerLastEvent');
122
- if (!eventStr)
123
- return null;
124
- const event = JSON.parse(eventStr);
125
- event.occurred = new Date(event.occurred);
126
- return event;
127
- }
128
- exports.getLastTrackedEvent = getLastTrackedEvent;
197
+ /**
198
+ * Creates a Logger instance.
199
+ * @param name Name of the Logger.
200
+ * @param options Logger configuration options.
201
+ */
129
202
  function createLogger(name, options) {
130
203
  if (!initialized) {
131
204
  throw new Error('You must call init on BrowserLogger before creating a logger');
132
205
  }
133
206
  if (ddInitialized) {
134
- return (0, datadogReporter_1.datadogLogger)(name, options);
207
+ return (0, reporters_1.datadogLogger)(name, options);
135
208
  }
136
209
  else {
137
210
  return (0, utils_1.consoleLogger)(name, options);
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,mCAAwC;AACxC,iEAAoG;AACpG,yDAAsD;AACtD,iEAAqF;AAErF,0CAAwB;AAEb,QAAA,MAAM,GAAmB,IAAI,CAAC;AAazC,MAAM,SAAS,GAAgB,EAAE,CAAC;AAClC,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,SAAgB,IAAI,CAAC,MAAsB;IACzC,WAAW,GAAG,IAAI,CAAC;IAEnB,IAAI,MAAM,CAAC,OAAO,EAAE;QAClB,SAAS,CAAC,IAAI,CAAC,IAAA,iCAAe,EAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QACxD,aAAa,GAAG,IAAI,CAAC;KACtB;IAED,IAAI,MAAM,C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;KACzC;AACH,CAAC;AAJD,kCAIC;AAED;;;GAGG;AACH,SAAgB,aAAa,CAAC,OAAyB;;IACrD,KAAK,MAAM,QAAQ,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE;QAC5C,MAAA,QAAQ,CAAC,aAAa,wDAAI,CAAC;KAC5B;AACH,CAAC;AAJD,sCAIC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,OAAyB;;IACzD,KAAK,MAAM,QAAQ,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE;QAC5C,MAAA,QAAQ,CAAC,iBAAiB,wDAAI,CAAC;KAChC;AACH,CAAC;AAJD,8CAIC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAa,EAAE,OAAiC;IAC3E,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;KACjF;IAED,IAAI,aAAa,EAAE;QACjB,OAAO,IAAA,yBAAa,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;KACrC;SAAM;QACL,OAAO,IAAA,qBAAa,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;KACrC;AACH,CAAC;AAVD,oCAUC"}
@@ -1,23 +1,53 @@
1
- import { IReporter } from '.';
2
- import { ServiceInfo } from '../types';
3
- export declare type AmplifyReporterConfig = {
1
+ import { IReporter, ReporterConfigBase, ServiceInfo } from '../types';
2
+ import { AttributeMap } from '../utils';
3
+ export interface AmplifyReporterConfig extends ReporterConfigBase {
4
+ /**
5
+ * AWS Region for Amplify.
6
+ */
4
7
  region: string;
5
8
  /**
6
- * The Identity Pool ID to use for reporting, if set to false, Auth.configure is not called.
9
+ * The Identity Pool Id to use for reporting, if set to false, Auth.configure is not called.
7
10
  * This must be called manually for the reporter to work.
8
11
  */
9
12
  identityPoolId: string | false;
13
+ /**
14
+ * The Pinpoint App Id to report to.
15
+ */
10
16
  analyticsAppId: string;
17
+ /**
18
+ * The Cognito User Pool to configure in Auth.configure.
19
+ * If you are using Cognito, it is better to set identityPoolId to false and configure Auth manually.
20
+ */
21
+ userPoolId?: string;
22
+ /**
23
+ * The Cognito Web Client Id to configure in Auth.configure.
24
+ * If you are using Cognito, it is better to set identityPoolId to false and configure Auth manually.
25
+ */
26
+ userPoolWebClientId?: string;
27
+ /**
28
+ * If you want to track which page/url in your webapp is the most frequently viewed one, you can use this feature.
29
+ * It will automatically send events containing url information when the page is visited.
30
+ */
11
31
  autoTrackPageViews?: boolean;
32
+ /**
33
+ * If you want to track user interactions with elements on the page, you can use this feature.
34
+ * All you need to do is attach the specified selectors to your dom element and turn on the auto tracking.
35
+ */
12
36
  autoTrackEvents?: boolean;
37
+ /**
38
+ * A web session can be defined in different ways.
39
+ * To keep it simple we define that the web session is active when the page is not hidden and inactive when the page is hidden.
40
+ */
13
41
  autoTrackSessions?: boolean;
42
+ /**
43
+ * The data tag prefix to use for attributing HTML elements. Defaults to data-analytics-
44
+ */
14
45
  selectorPrefix?: string;
15
- ignoreBreadcrumbCategories?: string[];
46
+ /**
47
+ * Modify how the reporter sends events to Amplify.
48
+ */
16
49
  buffering?: AmplifyReporterBufferingConfig;
17
- userPoolId?: string;
18
- userPoolWebClientId?: string;
19
- ignoreMetadataPatterns?: RegExp[];
20
- };
50
+ }
21
51
  /**
22
52
  * Configuration options for the buffering behavior of Pinpoint's event tracker.
23
53
  *
@@ -34,19 +64,15 @@ declare type AmplifyReporterBufferingConfig = {
34
64
  resendLimit?: number;
35
65
  };
36
66
  export declare function amplifyReporter(info: ServiceInfo, config: AmplifyReporterConfig): IReporter;
37
- declare type AttributeMap = Record<string, string[] | string | null>;
38
67
  /**
39
68
  * Pinpoint has strict attribute name and value length limits
40
69
  */
41
- export declare function asAttributeMap(values: Record<string, any>, groupValues?: boolean, ignorePatterns?: RegExp[]): AttributeMap;
70
+ export declare function asAttributeMap(values: Record<string, unknown>, groupValues?: boolean, ignorePatterns?: (string | RegExp)[]): AttributeMap;
42
71
  /**
43
72
  * Pinpoint expects `endpoint.attributes` and `endpoint.userAttributes` to have
44
73
  * values which are string arrays. This function takes in an object and ensures
45
74
  * all of its values are of type `string[]` to appease Pinpoint.
46
75
  */
47
76
  export declare function buildAttributeMap(values: Record<string, any>, parentKey?: string | undefined, groupValues?: boolean): AttributeMap;
48
- export declare function filterAttributeMap(attributes: AttributeMap | Record<string, string>, ignorePatterns: RegExp[]): {
49
- [k: string]: string | string[] | null;
50
- };
51
77
  export {};
52
78
  //# sourceMappingURL=amplifyReporter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"amplifyReporter.d.ts","sourceRoot":"","sources":["../../src/reporters/amplifyReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqC,MAAM,GAAG,CAAC;AACjE,OAAO,EAAwB,WAAW,EAAE,MAAM,UAAU,CAAC;AAI7D,oBAAY,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,cAAc,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0BAA0B,CAAC,EAAE,MAAM,EAAE,CAAC;IACtC,SAAS,CAAC,EAAE,8BAA8B,CAAC;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;CACnC,CAAC;AAEF;;;;GAIG;AACH,aAAK,8BAA8B,GAAG;IACpC,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE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