@adobe/helix-rum-enhancer 2.14.1 → 2.15.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/.husky/pre-commit CHANGED
File without changes
package/.releaserc.cjs CHANGED
@@ -12,5 +12,5 @@ module.exports = {
12
12
  }],
13
13
  ["@semantic-release/github", {}]
14
14
  ],
15
- branches: ['main', '1.x'],
15
+ branches: ['main'],
16
16
  };
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ # [2.15.0](https://github.com/adobe/helix-rum-enhancer/compare/v2.14.2...v2.15.0) (2024-07-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * use correct token for release ([094f37e](https://github.com/adobe/helix-rum-enhancer/commit/094f37ef2de8ddf5d64ea38c9071c9b1bec6119a))
7
+
8
+
9
+ ### Features
10
+
11
+ * add more logic to button selector ([#205](https://github.com/adobe/helix-rum-enhancer/issues/205)) ([c9a5629](https://github.com/adobe/helix-rum-enhancer/commit/c9a5629e7e690397a5f46cbf8db08570f0c4d250))
12
+ * clean up and trigger release ([bfc8d24](https://github.com/adobe/helix-rum-enhancer/commit/bfc8d241cd19b33975ac37be5167783b99fbe54c))
13
+ * switch release token ([0e5b3b0](https://github.com/adobe/helix-rum-enhancer/commit/0e5b3b03d0b96a32118340e7b6f004da8660f0aa))
14
+ * trigger release ([bf26949](https://github.com/adobe/helix-rum-enhancer/commit/bf269492cb330c55d22fd0eeed4aad4cfdac57a3))
15
+
16
+ ## [2.14.2](https://github.com/adobe/helix-rum-enhancer/compare/v2.14.1...v2.14.2) (2024-06-12)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * restore original path behavior ([#201](https://github.com/adobe/helix-rum-enhancer/issues/201)) ([f70df99](https://github.com/adobe/helix-rum-enhancer/commit/f70df992da778f5700d9bdc8b4f114ddf272ea77))
22
+
1
23
  ## [2.14.1](https://github.com/adobe/helix-rum-enhancer/compare/v2.14.0...v2.14.1) (2024-06-11)
2
24
 
3
25
 
package/modules/dom.js CHANGED
@@ -54,11 +54,25 @@ export const sourceSelector = (element) => {
54
54
  return `.${element.getAttribute('data-block-name')}`;
55
55
  }
56
56
 
57
- if (Array.from(element.classList).some((className) => className.match(/button|cta/))) {
58
- return blockName ? `.${blockName} .button` : '.button';
57
+ const classes = Array.from(element.classList);
58
+ const label = element.tagName.toLowerCase();
59
+ const firstClass = classes.length > 0 ? `.${classes[0]}` : '';
60
+ const labelWithClass = `${element.tagName.toLowerCase()}${firstClass}`;
61
+ if (element.tagName.toLowerCase() === 'button'
62
+ || element.type === 'button'
63
+ || classes.some((className) => className.match(/button|cta/))) {
64
+ let parent = element.parentElement;
65
+ if (!parent) return labelWithClass;
66
+ if (parent.id) return `#${parent.id} ${label}`;
67
+ while (parent.tagName !== 'BODY' && !parent.id) parent = parent.parentElement;
68
+ if (parent.id) return `#${parent.id} ${labelWithClass}`;
69
+ return blockName ? `.${blockName} ${labelWithClass}` : labelWithClass;
59
70
  }
60
71
 
61
- return sourceSelector(element.parentElement);
72
+ const parent = sourceSelector(element.parentElement);
73
+ if (parent) return parent;
74
+
75
+ return labelWithClass;
62
76
  /* c8 ignore next 3 */
63
77
  } catch (error) {
64
78
  return null;
package/modules/utils.js CHANGED
@@ -11,7 +11,28 @@
11
11
  */
12
12
 
13
13
  export const urlSanitizers = {
14
+ /**
15
+ * Returns the full url.
16
+ * If no url is provided, it defaults to window.location.href.
17
+ * @param {string} url (default: window.location.href) The url to sanitize
18
+ * @returns {string} The sanitized url
19
+ */
14
20
  full: (url = window.location.href) => new URL(url).toString(),
21
+ /**
22
+ * Returns the origin of the provided url.
23
+ * If no url is provided, it defaults to window.location.href.
24
+ * @param {string} url (default: window.location.href) The url to sanitize
25
+ * @returns {string} The sanitized url
26
+ */
15
27
  origin: (url = window.location.href) => new URL(url).origin,
16
- path: (url = window.location.href) => new URL(url).pathname,
28
+ /**
29
+ * Returns the sanitized url: the origin and the path (no query params or hash)
30
+ * If no url is provided, it defaults to window.location.href.
31
+ * @param {string} url (default: window.location.href) The url to sanitize
32
+ * @returns {string} The sanitized url
33
+ */
34
+ path: (url = window.location.href) => {
35
+ const u = new URL(url);
36
+ return `${u.origin}${u.pathname}`;
37
+ },
17
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-rum-enhancer",
3
- "version": "2.14.1",
3
+ "version": "2.15.0",
4
4
  "description": "Helix RUM Enhancer",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -42,7 +42,7 @@
42
42
  "@web/test-runner-commands": "0.9.0",
43
43
  "@web/test-runner-mocha": "0.9.0",
44
44
  "@web/test-runner-playwright": "0.11.0",
45
- "c8": "10.0.0",
45
+ "c8": "10.1.2",
46
46
  "codecov": "3.8.3",
47
47
  "eslint": "8.57.0",
48
48
  "eslint-plugin-header": "3.1.1",
@@ -50,8 +50,8 @@
50
50
  "husky": "9.0.11",
51
51
  "jsdoc-to-markdown": "8.0.1",
52
52
  "junit-report-builder": "3.2.1",
53
- "lint-staged": "15.2.5",
54
- "mocha": "10.4.0",
53
+ "lint-staged": "15.2.7",
54
+ "mocha": "10.5.2",
55
55
  "mocha-multi-reporters": "1.5.1",
56
56
  "rollup": "4.18.0",
57
57
  "rollup-plugin-cleanup": "3.2.1",
package/src/index.js CHANGED
@@ -30,9 +30,30 @@
30
30
  };
31
31
 
32
32
  const urlSanitizers = {
33
+ /**
34
+ * Returns the full url.
35
+ * If no url is provided, it defaults to window.location.href.
36
+ * @param {string} url (default: window.location.href) The url to sanitize
37
+ * @returns {string} The sanitized url
38
+ */
33
39
  full: (url = window.location.href) => new URL(url).toString(),
40
+ /**
41
+ * Returns the origin of the provided url.
42
+ * If no url is provided, it defaults to window.location.href.
43
+ * @param {string} url (default: window.location.href) The url to sanitize
44
+ * @returns {string} The sanitized url
45
+ */
34
46
  origin: (url = window.location.href) => new URL(url).origin,
35
- path: (url = window.location.href) => new URL(url).pathname,
47
+ /**
48
+ * Returns the sanitized url: the origin and the path (no query params or hash)
49
+ * If no url is provided, it defaults to window.location.href.
50
+ * @param {string} url (default: window.location.href) The url to sanitize
51
+ * @returns {string} The sanitized url
52
+ */
53
+ path: (url = window.location.href) => {
54
+ const u = new URL(url);
55
+ return `${u.origin}${u.pathname}`;
56
+ },
36
57
  };
37
58
 
38
59
  const getTargetValue = (element) => element.getAttribute('data-rum-target') || element.getAttribute('href')
@@ -79,11 +100,25 @@
79
100
  return `.${element.getAttribute('data-block-name')}`;
80
101
  }
81
102
 
82
- if (Array.from(element.classList).some((className) => className.match(/button|cta/))) {
83
- return blockName ? `.${blockName} .button` : '.button';
103
+ const classes = Array.from(element.classList);
104
+ const label = element.tagName.toLowerCase();
105
+ const firstClass = classes.length > 0 ? `.${classes[0]}` : '';
106
+ const labelWithClass = `${element.tagName.toLowerCase()}${firstClass}`;
107
+ if (element.tagName.toLowerCase() === 'button'
108
+ || element.type === 'button'
109
+ || classes.some((className) => className.match(/button|cta/))) {
110
+ let parent = element.parentElement;
111
+ if (!parent) return labelWithClass;
112
+ if (parent.id) return `#${parent.id} ${label}`;
113
+ while (parent.tagName !== 'BODY' && !parent.id) parent = parent.parentElement;
114
+ if (parent.id) return `#${parent.id} ${labelWithClass}`;
115
+ return blockName ? `.${blockName} ${labelWithClass}` : labelWithClass;
84
116
  }
85
117
 
86
- return sourceSelector(element.parentElement);
118
+ const parent = sourceSelector(element.parentElement);
119
+ if (parent) return parent;
120
+
121
+ return labelWithClass;
87
122
  } catch (error) {
88
123
  return null;
89
124
  }