Skip to content

BDMS-857: PostHog analytics additions — search recording, copy/paste tracking, accessibility props#291

Open
jeremyzilar wants to merge 1 commit into
stagingfrom
BDMS-857-posthog-additions
Open

BDMS-857: PostHog analytics additions — search recording, copy/paste tracking, accessibility props#291
jeremyzilar wants to merge 1 commit into
stagingfrom
BDMS-857-posthog-additions

Conversation

@jeremyzilar

Copy link
Copy Markdown
Contributor

Why

Three small instrumentation additions to improve what we can see in PostHog session recordings and the person/event data.

What changed

1. Search text in session recordings

SearchModal.tsx now adds className: 'ph-no-mask' to the search input instead of the previous data-posthog-unmask-search attribute. ph-no-mask is PostHog's standard class for opting inputs out of masking.

The custom maskInputFn in posthog.ts was updated to check for ph-no-mask (class on element or ancestor) so it respects the standard approach.

2. Copy/paste tracking

New src/hooks/useCopyPasteTracking.ts attaches document-level copy, cut, and paste listeners. Fires two events:

  • text_copied — properties: path, selection_length
  • text_pasted — properties: path

No actual copied or pasted text is captured.

Wired up via a new renderless src/components/analytics/CopyPasteTracking.tsx component mounted in AppProviders.tsx.

3. Browser accessibility preferences

New getAccessibilityProps() in posthog.ts reads five values from the browser once per session:

  • browser_font_size_px
  • font_size_increased (true if root font size > 16px)
  • device_pixel_ratio
  • prefers_reduced_motion
  • prefers_high_contrast

PostHogIdentify.tsx now calls setPersonProperties(getAccessibilityProps()) immediately after the user is identified so the values are stored on the PostHog person record.

Notes

  • No behaviour changes, only instrumentation
  • TypeScript builds cleanly with no errors

…y props to PostHog

1. Search recording: replace data-posthog-unmask-search attribute with ph-no-mask
   CSS class on the search input in SearchModal. Update maskInputFn in posthog.ts
   to check for ph-no-mask so the custom masking function respects the standard class.

2. Copy/paste tracking: new useCopyPasteTracking hook attaches document-level
   listeners for copy, cut, and paste events. Fires text_copied (with path and
   selection_length) and text_pasted (with path). No actual text is captured.
   Wired up via a new renderless CopyPasteTracking component mounted in AppProviders.

3. Accessibility preferences: new getAccessibilityProps() in posthog.ts reads
   browser_font_size_px, font_size_increased, device_pixel_ratio,
   prefers_reduced_motion, and prefers_high_contrast once per session.
   PostHogIdentify now calls setPersonProperties(getAccessibilityProps()) after
   the user is identified so the values are attached to the person record.
@github-actions

Copy link
Copy Markdown

Preview Deployment

Preview URL: https://preview-bdms-857-posthog-additions-auejgdbofq-uc.a.run.app

Note: This preview uses the staging API endpoints.

@chasetmartin chasetmartin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good @jeremyzilar, just one comment. My only broad question is: why collect copy paste events? Have you found that helpful in other applications for signs that a user is making their own shortcuts?

}

const handleCut = () => {
captureEvent('text_copied', {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do you want this to be text_cut so that it can be registered as it's own event outside of a copy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants