Skip to content

feat: add PostHog tracking for onboarding CTA interactions#3362

Merged
rachellougee merged 2 commits into
mainfrom
onboarding-posthog-tracking
May 20, 2026
Merged

feat: add PostHog tracking for onboarding CTA interactions#3362
rachellougee merged 2 commits into
mainfrom
onboarding-posthog-tracking

Conversation

@rachellougee
Copy link
Copy Markdown
Contributor

What are the relevant tickets?

https://github.com/mitodl/hq/issues/10916#issuecomment-4499456757

Description (What does it do?)

adds PostHog tracking for onboarding CTA interactions

Screenshots (if appropriate):

image

How can this be tested?

image
  • Confirm the event contains the following data attribute
image

Additional Context

Copilot AI review requested due to automatic review settings May 20, 2026 17:51
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

OpenAPI Changes

No changes detected

View full changelog

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds PostHog analytics instrumentation to the onboarding flow so onboarding CTA interactions (Next/Finish) emit a standardized cta_clicked event with step context, aligning onboarding tracking with existing CTA tracking patterns elsewhere in frontends/main.

Changes:

  • Capture PostHogEvents.CallToActionClicked on onboarding form submission with { label, step, location: "onboarding" }, gated by NEXT_PUBLIC_POSTHOG_API_KEY.
  • Add Jest/RTL test coverage to verify event payloads for both “Next” and “Finish”, and verify no capture when PostHog is not configured.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
frontends/main/src/app-pages/OnboardingPage/OnboardingPage.tsx Emits cta_clicked on onboarding Next/Finish submissions with step + location metadata.
frontends/main/src/app-pages/OnboardingPage/OnboardingPage.test.tsx Adds tests that mock PostHog and assert capture behavior/payload (and gating when env var is unset).

onSubmit: async (values) => {
const label = activeStep < NUM_STEPS - 1 ? "Next" : "Finish"
if (process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {
posthog.capture(PostHogEvents.CallToActionClicked, {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

posthog.capture fires before mutateAsync, so if the mutation throws and error the event is already recorded even though the step wasn't actually completed. Quick fix just move this after:

      if (formik.dirty) {
        await mutateAsync({
          ...values,
          topic_interests: values.topic_interests.map((id) => parseInt(id)),
        })
      }

validationSchema: ProfileSchema,
onSubmit: async (values) => {
const label = activeStep < NUM_STEPS - 1 ? "Next" : "Finish"
if (process.env.NEXT_PUBLIC_POSTHOG_API_KEY) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure you need this guard here. posthog.capture is safe to call unconditionally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I kept it here because Copilot pointed out in my first PR that this PostHog capture isn’t guarded by NEXT_PUBLIC_POSTHOG_API_KEY, while most other captures in frontends/main check that env var before calling posthog.capture.”. I don’t think that guard is necessary.

#3218 (comment)

Copy link
Copy Markdown
Contributor

@daniellefrappier18 daniellefrappier18 left a comment

Choose a reason for hiding this comment

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

See my comment about timing but otherwise looks good.

@rachellougee rachellougee merged commit 2cf23ad into main May 20, 2026
13 checks passed
@rachellougee rachellougee deleted the onboarding-posthog-tracking branch May 20, 2026 21:21
This was referenced May 21, 2026
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.

3 participants