The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Polyfill workspace_id in case it's not defined (#3004)
Steven Tey7b448f7ab208
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.tsindex 07bc3e8866..fcc8153a77 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@@ -138,6 +138,7 @@ export async function checkoutSessionCompleted(const { timestamp, ...rest } = clickEvent;leadEvent = {...rest,+ workspace_id: clickEvent.workspace_id || customer.projectId, // in case for some reason the click event doesn't have workspace_idevent_id: nanoid(16),event_name: "Sign up",customer_id: customer.id,@@ -321,6 +322,7 @@ export async function checkoutSessionCompleted(const saleData = {...leadEvent,+ workspace_id: leadEvent.workspace_id || customer.projectId, // in case for some reason the lead event doesn't have workspace_idevent_id: nanoid(16),// if the charge is a one-time payment, we set the event name to "Purchase"event_name:@@ -623,6 +625,7 @@ async function attributeViaPromoCode({const leadEvent = {...rest,+ workspace_id: clickEvent.workspace_id || customer.projectId, // in case for some reason the click event doesn't have workspace_idevent_id: nanoid(16),event_name: "Sign up",customer_id: customer.id,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.tsindex 26c5dcfcdb..76bb0694d3 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@@ -126,6 +126,7 @@ export async function invoicePaid(event: Stripe.Event, mode: StripeMode) {const saleData = {...leadEvent.data[0],+ workspace_id: leadEvent.data[0].workspace_id || customer.projectId, // in case for some reason the lead event doesn't have workspace_idevent_id: eventId,event_name: isOneTimePayment ? "Purchase" : "Invoice paid",payment_processor: "stripe",diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.tsindex 0c5b267476..d97d574442 100644--- a/apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts@@ -64,6 +64,7 @@ export async function createNewCustomer(event: Stripe.Event) {const leadData = {...clickData,+ workspace_id: clickData.workspace_id || customer.projectId, // in case for some reason the click event doesn't have workspace_idevent_id: nanoid(16),event_name: eventName,customer_id: customer.id,diff --git a/apps/web/lib/api/conversions/track-lead.ts b/apps/web/lib/api/conversions/track-lead.tsindex fcad1339d6..237718fae3 100644--- a/apps/web/lib/api/conversions/track-lead.ts+++ b/apps/web/lib/api/conversions/track-lead.ts@@ -141,6 +141,7 @@ export const trackLead = async ({const createLeadEventPayload = (customerId: string) => {const basePayload = {...clickData,+ workspace_id: clickData.workspace_id || workspace.id, // in case for some reason the click event doesn't have workspace_idevent_id: leadEventId,event_name: eventName,customer_id: customerId,diff --git a/apps/web/lib/api/conversions/track-sale.ts b/apps/web/lib/api/conversions/track-sale.tsindex 1944fe2fe5..7e4297b08b 100644--- a/apps/web/lib/api/conversions/track-sale.ts+++ b/apps/web/lib/api/conversions/track-sale.ts@@ -125,9 +125,15 @@ export const trackSale = async ({});}- leadEventData = cachedLeadEvent;+ leadEventData = {+ ...cachedLeadEvent,+ workspace_id: cachedLeadEvent.workspace_id || workspace.id, // in case for some reason the lead event doesn't have workspace_id+ };} else {- leadEventData = leadEvent.data[0];+ leadEventData = {+ ...leadEvent.data[0],+ workspace_id: leadEvent.data[0].workspace_id || workspace.id, // in case for some reason the lead event doesn't have workspace_id+ };}}@@ -300,7 +306,10 @@ const _trackLead = async ({(async () => {const [_leadEvent, link, _workspace] = await Promise.all([// Record the lead event for the customer- recordLead(leadEventData),+ recordLead({+ ...leadEventData,+ workspace_id: leadEventData.workspace_id || workspace.id, // in case for some reason the lead event doesn't have workspace_id+ }),// Update link leads count + lastLeadAt dateprisma.link.update({@@ -419,6 +428,7 @@ const _trackSale = async ({const saleData = {...leadEventData,+ workspace_id: leadEventData.workspace_id || workspace.id, // in case for some reason the lead event doesn't have workspace_idevent_id: nanoid(16),event_name: eventName,customer_id: customer.id,diff --git a/apps/web/lib/integrations/shopify/create-lead.ts b/apps/web/lib/integrations/shopify/create-lead.tsindex 6f0f083c7a..b12ca86a11 100644--- a/apps/web/lib/integrations/shopify/create-lead.ts+++ b/apps/web/lib/integrations/shopify/create-lead.ts@@ -65,6 +65,7 @@ export async function createShopifyLead({const leadData = leadEventSchemaTB.parse({...clickData,+ workspace_id: clickData.workspace_id || customer.projectId, // in case for some reason the click event doesn't have workspace_idevent_id: nanoid(16),event_name: eventName,customer_id: customer.id,diff --git a/apps/web/lib/integrations/shopify/create-sale.ts b/apps/web/lib/integrations/shopify/create-sale.tsindex 37bda6f8b6..eabefabb37 100644--- a/apps/web/lib/integrations/shopify/create-sale.ts+++ b/apps/web/lib/integrations/shopify/create-sale.ts@@ -55,6 +55,7 @@ export async function createShopifySale({const saleData = {...leadData,+ workspace_id: leadData.workspace_id || workspaceId, // in case for some reason the lead event doesn't have workspace_idevent_id: nanoid(16),event_name: "Purchase",payment_processor: "shopify",