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

Commit

Permalink
Merge pull request #74 from MozillaSocial/fix/posts-nested-link-clicks
Browse files Browse the repository at this point in the history
fix(posts): track when users click links within posts [MOSOWEB-49]
  • Loading branch information
jpezninjo authored Nov 7, 2023
2 parents 7500fc2 + 2a9efae commit e854a27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/status/StatusLink.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="ts">
import type { mastodon } from 'masto'
import { engagement } from '~~/telemetry/generated/ui'
import { engagementDetails } from '~~/telemetry/engagementDetails'
const props = defineProps<{
status: mastodon.v1.Status
Expand All @@ -16,6 +18,13 @@ function onclick(evt: MouseEvent | KeyboardEvent) {
const text = window.getSelection()?.toString()
if (!el && !text)
go(evt)
const eventTarget = evt?.target as Element
const closestLink = eventTarget.closest('a')
if (closestLink) {
const ui_identifier = 'post.link.tap'
engagement.record({ ui_identifier, mastodon_status_id: props.status.id, ...engagementDetails[ui_identifier] })
}
}
function go(evt: MouseEvent | KeyboardEvent) {
Expand Down
2 changes: 2 additions & 0 deletions telemetry/engagementDetails.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { postEvents } from './engagementPostEvents'
import { profileEvents } from './engagementProfileEvents'

interface EngagementDetails {
Expand Down Expand Up @@ -35,5 +36,6 @@ export const engagementDetails: EngagementDetails = {
'nav.login': {
engagement_type: 'general',
},
...postEvents,
...profileEvents,
}
5 changes: 5 additions & 0 deletions telemetry/engagementPostEvents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const postEvents = {
'post.link.tap': {
engagement_type: 'general',
},
}

0 comments on commit e854a27

Please sign in to comment.