-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
![](https://user-images.githubusercontent.com/14023085/277800121-b590ffdf-00d6-4091-8da1-031336008d38.png)
<span>
in an<a>