@statsig/web-analytics 1.7.0 → 2.0.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.
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@statsig/web-analytics",
3
- "version": "1.7.0",
3
+ "version": "2.0.0",
4
4
  "dependencies": {
5
- "@statsig/client-core": "1.7.0",
6
- "@statsig/js-client": "1.7.0"
5
+ "@statsig/client-core": "2.0.0",
6
+ "@statsig/js-client": "2.0.0"
7
7
  },
8
8
  "jsdelivr": "./build/statsig-web-analytics.min.js",
9
9
  "type": "commonjs",
@@ -1,11 +1,12 @@
1
- import { StatsigClient } from '@statsig/js-client';
2
- export declare function runStatsigAutoCapture(client: StatsigClient): AutoCapture;
1
+ import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
+ export declare function runStatsigAutoCapture(client: PrecomputedEvaluationsInterface): AutoCapture;
3
3
  export declare class AutoCapture {
4
4
  private _client;
5
5
  private _errorBoundary;
6
6
  private _startTime;
7
7
  private _deepestScroll;
8
- constructor(_client: StatsigClient);
8
+ private _disabledEvents;
9
+ constructor(_client: PrecomputedEvaluationsInterface);
9
10
  private _addEventHandlers;
10
11
  private _autoLogEvent;
11
12
  private _initialize;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.AutoCapture = exports.runStatsigAutoCapture = void 0;
13
4
  const client_core_1 = require("@statsig/client-core");
@@ -19,17 +10,19 @@ function runStatsigAutoCapture(client) {
19
10
  exports.runStatsigAutoCapture = runStatsigAutoCapture;
20
11
  class AutoCapture {
21
12
  constructor(_client) {
22
- var _a;
13
+ var _a, _b, _c;
23
14
  this._client = _client;
24
15
  this._startTime = Date.now();
25
16
  this._deepestScroll = 0;
26
- const { sdkKey, errorBoundary } = _client.getContext();
17
+ this._disabledEvents = {};
18
+ const { sdkKey, errorBoundary, values } = _client.getContext();
19
+ this._disabledEvents = (_b = (_a = values === null || values === void 0 ? void 0 : values.auto_capture_settings) === null || _a === void 0 ? void 0 : _a.disabled_events) !== null && _b !== void 0 ? _b : {};
27
20
  this._errorBoundary = errorBoundary;
28
21
  this._errorBoundary.wrap(this);
29
22
  const doc = (0, client_core_1._getDocumentSafe)();
30
23
  if (!(0, client_core_1._isServerEnv)()) {
31
24
  __STATSIG__ = (0, client_core_1._getStatsigGlobal)();
32
- const instances = (_a = __STATSIG__.acInstances) !== null && _a !== void 0 ? _a : {};
25
+ const instances = (_c = __STATSIG__.acInstances) !== null && _c !== void 0 ? _c : {};
33
26
  instances[sdkKey] = this;
34
27
  __STATSIG__.acInstances = instances;
35
28
  }
@@ -103,16 +96,16 @@ class AutoCapture {
103
96
  });
104
97
  }
105
98
  _logSessionStart() {
106
- this._getSessionFromClient()
107
- .then((session) => {
99
+ const session = this._getSessionFromClient();
100
+ try {
108
101
  if (!this._isNewSession(session)) {
109
102
  return;
110
103
  }
111
104
  this._enqueueAutoCapture('session_start', (0, Utils_1._getSanitizedPageUrl)(), { sessionID: session.data.sessionID }, { flushImmediately: true });
112
- })
113
- .catch((err) => {
105
+ }
106
+ catch (err) {
114
107
  this._errorBoundary.logError('AC::logSession', err);
115
- });
108
+ }
116
109
  }
117
110
  _logPageView() {
118
111
  setTimeout(() => {
@@ -160,9 +153,12 @@ class AutoCapture {
160
153
  }, { flushImmediately: true });
161
154
  }
162
155
  _enqueueAutoCapture(name, value, metadata, options) {
163
- this._getSessionFromClient()
164
- .then((session) => {
165
- var _a, _b, _c;
156
+ var _a, _b, _c;
157
+ if (this._disabledEvents[name]) {
158
+ return;
159
+ }
160
+ const session = this._getSessionFromClient();
161
+ try {
166
162
  const logMetadata = Object.assign({ sessionID: session.data.sessionID, page_url: (_c = (_b = (_a = (0, client_core_1._getWindowSafe)()) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.href) !== null && _c !== void 0 ? _c : '' }, metadata);
167
163
  if (options === null || options === void 0 ? void 0 : options.addNewSessionMetadata) {
168
164
  logMetadata['isNewSession'] = String(this._isNewSession(session));
@@ -178,10 +174,10 @@ class AutoCapture {
178
174
  client_core_1.Log.error(e);
179
175
  });
180
176
  }
181
- })
182
- .catch((err) => {
177
+ }
178
+ catch (err) {
183
179
  this._errorBoundary.logError('AC::enqueue', err);
184
- });
180
+ }
185
181
  }
186
182
  _scrollEventHandler() {
187
183
  var _a, _b, _c, _d;
@@ -196,10 +192,7 @@ class AutoCapture {
196
192
  return Math.abs(session.data.startTime - Date.now()) < 1000;
197
193
  }
198
194
  _getSessionFromClient() {
199
- return __awaiter(this, void 0, void 0, function* () {
200
- const x = yield this._client.getAsyncContext();
201
- return x.session;
202
- });
195
+ return this._client.getContext().session;
203
196
  }
204
197
  }
205
198
  exports.AutoCapture = AutoCapture;