@statsig/web-analytics 0.0.1-beta.29 → 0.0.1-beta.30

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": "0.0.1-beta.29",
3
+ "version": "0.0.1-beta.30",
4
4
  "dependencies": {
5
- "@statsig/client-core": "0.0.1-beta.29",
6
- "@statsig/js-client": "0.0.1-beta.29"
5
+ "@statsig/client-core": "0.0.1-beta.30",
6
+ "@statsig/js-client": "0.0.1-beta.30"
7
7
  },
8
8
  "jsdelivr": "./build/statsig-web-analytics.min.js",
9
9
  "type": "commonjs",
@@ -20,7 +20,7 @@ class AutoCapture {
20
20
  const instances = (_a = __STATSIG__.acInstances) !== null && _a !== void 0 ? _a : {};
21
21
  instances[sdkKey] = this;
22
22
  __STATSIG__.acInstances = instances;
23
- const doc = (0, Utils_1._getDocumentSafe)();
23
+ const doc = (0, client_core_1._getDocumentSafe)();
24
24
  if ((doc === null || doc === void 0 ? void 0 : doc.readyState) === 'loading') {
25
25
  doc.addEventListener('DOMContentLoaded', () => this._initialize());
26
26
  return;
@@ -28,8 +28,8 @@ class AutoCapture {
28
28
  this._initialize();
29
29
  }
30
30
  _addEventHandlers() {
31
- const win = (0, Utils_1._getWindowSafe)();
32
- const doc = (0, Utils_1._getDocumentSafe)();
31
+ const win = (0, client_core_1._getWindowSafe)();
32
+ const doc = (0, client_core_1._getDocumentSafe)();
33
33
  if (!win || !doc) {
34
34
  return;
35
35
  }
@@ -94,13 +94,13 @@ class AutoCapture {
94
94
  var _a;
95
95
  const url = (0, Utils_1._getSafeUrl)();
96
96
  this._logAutoCaptureImmediately('page_view', (0, Utils_1._getSanitizedPageUrl)(), {
97
- title: (_a = (0, Utils_1._getDocumentSafe)()) === null || _a === void 0 ? void 0 : _a.title,
97
+ title: (_a = (0, client_core_1._getDocumentSafe)()) === null || _a === void 0 ? void 0 : _a.title,
98
98
  queryParams: Object.fromEntries(url.searchParams),
99
99
  });
100
100
  }, 1);
101
101
  }
102
102
  _logPerformance() {
103
- const win = (0, Utils_1._getWindowSafe)();
103
+ const win = (0, client_core_1._getWindowSafe)();
104
104
  if (typeof (win === null || win === void 0 ? void 0 : win.performance) === 'undefined' ||
105
105
  typeof win.performance.getEntriesByType !== 'function' ||
106
106
  typeof win.performance.getEntriesByName !== 'function') {
@@ -139,7 +139,7 @@ class AutoCapture {
139
139
  const event = {
140
140
  eventName: `auto_capture::${name}`,
141
141
  value,
142
- metadata: Object.assign({ sessionId: (0, Utils_1._getWebSessionId)(this._client.getContext().sdkKey), page_url: (_c = (_b = (_a = (0, Utils_1._getWindowSafe)()) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.href) !== null && _c !== void 0 ? _c : '' }, metadata),
142
+ metadata: Object.assign({ sessionId: (0, Utils_1._getWebSessionId)(this._client.getContext().sdkKey), 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),
143
143
  };
144
144
  this._client.logEvent(event);
145
145
  client_core_1.Log.debug('Enqueued Event', event);
@@ -152,8 +152,8 @@ class AutoCapture {
152
152
  }
153
153
  _scrollEventHandler() {
154
154
  var _a, _b, _c, _d;
155
- const scrollHeight = (_b = (_a = (0, Utils_1._getDocumentSafe)()) === null || _a === void 0 ? void 0 : _a.body.scrollHeight) !== null && _b !== void 0 ? _b : 1;
156
- const win = (0, Utils_1._getWindowSafe)();
155
+ const scrollHeight = (_b = (_a = (0, client_core_1._getDocumentSafe)()) === null || _a === void 0 ? void 0 : _a.body.scrollHeight) !== null && _b !== void 0 ? _b : 1;
156
+ const win = (0, client_core_1._getWindowSafe)();
157
157
  const scrollY = (_c = win === null || win === void 0 ? void 0 : win.scrollY) !== null && _c !== void 0 ? _c : 1;
158
158
  const innerHeight = (_d = win === null || win === void 0 ? void 0 : win.innerHeight) !== null && _d !== void 0 ? _d : 1;
159
159
  this._deepestScroll = Math.max(this._deepestScroll, Math.min(100, Math.round(((scrollY + innerHeight) / scrollHeight) * 100)));
package/src/Utils.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- export declare function _getDocumentSafe(): Document | null;
2
- export declare function _getWindowSafe(): Window | null;
3
1
  export declare function _gatherEventData(target: Element): {
4
2
  value: string;
5
3
  metadata: Record<string, string | null>;
package/src/Utils.js CHANGED
@@ -1,20 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._registerEventHandler = exports._getSanitizedPageUrl = exports._getWebSessionId = exports._getSafeUrl = exports._shouldLogEvent = exports._getTargetNode = exports._gatherEventData = exports._getWindowSafe = exports._getDocumentSafe = void 0;
3
+ exports._registerEventHandler = exports._getSanitizedPageUrl = exports._getWebSessionId = exports._getSafeUrl = exports._shouldLogEvent = exports._getTargetNode = exports._gatherEventData = void 0;
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const MAX_SESSION_IDLE_TIME = 10 * 60 * 1000; // 10 minutes
6
6
  const MAX_SESSION_AGE = 4 * 60 * 60 * 1000; // 4 hours
7
7
  const globals = {};
8
- function _getDocumentSafe() {
9
- var _a;
10
- const win = _getWindowSafe();
11
- return (_a = win === null || win === void 0 ? void 0 : win.document) !== null && _a !== void 0 ? _a : null;
12
- }
13
- exports._getDocumentSafe = _getDocumentSafe;
14
- function _getWindowSafe() {
15
- return typeof window !== 'undefined' ? window : null;
16
- }
17
- exports._getWindowSafe = _getWindowSafe;
18
8
  function _gatherEventData(target) {
19
9
  var _a;
20
10
  const tagName = target.tagName.toLowerCase();
@@ -86,7 +76,7 @@ function _shouldLogEvent(e, el) {
86
76
  exports._shouldLogEvent = _shouldLogEvent;
87
77
  function _getSafeUrl() {
88
78
  var _a, _b, _c;
89
- const href = (_c = (_b = (_a = _getWindowSafe()) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.href) !== null && _c !== void 0 ? _c : '';
79
+ const href = (_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 : '';
90
80
  let url;
91
81
  try {
92
82
  url = new URL(href);
@@ -116,7 +106,7 @@ function _getWebSessionId(sdkKey) {
116
106
  exports._getWebSessionId = _getWebSessionId;
117
107
  function _getSanitizedPageUrl() {
118
108
  var _a, _b, _c;
119
- const url = (_c = (_b = (_a = _getWindowSafe()) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.href) === null || _c === void 0 ? void 0 : _c.split(/[?#]/)[0];
109
+ const 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 ? void 0 : _c.split(/[?#]/)[0];
120
110
  return url || '';
121
111
  }
122
112
  exports._getSanitizedPageUrl = _getSanitizedPageUrl;
@@ -145,7 +135,7 @@ function _getAnchorNodeInHierarchy(node) {
145
135
  return null;
146
136
  }
147
137
  function _setLocalValue(key, value) {
148
- const win = _getWindowSafe();
138
+ const win = (0, client_core_1._getWindowSafe)();
149
139
  if (win && win.localStorage) {
150
140
  win.localStorage.setItem(key, value);
151
141
  }
@@ -155,7 +145,7 @@ function _setLocalValue(key, value) {
155
145
  }
156
146
  }
157
147
  function _getLocalValue(key) {
158
- const win = _getWindowSafe();
148
+ const win = (0, client_core_1._getWindowSafe)();
159
149
  if (win && win.localStorage) {
160
150
  return win.localStorage.getItem(key);
161
151
  }