@arthurreira/analytics 0.12.0 → 0.13.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.
@@ -176,11 +176,8 @@ var AfAnalytics = (() => {
176
176
  function trackScroll(apiUrl, apiKey, sessionId, depth) {
177
177
  send(apiUrl, apiKey, __spreadProps(__spreadValues({}, baseFields(sessionId, "scroll")), { scroll_depth: depth }));
178
178
  }
179
- function trackError(apiUrl, apiKey, sessionId, error) {
180
- send(apiUrl, apiKey, __spreadProps(__spreadValues({}, baseFields(sessionId, "error")), {
181
- error_message: error.message,
182
- stack_trace: error.stack || null
183
- }));
179
+ function trackException(apiUrl, apiKey, sessionId, fields) {
180
+ send(apiUrl, apiKey, __spreadValues(__spreadValues({}, baseFields(sessionId, "js_exception")), fields));
184
181
  }
185
182
  function init() {
186
183
  const config = readConfig();
@@ -223,7 +220,31 @@ var AfAnalytics = (() => {
223
220
  { passive: true }
224
221
  );
225
222
  window.addEventListener("error", (e) => {
226
- enqueue((id) => trackError(apiUrl, apiKey, id, new Error(e.message)));
223
+ enqueue((id) => {
224
+ var _a, _b, _c, _d, _e, _f, _g;
225
+ return trackException(apiUrl, apiKey, id, {
226
+ exception_type: (_b = (_a = e.error) == null ? void 0 : _a.name) != null ? _b : "Error",
227
+ exception_message: e.message,
228
+ exception_filename: (_c = e.filename) != null ? _c : null,
229
+ exception_lineno: (_d = e.lineno) != null ? _d : null,
230
+ exception_colno: (_e = e.colno) != null ? _e : null,
231
+ stack_trace: (_g = (_f = e.error) == null ? void 0 : _f.stack) != null ? _g : null
232
+ });
233
+ });
234
+ });
235
+ window.addEventListener("unhandledrejection", (e) => {
236
+ const reason = e.reason;
237
+ enqueue((id) => {
238
+ var _a, _b, _c;
239
+ return trackException(apiUrl, apiKey, id, {
240
+ exception_type: (_a = reason == null ? void 0 : reason.name) != null ? _a : "UnhandledRejection",
241
+ exception_message: (_b = reason == null ? void 0 : reason.message) != null ? _b : String(reason),
242
+ exception_filename: null,
243
+ exception_lineno: null,
244
+ exception_colno: null,
245
+ stack_trace: (_c = reason == null ? void 0 : reason.stack) != null ? _c : null
246
+ });
247
+ });
227
248
  });
228
249
  const endSession = () => {
229
250
  if (!sessionId || sessionEnded) return;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  { "name": "@arthurreira/analytics",
2
- "version": "0.12.0",
2
+ "version": "0.13.0",
3
3
  "type": "module",
4
4
  "scripts": {
5
5
  "build": "tsup",