@statsig/web-analytics 3.18.3 → 3.20.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/web-analytics",
3
- "version": "3.18.3",
3
+ "version": "3.20.0",
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.18.3",
13
- "@statsig/js-client": "3.18.3",
12
+ "@statsig/client-core": "3.20.0",
13
+ "@statsig/js-client": "3.20.0",
14
14
  "web-vitals": "5.0.3"
15
15
  },
16
16
  "jsdelivr": "./build/statsig-web-analytics.min.js",
@@ -19,6 +19,7 @@ export declare class AutoCapture {
19
19
  private _hasLoggedPageViewEnd;
20
20
  private _engagementManager;
21
21
  private _rageClickManager;
22
+ private _pageViewLogged;
22
23
  private _webVitalsManager;
23
24
  constructor(_client: PrecomputedEvaluationsInterface, options?: AutoCaptureOptions);
24
25
  private _addEventHandlers;
@@ -32,6 +33,7 @@ export declare class AutoCapture {
32
33
  private _logRageClick;
33
34
  private _logPerformance;
34
35
  private _enqueueAutoCapture;
36
+ private _updateClientWithPossibleFirstTouchMetadata;
35
37
  private _flushImmediately;
36
38
  private _isNewSession;
37
39
  private _getSessionFromClient;
@@ -43,6 +43,7 @@ class AutoCapture {
43
43
  this._disabledEvents = {};
44
44
  this._previousLoggedPageViewUrl = null;
45
45
  this._hasLoggedPageViewEnd = false;
46
+ this._pageViewLogged = false;
46
47
  const { sdkKey, errorBoundary, values } = _client.getContext();
47
48
  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 : {};
48
49
  this._errorBoundary = errorBoundary;
@@ -182,13 +183,20 @@ class AutoCapture {
182
183
  return;
183
184
  }
184
185
  this._engagementManager.setLastPageViewTime(Date.now());
185
- this._previousLoggedPageViewUrl = url;
186
186
  this._hasLoggedPageViewEnd = false;
187
187
  const payload = (0, metadataUtils_1._gatherAllMetadata)(url);
188
+ if (this._previousLoggedPageViewUrl) {
189
+ payload['last_page_view_url'] = this._previousLoggedPageViewUrl.href;
190
+ }
191
+ if (!this._pageViewLogged) {
192
+ this._updateClientWithPossibleFirstTouchMetadata();
193
+ this._pageViewLogged = true;
194
+ }
188
195
  this._enqueueAutoCapture(AutoCaptureEvent_1.AutoCaptureEventName.PAGE_VIEW, (0, commonUtils_1._getSanitizedPageUrl)(), payload, {
189
196
  flushImmediately: true,
190
197
  addNewSessionMetadata: true,
191
198
  });
199
+ this._previousLoggedPageViewUrl = url;
192
200
  this._engagementManager.bumpInactiveTimer();
193
201
  }
194
202
  _tryLogPageViewEnd(dueToInactivity = false) {
@@ -268,6 +276,12 @@ class AutoCapture {
268
276
  this._errorBoundary.logError('AC::enqueue', err);
269
277
  }
270
278
  }
279
+ _updateClientWithPossibleFirstTouchMetadata() {
280
+ const typedClient = this._client;
281
+ typedClient._possibleFirstTouchMetadata =
282
+ (0, metadataUtils_1._getPossibleFirstTouchMetadata)((0, commonUtils_1._getSafeUrl)());
283
+ typedClient._user = Object.assign(Object.assign({}, typedClient._user), { analyticsOnlyMetadata: Object.assign(Object.assign({}, typedClient._possibleFirstTouchMetadata), typedClient._user.analyticsOnlyMetadata) });
284
+ }
271
285
  _flushImmediately() {
272
286
  this._client.flush().catch((e) => {
273
287
  client_core_1.Log.error(e);
@@ -1,3 +1,4 @@
1
1
  export declare function _gatherCommonMetadata(url: URL): Record<string, string | number | null>;
2
2
  export declare function _gatherAllMetadata(url: URL): Record<string, string | number>;
3
3
  export declare function _getNetworkInfo(): Record<string, string | number | boolean>;
4
+ export declare function _getPossibleFirstTouchMetadata(url: URL): Record<string, string | number>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._getNetworkInfo = exports._gatherAllMetadata = exports._gatherCommonMetadata = void 0;
3
+ exports._getPossibleFirstTouchMetadata = exports._getNetworkInfo = exports._gatherAllMetadata = exports._gatherCommonMetadata = void 0;
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const commonUtils_1 = require("./commonUtils");
6
6
  function _gatherCommonMetadata(url) {
@@ -48,6 +48,22 @@ function _getNetworkInfo() {
48
48
  return result;
49
49
  }
50
50
  exports._getNetworkInfo = _getNetworkInfo;
51
+ function _getPossibleFirstTouchMetadata(url) {
52
+ const safeDoc = (0, client_core_1._getDocumentSafe)();
53
+ const safeWnd = (0, client_core_1._getWindowSafe)();
54
+ if (!safeDoc || !safeWnd) {
55
+ return {};
56
+ }
57
+ const referrerInfo = getReferrerInfo(safeDoc);
58
+ const campaignParams = getCampaignParams(url);
59
+ const combined = (0, commonUtils_1._stripEmptyValues)(Object.assign(Object.assign({}, referrerInfo), campaignParams));
60
+ const prefixed = {};
61
+ for (const [key, value] of Object.entries(combined)) {
62
+ prefixed[`$s_${key}`] = value;
63
+ }
64
+ return prefixed;
65
+ }
66
+ exports._getPossibleFirstTouchMetadata = _getPossibleFirstTouchMetadata;
51
67
  function getReferrerInfo(safeDoc) {
52
68
  const referrer = (safeDoc === null || safeDoc === void 0 ? void 0 : safeDoc.referrer) || '';
53
69
  if (!referrer) {