@statsig/web-analytics 3.30.2 → 3.31.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/web-analytics",
3
- "version": "3.30.2",
3
+ "version": "3.31.1",
4
4
  "license": "ISC",
5
5
  "homepage": "https://github.com/statsig-io/js-client-monorepo",
6
6
  "repository": {
@@ -9,8 +9,8 @@
9
9
  "directory": "packages/web-analytics"
10
10
  },
11
11
  "dependencies": {
12
- "@statsig/client-core": "3.30.2",
13
- "@statsig/js-client": "3.30.2",
12
+ "@statsig/client-core": "3.31.1",
13
+ "@statsig/js-client": "3.31.1",
14
14
  "web-vitals": "5.0.3"
15
15
  },
16
16
  "jsdelivr": "./build/statsig-web-analytics.min.js",
@@ -36,6 +36,5 @@ export declare class AutoCapture {
36
36
  private _updateClientWithPossibleFirstTouchMetadata;
37
37
  private _flushImmediately;
38
38
  private _isNewSession;
39
- private _getSessionFromClient;
40
39
  static getAllMetadata(): Record<string, string | number>;
41
40
  }
@@ -33,7 +33,7 @@ function runStatsigAutoCapture(client, options) {
33
33
  if ((0, client_core_1._isServerEnv)()) {
34
34
  return null;
35
35
  }
36
- const { sdkKey } = client.getContext();
36
+ const { sdkKey } = client.getContextHandle();
37
37
  if (!(0, client_core_1._isServerEnv)()) {
38
38
  const global = (0, client_core_1._getStatsigGlobal)();
39
39
  const instances = (_a = global.acInstances) !== null && _a !== void 0 ? _a : {};
@@ -52,14 +52,14 @@ class AutoCapture {
52
52
  this._previousLoggedPageViewUrl = null;
53
53
  this._hasLoggedPageViewEnd = false;
54
54
  this._pageViewLogged = false;
55
- const { sdkKey, errorBoundary, values } = _client.getContext();
55
+ const { sdkKey, errorBoundary, values } = _client.getContextHandle();
56
56
  this._options = options;
57
57
  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 : {};
58
58
  this._errorBoundary = errorBoundary;
59
59
  this._errorBoundary.wrap(this, 'autoCapture:');
60
60
  this._client.$on('values_updated', () => {
61
61
  var _a, _b;
62
- const values = this._client.getContext().values;
62
+ const values = this._client.getContextHandle().values;
63
63
  this._disabledEvents =
64
64
  (_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 : this._disabledEvents;
65
65
  });
@@ -225,7 +225,7 @@ class AutoCapture {
225
225
  });
226
226
  }
227
227
  _logSessionStart() {
228
- const session = this._getSessionFromClient();
228
+ const session = this._client.getContextHandle().getSession();
229
229
  try {
230
230
  if (!this._isNewSession(session)) {
231
231
  return;
@@ -319,7 +319,8 @@ class AutoCapture {
319
319
  if (this._disabledEvents[eventName] || this._disabledEvents[subname]) {
320
320
  return;
321
321
  }
322
- const session = this._getSessionFromClient();
322
+ const isUserAction = (0, AutoCaptureEvent_1.isUserActionAutoCaptureEvent)(eventName);
323
+ const session = this._client.getContextHandle().getSession(isUserAction);
323
324
  try {
324
325
  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);
325
326
  if (options === null || options === void 0 ? void 0 : options.addNewSessionMetadata) {
@@ -360,9 +361,6 @@ class AutoCapture {
360
361
  // within the last second
361
362
  return Math.abs(session.data.startTime - Date.now()) < 1000;
362
363
  }
363
- _getSessionFromClient() {
364
- return this._client.getContext().session;
365
- }
366
364
  static getAllMetadata() {
367
365
  return (0, metadataUtils_1._gatherAllMetadata)((0, commonUtils_1._getSafeUrl)());
368
366
  }
@@ -17,3 +17,4 @@ export type AutoCaptureEventName = (typeof AutoCaptureEventName)[keyof typeof Au
17
17
  export type AutoCaptureEvent = StatsigEvent & {
18
18
  eventName: AutoCaptureEventName;
19
19
  };
20
+ export declare const isUserActionAutoCaptureEvent: (eventName: AutoCaptureEventName) => boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AutoCaptureEventName = void 0;
3
+ exports.isUserActionAutoCaptureEvent = exports.AutoCaptureEventName = void 0;
4
4
  exports.AutoCaptureEventName = {
5
5
  PAGE_VIEW: 'auto_capture::page_view',
6
6
  PAGE_VIEW_END: 'auto_capture::page_view_end',
@@ -16,3 +16,16 @@ exports.AutoCaptureEventName = {
16
16
  // log line is a special event name used to populate logs metrics explorer
17
17
  CONSOLE_LOG: 'statsig::log_line',
18
18
  };
19
+ const USER_ACTION_EVENTS = new Set([
20
+ exports.AutoCaptureEventName.PAGE_VIEW,
21
+ exports.AutoCaptureEventName.PAGE_VIEW_END,
22
+ exports.AutoCaptureEventName.SESSION_START,
23
+ exports.AutoCaptureEventName.FORM_SUBMIT,
24
+ exports.AutoCaptureEventName.CLICK,
25
+ exports.AutoCaptureEventName.RAGE_CLICK,
26
+ exports.AutoCaptureEventName.COPY,
27
+ ]);
28
+ const isUserActionAutoCaptureEvent = (eventName) => {
29
+ return USER_ACTION_EVENTS.has(eventName);
30
+ };
31
+ exports.isUserActionAutoCaptureEvent = isUserActionAutoCaptureEvent;