Skip to content

Commit

Permalink
capture user created events
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfcosta committed Dec 18, 2024
1 parent 40c66ee commit 1abf64a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apps/api/src/events/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,18 @@ export const captureCreateSchedule = async (
},
})
}

export const captureUserAdded = async (
newUser: ApiUser,
workspaceId: string
) => {
const posthog = getPostHogClient()
posthog?.capture({
distinctId: newUser.id,
event: 'user_created',
properties: {
userId: newUser.id,
workspaceId: workspaceId,
},
})
}
2 changes: 2 additions & 0 deletions apps/api/src/v1/workspaces/workspace/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { validate } from 'uuid'
import { generatePassword, hashPassword } from '../../../../password.js'
import { hasWorkspaceRoles } from '../../../../auth/token.js'
import { isUserNameValid } from '../../../../utils/validation.js'
import { captureUserCreated } from '../../../../events/posthog.js'

const usersRouter = Router({ mergeParams: true })

Expand Down Expand Up @@ -64,6 +65,7 @@ usersRouter.post('/', isAdmin, async (req, res) => {
}

await addUserToWorkspace(invitee.id, workspaceId, result.data.role)
captureUserCreated(invitee, workspace.id)

res.json({
...invitee,
Expand Down

0 comments on commit 1abf64a

Please sign in to comment.