Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Improve net-new revenue bounty logic (#3986)

Steven Tey34821bc51500
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts
index dfc8b54696..97dce7aa39 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts
@@ -535,11 +535,13 @@ export async function checkoutSessionCompleted(
workspaceId: workspace.id,
programId: link.programId,
partnerId: link.partnerId,
+ customerId: customer.id,
+ customerFirstSaleAt: customer.firstSaleAt ?? new Date(),
},
metrics: {
current: {
- saleAmount: saleData.amount,
conversions: firstConversionFlag ? 1 : 0,
+ saleAmount: saleData.amount,
},
},
}),
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts
index 9bb6f3d482..13e1aaf95d 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts
@@ -369,11 +369,13 @@ export async function invoicePaid(
workspaceId: workspace.id,
programId: link.programId,
partnerId: link.partnerId,
+ customerId: customer.id,
+ customerFirstSaleAt: customer.firstSaleAt ?? new Date(),
},
metrics: {
current: {
- saleAmount: saleData.amount,
conversions: firstConversionFlag ? 1 : 0,
+ saleAmount: saleData.amount,
},
},
}),
diff --git a/apps/web/lib/api/conversions/track-sale.ts b/apps/web/lib/api/conversions/track-sale.ts
index f8661c4f80..8aaf9fa9ba 100644
--- a/apps/web/lib/api/conversions/track-sale.ts
+++ b/apps/web/lib/api/conversions/track-sale.ts
@@ -506,11 +506,13 @@ const _trackSale = async ({
workspaceId: workspace.id,
programId: link.programId,
partnerId: link.partnerId,
+ customerId: customer.id,
+ customerFirstSaleAt: customer.firstSaleAt ?? new Date(),
},
metrics: {
current: {
- saleAmount: saleData.amount,
conversions: firstConversionFlag ? 1 : 0,
+ saleAmount: saleData.amount,
},
},
}),
diff --git a/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
index 60f8409490..c3259c1adf 100644
--- a/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
+++ b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
@@ -38,7 +38,7 @@ export const executeCompleteBountyWorkflow = async ({
const { bountyId } = action.data;
const { identity, metrics } = context;
- const { partnerId, groupId } = identity;
+ const { partnerId, groupId, customerId, customerFirstSaleAt } = identity;
if (!groupId) {
console.error("Partner groupId not set in the context.");
@@ -118,6 +118,17 @@ export const executeCompleteBountyWorkflow = async ({
}
}
+ if (
+ bounty.performanceScope === "new" &&
+ customerFirstSaleAt &&
+ customerFirstSaleAt < bounty.startsAt
+ ) {
+ console.log(
+ `Bounty ${bounty.id} is for net-new revenue only and partner ${partnerId} referred customer ${customerId} before the bounty started, skipping...`,
+ );
+ return;
+ }
+
console.log(
`Partner is eligible for bounty ${bounty.id}, executing workflow ${bounty.workflowId}...`,
);
diff --git a/apps/web/lib/integrations/shopify/create-sale.ts b/apps/web/lib/integrations/shopify/create-sale.ts
index 3b89c4e8ca..b408deb7c1 100644
--- a/apps/web/lib/integrations/shopify/create-sale.ts
+++ b/apps/web/lib/integrations/shopify/create-sale.ts
@@ -172,11 +172,13 @@ export async function createShopifySale({
workspaceId: workspaceId,
programId: link.programId,
partnerId: link.partnerId,
+ customerId: customer.id,
+ customerFirstSaleAt: customer.firstSaleAt ?? new Date(),
},
metrics: {
current: {
- saleAmount: saleData.amount,
conversions: firstConversionFlag ? 1 : 0,
+ saleAmount: saleData.amount,
},
},
}),
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 0f5b07a7b1..034008e7d1 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -848,6 +848,8 @@ interface WorkflowIdentity {
programId: string;
partnerId: string;
groupId?: string;
+ customerId?: string;
+ customerFirstSaleAt?: Date;
}
interface PartnerMetrics {