-
Notifications
You must be signed in to change notification settings - Fork 7
fix(analytics): capture engagement events on children of <a>'s #73
Conversation
|
||
linkClick.record({ target_url: closestLink.getAttribute('href') || '' }) | ||
|
||
recordEngagement(closestLink) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capturing of links engagement happens here
function handleButtonClick(ev: MouseEvent) { | ||
const eventTarget = ev?.target as Element | ||
const closestButton = eventTarget.closest('button') | ||
|
||
if (!closestButton) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guard is a functional change. Currently, handleButtonClick
captures engagement events on any element. Adding this guard is needed to prevent duplicate events from both here and handleLinkClick
for clicks on links.
cc @wtfluckey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love it
@@ -33,24 +33,41 @@ export default defineNuxtPlugin((nuxtApp) => { | |||
} | |||
} | |||
|
|||
function recordEngagement(element: Element) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
broke out the code in handleButtonClick
to this re-usable function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used early returns instead of if-statements and optional chaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense to me!
Goal: clicking on any part of a link should trigger engagement events.
Currently, our code is not setup to handle clicks on children of an anchor
<a>
tag.This PR is a follow up improvement to #67 (comment)
To Do:
Image showing the bounding box of a nested
<span>
in an<a>