The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Only match similar emails against earlier customers
Rafi3d013cd9e0dc
diff --git a/apps/web/app/(ee)/api/workflows/create-partner-commission/route.ts b/apps/web/app/(ee)/api/workflows/create-partner-commission/route.tsindex afbe134295..f64664c833 100644--- a/apps/web/app/(ee)/api/workflows/create-partner-commission/route.ts+++ b/apps/web/app/(ee)/api/workflows/create-partner-commission/route.ts@@ -612,7 +612,7 @@ async function stepRunSideEffects("riskMonitoringDisabledAt",]),customer: {- ...pick(commission.customer!, ["id", "email", "name"]),+ ...pick(commission.customer!, ["id", "email", "name", "createdAt"]),// only pass along isFirstConversion if it's a boolean...(typeof isFirstConversion === "boolean" && { isFirstConversion }),},diff --git a/apps/web/lib/api/fraud/rules/check-customer-email-match.ts b/apps/web/lib/api/fraud/rules/check-customer-email-match.tsindex 2414563c66..9d61a308a6 100644--- a/apps/web/lib/api/fraud/rules/check-customer-email-match.ts+++ b/apps/web/lib/api/fraud/rules/check-customer-email-match.ts@@ -40,9 +40,11 @@ export const checkCustomerEmailMatch = defineFraudRule({("isFirstConversion" in customer && customer.isFirstConversion) ||!("isFirstConversion" in customer);- // 2. Similar email match: the customer's normalized email matches a- // customer referred by any partner in the same program, because variants- // of one inbox can come through different partners.+ // 2. Similar email match: the customer's normalized email matches an+ // earlier customer referred by any partner in the same program, because+ // variants of one inbox can come through different partners.+ // Only earlier customers count, so the partner who referred the original+ // address is not held when that customer converts later.// Require the raw emails to differ. Importers and promo-code attribution// can create duplicate rows for one address, and those should not count.if (shouldCheckHistoricalMatch) {@@ -51,8 +53,8 @@ export const checkCustomerEmailMatch = defineFraudRule({projectId: program.workspaceId,normalizedEmail: normalizedCustomerEmail,programId: program.id,- id: {- not: customer.id,+ createdAt: {+ lt: customer.createdAt,},email: {not: customer.email,diff --git a/apps/web/lib/zod/schemas/schemas.ts b/apps/web/lib/zod/schemas/schemas.tsindex ff9ab1996e..cf43b93c0e 100644--- a/apps/web/lib/zod/schemas/schemas.ts+++ b/apps/web/lib/zod/schemas/schemas.ts@@ -19,6 +19,7 @@ export const fraudEventContext = z.object({id: z.string(),email: z.string().nullable(),name: z.string().nullable(),+ createdAt: z.date(),isFirstConversion: z.boolean().nullish(),}),link: z.object({diff --git a/apps/web/tests/fraud/index.test.ts b/apps/web/tests/fraud/index.test.tsindex 7985506a6e..10062f970f 100644--- a/apps/web/tests/fraud/index.test.ts+++ b/apps/web/tests/fraud/index.test.ts@@ -257,6 +257,18 @@ describe.concurrent("/fraud/**", async () => {matchedCustomerId: firstCustomers[0].id,},});++ // Only the later variant is flagged, not the original customer+ const { status, data: firstCustomerEvents } = await http.get<unknown[]>({+ path: "/fraud/events",+ query: {+ customerId: firstCustomers[0].id,+ type: "customerEmailMatch",+ },+ });++ expect(status).toEqual(200);+ expect(firstCustomerEvents).toEqual([]);});test("FraudRuleType = customerEmailSuspiciousDomain", async () => {