Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
fix(analytics): refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jpezninjo committed Oct 26, 2023
1 parent 9ab44fd commit 5586dd0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions modules/glean/runtime/glean-plugin.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,21 @@ export default defineNuxtPlugin((nuxtApp) => {
if (!element)
return

if (!element.hasAttribute('data-glean'))
return

const data = element.getAttribute('data-glean') || ''
if (element.hasAttribute('data-glean')) {
const value = element.getAttribute('data-glean-value') || ''
engagement.record({ ui_identifier: data, engagement_value: value, ...engagementDetails[data] })
}
const value = element.getAttribute('data-glean-value') || ''
engagement.record({ ui_identifier: data, engagement_value: value, ...engagementDetails[data] })
}

function handleButtonClick(ev: MouseEvent) {
const eventTarget = ev?.target as Element
const closestButton = eventTarget.closest('button')

if (!closestButton)
return

if (closestButton?.hasAttribute('href'))
linkClick.record({ target_url: closestButton.getAttribute('href') || '' })

Expand All @@ -57,10 +61,13 @@ export default defineNuxtPlugin((nuxtApp) => {
function handleLinkClick(ev: MouseEvent) {
const eventTarget = ev?.target as Element
const closestLink = eventTarget.closest('a')
if (closestLink) {
linkClick.record({ target_url: closestLink.getAttribute('href') || '' })
recordEngagement(closestLink)
}

if (!closestLink)
return

linkClick.record({ target_url: closestLink.getAttribute('href') || '' })

recordEngagement(closestLink)
}

window.addEventListener('click', eventListener)
Expand Down

0 comments on commit 5586dd0

Please sign in to comment.