We need to add server-side PostHog tracking to monitor key user events within our application. The specific events to track are:
New Pull Requests Created: When a new pull request is created in the repository.
New Tasks Started: When a user starts a new task. Refer to the TRPC procedures in /src/server/api/routers/ for integration points.
New Todos Created: When a new todo item is added to the system.
Adding this tracking will help us understand user engagement and behavior, enabling us to improve the application based on data-driven insights.
Expected Outcome
PostHog is configured to capture the specified server-side events.
The tracking code is implemented in the appropriate server-side modules handling these events.
Events are successfully sent to PostHog with relevant data (e.g., user ID, timestamp, related entities).
The implementation follows best practices for event tracking without affecting application performance.
All existing tests pass, and new tests are added if necessary to cover the tracking functionality.
Additional Information
Check /src/server/analytics/posthog.ts for existing PostHog configuration.
Ensure compliance with user privacy policies when collecting and sending data.
@jacob-ai-bot --skip-build
Plan:
Step 1: Edit /src/server/github/pr.ts
Task: Add PostHog tracking to pull request creation
Instructions:
In the file /src/server/github/pr.ts, within the createPR function, after a pull request is successfully created (after the octokit.pulls.create call), import posthogClient from /src/server/analytics/posthog.ts if not already imported. Then, add a PostHog event capture using posthogClient.capture. The event should be named "Pull Request Created" and include properties such as repository.full_name (repository name), result.data.number (pull request number), title (pull request title), and any other relevant data like the user ID if available.
Exit Criteria:
A PostHog event named "Pull Request Created" is sent whenever a new pull request is created, including the repository name, pull request number, title, and relevant user information.
Step 2: Edit /src/server/utils/events.ts
Task: Add PostHog tracking when a new task is started
Instructions:
In the file /src/server/utils/events.ts, within the emitTaskEvent function, import posthogClient from /src/server/analytics/posthog.ts if not already imported. When emitting a task event with status equal to TaskStatus.IN_PROGRESS (indicating a new task has started), add a PostHog event capture using posthogClient.capture. The event should be named "Task Started" and include properties such as the taskId, issueId, userId from baseEventData.userId, projectId from baseEventData.projectId, subType (task subtype), and any other relevant data.
Exit Criteria:
A PostHog event named "Task Started" is sent whenever a new task is started, including task ID, issue ID, user ID, project ID, and task subtype.
Step 3: Edit /src/server/api/routers/todos.ts
Task: Add PostHog tracking to new todo creation
Instructions:
In the file /src/server/api/routers/todos.ts, within the create mutation of the todoRouter, after a new todo item is successfully created, import posthogClient from /src/server/analytics/posthog.ts if not already imported. Add a PostHog event capture using posthogClient.capture. The event should be named "Todo Created" and include properties such as todo.id (the ID of the newly created todo), input.projectId, input.name, input.status, and any other relevant data. If the user ID is available in the context, include it as well.
Exit Criteria:
A PostHog event named "Todo Created" is sent whenever a new todo is created, including the todo ID, project ID, name, status, and user ID if available.
Summary:
Description
We need to add server-side PostHog tracking to monitor key user events within our application. The specific events to track are:
/src/server/api/routers/
for integration points.Adding this tracking will help us understand user engagement and behavior, enabling us to improve the application based on data-driven insights.
Expected Outcome
Additional Information
/src/server/analytics/posthog.ts
for existing PostHog configuration.Plan:
Step 1: Edit
/src/server/github/pr.ts
Task: Add PostHog tracking to pull request creation
Instructions: In the file
/src/server/github/pr.ts
, within thecreatePR
function, after a pull request is successfully created (after theoctokit.pulls.create
call), importposthogClient
from/src/server/analytics/posthog.ts
if not already imported. Then, add a PostHog event capture usingposthogClient.capture
. The event should be named "Pull Request Created" and include properties such asrepository.full_name
(repository name),result.data.number
(pull request number),title
(pull request title), and any other relevant data like the user ID if available.Exit Criteria: A PostHog event named "Pull Request Created" is sent whenever a new pull request is created, including the repository name, pull request number, title, and relevant user information.
Step 2: Edit
/src/server/utils/events.ts
Task: Add PostHog tracking when a new task is started
Instructions: In the file
/src/server/utils/events.ts
, within theemitTaskEvent
function, importposthogClient
from/src/server/analytics/posthog.ts
if not already imported. When emitting a task event withstatus
equal toTaskStatus.IN_PROGRESS
(indicating a new task has started), add a PostHog event capture usingposthogClient.capture
. The event should be named "Task Started" and include properties such as thetaskId
,issueId
,userId
frombaseEventData.userId
,projectId
frombaseEventData.projectId
,subType
(task subtype), and any other relevant data.Exit Criteria: A PostHog event named "Task Started" is sent whenever a new task is started, including task ID, issue ID, user ID, project ID, and task subtype.
Step 3: Edit
/src/server/api/routers/todos.ts
Task: Add PostHog tracking to new todo creation
Instructions: In the file
/src/server/api/routers/todos.ts
, within thecreate
mutation of thetodoRouter
, after a new todo item is successfully created, importposthogClient
from/src/server/analytics/posthog.ts
if not already imported. Add a PostHog event capture usingposthogClient.capture
. The event should be named "Todo Created" and include properties such astodo.id
(the ID of the newly created todo),input.projectId
,input.name
,input.status
, and any other relevant data. If the user ID is available in the context, include it as well.Exit Criteria: A PostHog event named "Todo Created" is sent whenever a new todo is created, including the todo ID, project ID, name, status, and user ID if available.