From 2a733b307d00c1a0613f645a01e325e683734625 Mon Sep 17 00:00:00 2001 From: Sean Steimer Date: Mon, 8 Apr 2024 09:32:56 -0700 Subject: [PATCH] feat: add logic to capture target from wrapping anchor tag --- package-lock.json | 4 ++-- src/index.js | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index c83d242..a9f5c96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@adobe/helix-rum-enhancer", - "version": "2.4.0", + "version": "2.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@adobe/helix-rum-enhancer", - "version": "2.4.0", + "version": "2.4.1", "license": "Apache-2.0", "devDependencies": { "@adobe/eslint-config-helix": "2.0.6", diff --git a/src/index.js b/src/index.js index 8563c73..2c93190 100644 --- a/src/index.js +++ b/src/index.js @@ -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;