Skip to content

Commit

Permalink
adding focus handler for form elements
Browse files Browse the repository at this point in the history
  • Loading branch information
vdua committed Dec 12, 2024
1 parent 33aca1e commit 04631ff
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,21 @@ function addViewMediaTracking(parent) {
}
}

function addFocusTracking(parent) {
parent.addEventListener('focusin', (event) => {
if (['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'].includes(event.target.tagName)
|| event.target.getAttribute('contenteditable') === 'true') {
sampleRUM('click', { source: sourceSelector(event.target) });
}
});
}

function addFormTracking(parent) {
activateBlocksMO();
activateMediaMO();
parent.querySelectorAll('form').forEach((form) => {
form.addEventListener('submit', (e) => sampleRUM('formsubmit', { target: targetSelector(e.target), source: sourceSelector(e.target) }), { once: true });
addFocusTracking(form);
});
}

Expand Down

0 comments on commit 04631ff

Please sign in to comment.