The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Attribute Shopify orders from note_attributes dubClickId without waiting for pixel.
Kiran K07311f592c8e
diff --git a/apps/web/app/(ee)/api/shopify/integration/webhook/orders-paid.ts b/apps/web/app/(ee)/api/shopify/integration/webhook/orders-paid.tsindex 1c16fce161..f97d4b53d0 100644--- a/apps/web/app/(ee)/api/shopify/integration/webhook/orders-paid.ts+++ b/apps/web/app/(ee)/api/shopify/integration/webhook/orders-paid.ts@@ -5,6 +5,7 @@ import {import { shopifyOrderSchema } from "@/lib/integrations/shopify/schema";import { processShopifyOrderJob } from "@/lib/jobs/handlers/process-shopify-order-job";import { prisma } from "@/lib/prisma";+import { getClickEvent } from "@/lib/tinybird";import { WorkspaceProps } from "@/lib/types";export async function ordersPaid({@@ -87,12 +88,28 @@ export async function ordersPaid({}// At this stage, we know the order has no customer or partner discount code- // so we need to wait for the pixel event to arrive as this could be a new customer coming via a link+ // Prefer dubClickId from note_attributes when present; otherwise wait for the pixel+ let clickId =+ order.note_attributes.find(({ name }) => name === "dubClickId")?.value ||+ undefined;++ if (clickId) {+ const clickEvent = await getClickEvent({ clickId });++ if (!clickEvent) {+ console.warn(+ `Click event not found for the clickId ${clickId} from note_attributes`,+ );+ clickId = undefined;+ }+ }+const checkout = await shopifyCheckoutCache.set({checkoutToken,fields: {order,workspaceId: workspace.id,+ ...(clickId && { clickId }),},});diff --git a/apps/web/lib/integrations/shopify/schema.ts b/apps/web/lib/integrations/shopify/schema.tsindex 7990b9a612..62ad7bcb85 100644--- a/apps/web/lib/integrations/shopify/schema.ts+++ b/apps/web/lib/integrations/shopify/schema.ts@@ -30,6 +30,14 @@ export const shopifyOrderSchema = z.object({country_code: z.string().nullish(),}).nullish(),+ note_attributes: z+ .array(+ z.object({+ name: z.string(), // dubClickId+ value: z.string().nullish(),+ }),+ )+ .default([]),});export const integrationCredentialsSchema = z.object({diff --git a/apps/web/playwright/api/shopify/helpers.ts b/apps/web/playwright/api/shopify/helpers.tsindex ba564e05c4..1d1f7ed79f 100644--- a/apps/web/playwright/api/shopify/helpers.ts+++ b/apps/web/playwright/api/shopify/helpers.ts@@ -31,6 +31,7 @@ export function shopifyOrderPayload({},},discount_codes: [],+ note_attributes: [],billing_address: {province: "California",country_code: "US",diff --git a/apps/web/playwright/api/shopify/orders.spec.ts b/apps/web/playwright/api/shopify/orders.spec.tsindex f37db3c08b..1379c64a33 100644--- a/apps/web/playwright/api/shopify/orders.spec.ts+++ b/apps/web/playwright/api/shopify/orders.spec.ts@@ -110,6 +110,34 @@ test.describe("Shopify orders/paid", () => {]).toContain(webhook.data);});+ test("webhook with dubClickId in note_attributes", async () => {+ const checkoutToken = nanoid(10);++ const webhook = await postShopifyOrdersPaidWebhook({+ checkoutToken,+ note_attributes: [{ name: "dubClickId", value: clickId }],+ });++ expect(webhook.status).toEqual(200);+ expect(webhook.data).toEqual(+ `[Shopify] Click ID ${clickId} found. Order queued for processing.`,+ );+ });++ test("webhook with unknown dubClickId waits for pixel", async () => {+ const checkoutToken = nanoid(10);++ const webhook = await postShopifyOrdersPaidWebhook({+ checkoutToken,+ note_attributes: [{ name: "dubClickId", value: nanoid(16) }],+ });++ expect(webhook.status).toEqual(200);+ expect(webhook.data).toEqual(+ "[Shopify] Waiting for pixel event to arrive...",+ );+ });+test("orders/paid – existing customer", async ({ api }) => {const { customer } = await trackLead({ clickId });const created = await getCustomerByExternalId(api, customer.externalId);