Skip to content

Commit

Permalink
Merge pull request #148 from shsteimer/target-value-anchors
Browse files Browse the repository at this point in the history
feat: add logic to capture target from wrapping anchor tag
  • Loading branch information
trieloff authored Apr 18, 2024
2 parents 92883ef + 2a733b3 commit 06d696c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ const urlSanitizers = {
path: () => window.location.href.replace(/\?.*$/, ''),
};

const targetselector = (element) => {
let value = element.getAttribute('data-rum-target') || element.getAttribute('href')
const getTargetValue = (element) => element.getAttribute('data-rum-target') || element.getAttribute('href')
|| element.currentSrc || element.getAttribute('src') || element.dataset.action || element.action;

const targetselector = (element) => {
let value = getTargetValue(element);
if (!value && element.tagName !== 'A' && element.closest('a')) {
value = getTargetValue(element.closest('a'));
}
if (value && !value.startsWith('https://')) {
// resolve relative links
value = new URL(value, window.location).href;
Expand Down

0 comments on commit 06d696c

Please sign in to comment.