Skip to content

Commit ed2625f

Browse files
authored
feat: add signup source tag (#1715)
Adds source tag to workspace created event to identify where the users where signed up from.
1 parent c635826 commit ed2625f

File tree

9 files changed

+23
-1
lines changed

9 files changed

+23
-1
lines changed

apps/web/src/actions/user/setupAction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const setupAction = errorHandlingProcedure
1616
async () => {
1717
return z.object({
1818
returnTo: z.string().optional(),
19+
source: z.string().optional(),
1920
name: z.string().min(1, { message: 'Name is a required field' }),
2021
email: z
2122
.string()

apps/web/src/app/(public)/setup/SetupForm/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ export default function SetupForm({
1818
name,
1919
companyName,
2020
footer,
21+
source,
2122
returnTo,
2223
}: {
2324
footer: ReactNode
2425
email?: string
2526
name?: string
2627
companyName?: string
28+
source?: string
2729
returnTo?: string
2830
}) {
2931
const { toast } = useToast()
@@ -43,6 +45,7 @@ export default function SetupForm({
4345
return (
4446
<form action={action}>
4547
<input type='hidden' name='returnTo' value={returnTo} />
48+
<input type='hidden' name='source' value={source} />
4649
<FormWrapper>
4750
<Input
4851
autoFocus

apps/web/src/app/(public)/setup/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ export default async function SetupPage({
2323
name?: string
2424
companyName?: string
2525
returnTo?: string
26+
source?: string
2627
}>
2728
}) {
28-
const { email, name, companyName, returnTo } = await searchParams
29+
const { email, name, companyName, source, returnTo } = await searchParams
2930

3031
return (
3132
<FocusLayout
@@ -44,6 +45,7 @@ export default async function SetupPage({
4445
name={name}
4546
companyName={companyName}
4647
footer={<AuthFooter />}
48+
source={source}
4749
returnTo={returnTo}
4850
/>
4951
</CardContent>

apps/web/src/services/user/setupService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ export default function setupService({
66
email,
77
name,
88
companyName,
9+
source,
910
importDefaultProject = env.IMPORT_DEFAULT_PROJECT,
1011
}: {
1112
email: string
1213
name: string
1314
companyName: string
15+
source?: string
1416
importDefaultProject?: boolean
1517
}) {
1618
return setupServiceFn({
1719
email,
1820
name,
1921
companyName,
22+
source,
2023
defaultProviderName: env.NEXT_PUBLIC_DEFAULT_PROVIDER_NAME,
2124
defaultProviderApiKey: env.DEFAULT_PROVIDER_API_KEY,
2225
captureException,

packages/core/src/events/events.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export type WorkspaceCreatedEvent = LatitudeEventGeneric<
158158
user: User
159159
userEmail: string
160160
workspaceId: number
161+
source: string
161162
}
162163
>
163164

packages/core/src/lib/analytics/AnalyticsClient.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe('AnalyticsClient', () => {
122122
event: {
123123
type: 'workspaceCreated',
124124
data: {
125+
source: 'default',
125126
workspace: {} as Workspace, // Not really
126127
user,
127128
workspaceId: 123,
@@ -163,6 +164,7 @@ describe('AnalyticsClient', () => {
163164
event: {
164165
type: 'workspaceCreated',
165166
data: {
167+
source: 'default',
166168
workspace,
167169
user,
168170
workspaceId: workspace.id,
@@ -204,6 +206,7 @@ describe('AnalyticsClient', () => {
204206
event: {
205207
type: 'workspaceCreated',
206208
data: {
209+
source: 'default',
207210
workspace,
208211
user,
209212
workspaceId: workspace.id,
@@ -229,6 +232,7 @@ describe('AnalyticsClient', () => {
229232
event: {
230233
type: 'workspaceCreated',
231234
data: {
235+
source: 'default',
232236
workspace,
233237
user,
234238
workspaceId: workspace.id,
@@ -256,6 +260,7 @@ describe('AnalyticsClient', () => {
256260
event: {
257261
type: 'workspaceCreated',
258262
data: {
263+
source: 'default',
259264
workspace,
260265
user,
261266
workspaceId: workspace.id,

packages/core/src/services/users/setupService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ export default async function setupService(
2626
defaultProviderName,
2727
defaultProviderApiKey,
2828
captureException,
29+
source,
2930
importDefaultProject = env.IMPORT_DEFAULT_PROJECT,
3031
}: {
3132
email: string
3233
name: string
3334
companyName: string
3435
defaultProviderName: string
3536
defaultProviderApiKey: string
37+
source?: string
3638
captureException?: (error: Error) => void
3739
importDefaultProject?: boolean
3840
},
@@ -46,6 +48,7 @@ export default async function setupService(
4648
{
4749
name: companyName,
4850
user,
51+
source,
4952
},
5053
transaction,
5154
).then((r) => r.unwrap())

packages/core/src/services/workspaces/create.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ export async function createWorkspace(
1313
name,
1414
user,
1515
createdAt,
16+
source = 'default',
1617
subscriptionPlan = SubscriptionPlan.HobbyV2,
1718
}: {
1819
name: string
1920
user: User
21+
source?: string
2022
createdAt?: Date
2123
subscriptionPlan?: SubscriptionPlan
2224
},
@@ -59,6 +61,7 @@ export async function createWorkspace(
5961
data: {
6062
workspace: w,
6163
user,
64+
source,
6265
workspaceId: w.id,
6366
userEmail: user.email,
6467
},

packages/core/src/tests/factories/workspaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type ICreateWorkspace = {
1313
creator?: User | ICreateUser
1414
createdAt?: Date
1515
subscriptionPlan?: SubscriptionPlan
16+
source?: string
1617
onboarding?: boolean
1718
features?: string[]
1819
}

0 commit comments

Comments
 (0)