@statsig/web-analytics 3.24.4 → 3.25.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.24.4",
3
+ "version": "3.25.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.24.4",
13
- "@statsig/js-client": "3.24.4",
12
+ "@statsig/client-core": "3.25.0",
13
+ "@statsig/js-client": "3.25.0",
14
14
  "web-vitals": "5.0.3"
15
15
  },
16
16
  "jsdelivr": "./build/statsig-web-analytics.min.js",
@@ -240,6 +240,9 @@ class AutoCapture {
240
240
  });
241
241
  }
242
242
  _logRageClick(e) {
243
+ if (!(0, commonUtils_1._shouldLogEvent)(e, e.target)) {
244
+ return;
245
+ }
243
246
  const { value, metadata } = (0, eventUtils_1._gatherEventData)(e.target);
244
247
  this._enqueueAutoCapture(AutoCaptureEvent_1.AutoCaptureEventName.RAGE_CLICK, value, Object.assign(Object.assign({ x: e.clientX, y: e.clientY, timestamp: Date.now() }, (0, metadataUtils_1._gatherAllMetadata)((0, commonUtils_1._getSafeUrl)())), metadata));
245
248
  }
@@ -311,7 +314,10 @@ class AutoCapture {
311
314
  const typedClient = this._client;
312
315
  typedClient._possibleFirstTouchMetadata =
313
316
  (0, metadataUtils_1._getPossibleFirstTouchMetadata)((0, commonUtils_1._getSafeUrl)());
314
- typedClient._user = Object.assign(Object.assign({}, typedClient._user), { analyticsOnlyMetadata: Object.assign(Object.assign({}, typedClient._possibleFirstTouchMetadata), typedClient._user.analyticsOnlyMetadata) });
317
+ // Only update user if first touch metadata is not empty
318
+ if (Object.keys(typedClient._possibleFirstTouchMetadata).length > 0) {
319
+ typedClient._user = Object.assign(Object.assign({}, typedClient._user), { analyticsOnlyMetadata: Object.assign(Object.assign({}, typedClient._possibleFirstTouchMetadata), typedClient._user.analyticsOnlyMetadata) });
320
+ }
315
321
  }
316
322
  _flushImmediately() {
317
323
  this._client.flush().catch((e) => {
@@ -59,7 +59,14 @@ function _shouldLogEvent(e, el, isCopyEvent = false) {
59
59
  return ['change', 'click'].indexOf(eventType) >= 0;
60
60
  default:
61
61
  if (eventType === 'click') {
62
- if (tagName === 'button') {
62
+ const compStyles = window.getComputedStyle(el);
63
+ if (compStyles && compStyles.getPropertyValue('cursor') === 'pointer') {
64
+ return true;
65
+ }
66
+ if (exports.interactiveElements.includes(tagName)) {
67
+ return true;
68
+ }
69
+ if (el.getAttribute('contenteditable') === 'true') {
63
70
  return true;
64
71
  }
65
72
  const anchor = _getAnchorNodeInHierarchy(el);
@@ -1,5 +1,5 @@
1
1
  export declare function _gatherEventData(target: Element): {
2
- value: string | null;
2
+ value: string;
3
3
  metadata: Record<string, unknown>;
4
4
  };
5
5
  export declare function _gatherCopyEventData(e: Event): Record<string, unknown>;
@@ -7,12 +7,13 @@ const MAX_ATTRIBUTE_LENGTH = 1000;
7
7
  const MAX_CLASS_LIST_LENGTH = 100;
8
8
  const MAX_SELECTOR_DEPTH = 50;
9
9
  function _gatherEventData(target) {
10
+ const value = (0, commonUtils_1._getSanitizedPageUrl)() || '';
11
+ const tagName = target.tagName.toLowerCase();
12
+ // If the element is sensitive, we only gather safe attribute fields
10
13
  if (_isSensitiveElement(target)) {
11
- return { value: null, metadata: {} };
14
+ return { value, metadata: _getSafeMetadataAttributes(target) };
12
15
  }
13
- const tagName = target.tagName.toLowerCase();
14
16
  const metadata = {};
15
- const value = (0, commonUtils_1._getSanitizedPageUrl)() || '';
16
17
  metadata['tagName'] = tagName;
17
18
  const elementMetadata = _getMetadataFromElement(target);
18
19
  Object.assign(metadata, elementMetadata);
@@ -95,14 +96,21 @@ function _truncateString(str, maxLength) {
95
96
  return null;
96
97
  return str.length > maxLength ? str.substring(0, maxLength) + '...' : str;
97
98
  }
99
+ function _getSafeMetadataAttributes(elem) {
100
+ const metadata = {};
101
+ metadata['class'] = _normalizeClassAttribute(_truncateString(elem.getAttribute('class'), MAX_ATTRIBUTE_LENGTH) || '');
102
+ metadata['id'] = _truncateString(elem.getAttribute('id'), MAX_ATTRIBUTE_LENGTH);
103
+ metadata['ariaLabel'] = _truncateString(elem.getAttribute('aria-label'), MAX_ATTRIBUTE_LENGTH);
104
+ metadata['name'] = _truncateString(elem.getAttribute('name'), MAX_ATTRIBUTE_LENGTH);
105
+ return metadata;
106
+ }
98
107
  function _getMetadataFromElement(target) {
99
108
  const metadata = {};
109
+ const safeAttributes = _getSafeMetadataAttributes(target);
110
+ Object.assign(metadata, safeAttributes);
100
111
  const classList = Array.from(target.classList);
101
112
  metadata['classList'] =
102
113
  classList.length > 0 ? classList.slice(0, MAX_CLASS_LIST_LENGTH) : null;
103
- metadata['class'] = _normalizeClassAttribute(_truncateString(target.getAttribute('class'), MAX_ATTRIBUTE_LENGTH) || '');
104
- metadata['id'] = _truncateString(target.getAttribute('id'), MAX_ATTRIBUTE_LENGTH);
105
- metadata['ariaLabel'] = _truncateString(target.getAttribute('aria-label'), MAX_ATTRIBUTE_LENGTH);
106
114
  metadata['selector'] = _generateCssSelector(target);
107
115
  return metadata;
108
116
  }