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

fix(posts): track when users click links within posts [MOSOWEB-49] #74

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Author

@jpezninjo jpezninjo Oct 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth wondering if it would be safer to place the analytics call before this go to future-proof for links changing to redirects instead of opening in new tab?

This train of thought stems from login/signup button clicks intermittently failing to show up on the debug tool (probably due to doing redirects)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to discern when the go function gets called? I haven't been able to figure it out.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wtfluckey Yup. When you click on a post in a feed and it takes you to the url for the standalone post.


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',
},
}
Loading