diff --git a/apps/web/utils/auth.ts b/apps/web/utils/auth.ts index 505a460843..423022d7b6 100644 --- a/apps/web/utils/auth.ts +++ b/apps/web/utils/auth.ts @@ -146,20 +146,36 @@ async function handleSignIn({ isNewUser: boolean; }) { if (isNewUser && user.email) { - const loops = createLoopsContact( - user.email, - user.name?.split(" ")?.[0], - ).catch((error) => { - const alreadyExists = - error instanceof Error && error.message.includes("409"); - if (!alreadyExists) { - logger.error("Error creating Loops contact", { - email: user.email, - error, + const loops = async () => { + const account = await prisma.account + .findFirst({ + where: { userId: user.id }, + select: { provider: true }, + }) + .catch((error) => { + logger.error("Error finding account", { + userId: user.id, + error, + }); + captureException(error, undefined, user.email); }); - captureException(error, undefined, user.email); - } - }); + + await createLoopsContact( + user.email, + user.name?.split(" ")?.[0], + account?.provider, + ).catch((error) => { + const alreadyExists = + error instanceof Error && error.message.includes("409"); + if (!alreadyExists) { + logger.error("Error creating Loops contact", { + email: user.email, + error, + }); + captureException(error, undefined, user.email); + } + }); + }; const resend = createResendContact({ email: user.email }).catch((error) => { logger.error("Error creating Resend contact", { @@ -177,7 +193,7 @@ async function handleSignIn({ captureException(error, undefined, user.email); }); - await Promise.all([loops, resend, dub]); + await Promise.all([loops(), resend, dub]); } if (isNewUser && user.email && user.id) { diff --git a/packages/loops/src/loops.ts b/packages/loops/src/loops.ts index 47f67b999d..4b92ae565c 100644 --- a/packages/loops/src/loops.ts +++ b/packages/loops/src/loops.ts @@ -16,19 +16,18 @@ function getLoopsClient(): LoopsClient | undefined { export async function createContact( email: string, firstName?: string, + provider?: string, ): Promise<{ success: boolean; id?: string; }> { const loops = getLoopsClient(); if (!loops) return { success: false }; - // so we can run a/b tests with 2-6 groups easily - const abTestId = getRandomInt(60); - const resp = await loops.createContact({ - email, - properties: firstName ? { firstName, abTestId } : { abTestId }, - }); - return resp; + const properties: Record = {}; + if (firstName) properties.firstName = firstName; + if (provider) properties.provider = provider; + + return await loops.createContact({ email, properties }); } export async function deleteContact( @@ -36,8 +35,7 @@ export async function deleteContact( ): Promise<{ success: boolean }> { const loops = getLoopsClient(); if (!loops) return { success: false }; - const resp = await loops.deleteContact({ email }); - return resp; + return await loops.deleteContact({ email }); } export async function startedTrial( @@ -46,13 +44,12 @@ export async function startedTrial( ): Promise<{ success: boolean }> { const loops = getLoopsClient(); if (!loops) return { success: false }; - const resp = await loops.sendEvent({ + return await loops.sendEvent({ eventName: "upgraded", email, contactProperties: { tier }, eventProperties: { tier }, }); - return resp; } export async function completedTrial( @@ -61,13 +58,12 @@ export async function completedTrial( ): Promise<{ success: boolean }> { const loops = getLoopsClient(); if (!loops) return { success: false }; - const resp = await loops.sendEvent({ + return await loops.sendEvent({ eventName: "completed_trial", email, contactProperties: { tier }, eventProperties: { tier }, }); - return resp; } export async function switchedPremiumPlan( @@ -76,13 +72,12 @@ export async function switchedPremiumPlan( ): Promise<{ success: boolean }> { const loops = getLoopsClient(); if (!loops) return { success: false }; - const resp = await loops.sendEvent({ + return await loops.sendEvent({ eventName: "switched_premium_plan", email, contactProperties: { tier }, eventProperties: { tier }, }); - return resp; } export async function cancelledPremium( @@ -90,12 +85,11 @@ export async function cancelledPremium( ): Promise<{ success: boolean }> { const loops = getLoopsClient(); if (!loops) return { success: false }; - const resp = await loops.sendEvent({ + return await loops.sendEvent({ eventName: "cancelled", email, contactProperties: { tier: "" }, }); - return resp; } async function updateContactProperty( @@ -105,11 +99,10 @@ async function updateContactProperty( const loops = getLoopsClient(); if (!loops) return { success: false }; - const resp = await loops.updateContact({ + return await loops.updateContact({ email, properties, }); - return resp; } export async function updateContactRole({ @@ -131,7 +124,3 @@ export async function updateContactCompanySize({ }) { return updateContactProperty(email, { companySize }); } - -function getRandomInt(max: number) { - return Math.ceil(Math.random() * max); -} diff --git a/version.txt b/version.txt index 4f3f1706c5..b686217ba5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v2.17.5 +v2.17.6