From cdfeaea21064440d5eb09423a86ac67f69a44d98 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 2 Sep 2026 12:15:22 +0530 Subject: [PATCH 1/5] Add Shopify pixel, webhook, and order dispatch logs for debugging. --- .../api/shopify/integration/webhook/route.ts | 35 +++++++++++-------- apps/web/app/(ee)/api/shopify/pixel/route.ts | 6 ++++ .../integrations/shopify/checkout-cache.ts | 24 +++++++++++++ 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts b/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts index a9ad369d102..445f9dc9acb 100644 --- a/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts +++ b/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts @@ -1,8 +1,8 @@ import { captureWebhookLog } from "@/lib/api-logs/capture-webhook-log"; import { isLocalDev } from "@/lib/api/environment"; import { prisma } from "@/lib/prisma"; -import { log } from "@dub/utils"; import { waitUntil } from "@vercel/functions"; +import { logAndRespond } from "app/(ee)/api/cron/utils"; import crypto from "crypto"; import { appUninstalled } from "./app-uninstalled"; import { customersDataRequest } from "./customers-data-request"; @@ -36,15 +36,23 @@ export const POST = async (req: Request) => { .digest("base64"); if (generatedSignature !== signature) { - return new Response(`[Shopify] Invalid webhook signature. Skipping...`, { - status: 401, + console.log({ + generatedSignature, + signature, }); + + return logAndRespond( + "Shopify webhook signature verification failed. Skipping...", + { + status: 401, + }, + ); } } // Check if topic is relevant if (!relevantTopics.has(topic)) { - return new Response(`[Shopify] Unsupported topic: ${topic}. Skipping...`); + return logAndRespond(`Unsupported topic: ${topic}. Skipping...`); } const event = JSON.parse(data); @@ -63,11 +71,17 @@ export const POST = async (req: Request) => { }); if (!workspace) { - return new Response( - `[Shopify] Workspace not found for shop: ${shopDomain}. Skipping...`, + return logAndRespond( + `Workspace not found for shop: ${shopDomain}. Skipping...`, ); } + console.info("Webhook event", { + workspaceId: workspace.id, + shopDomain, + topic, + }); + const requestLog = { workspaceId: workspace.id, method: req.method, @@ -111,14 +125,7 @@ export const POST = async (req: Request) => { break; } } catch (error) { - await log({ - message: `Shopify webhook failed. Error: ${error.message}`, - type: "errors", - }); - - const response = new Response( - `[Shopify] Webhook handler failed. View logs`, - ); + const response = new Response("Webhook handler failed. View logs."); waitUntil( captureWebhookLog({ diff --git a/apps/web/app/(ee)/api/shopify/pixel/route.ts b/apps/web/app/(ee)/api/shopify/pixel/route.ts index 1ff35bb7750..c8ae4a715c6 100644 --- a/apps/web/app/(ee)/api/shopify/pixel/route.ts +++ b/apps/web/app/(ee)/api/shopify/pixel/route.ts @@ -23,6 +23,11 @@ export const POST = async (req: Request) => { }); } + console.info("Shopify pixel event", { + clickId, + checkoutToken, + }); + // Rate limit the request const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP; const { success } = await ratelimit().limit(`shopify-track-pixel:${ip}`); @@ -39,6 +44,7 @@ export const POST = async (req: Request) => { const clickEvent = await getClickEvent({ clickId }); if (!clickEvent) { + console.warn(`Click event not found for the clickId ${clickId}`); clickId = undefined; } } diff --git a/apps/web/lib/integrations/shopify/checkout-cache.ts b/apps/web/lib/integrations/shopify/checkout-cache.ts index 3fd53217eb0..db7f24e62eb 100644 --- a/apps/web/lib/integrations/shopify/checkout-cache.ts +++ b/apps/web/lib/integrations/shopify/checkout-cache.ts @@ -65,11 +65,28 @@ export async function tryDispatchShopifyOrderJob({ checkoutToken: string; checkout: ShopifyCheckoutCacheItem; }) { + const logContext = { + checkoutToken, + workspaceId: checkout.workspaceId, + clickId: checkout.clickId, + confirmationNumber: checkout.order?.confirmation_number, + hasOrder: Boolean(checkout.order), + dispatched: Boolean(checkout.dispatched), + }; + if (!checkout.order || !checkout.workspaceId || !checkout.clickId) { + console.info( + "Shopify order dispatch skipped: checkout incomplete", + logContext, + ); return false; } if (checkout.dispatched) { + console.info( + "Shopify order dispatch skipped: already dispatched", + logContext, + ); return false; } @@ -79,6 +96,7 @@ export async function tryDispatchShopifyOrderJob({ const claimed = Boolean(claim); if (!claimed) { + console.info("Shopify order dispatch skipped: claim lost", logContext); return false; } @@ -94,11 +112,17 @@ export async function tryDispatchShopifyOrderJob({ }, ); } catch (error) { + console.error("Shopify order dispatch failed, releasing claim", { + ...logContext, + error, + }); await redis.hdel(key, "dispatched"); throw error; } await shopifyCheckoutCache.delete(checkoutToken); + console.info("Shopify order job dispatched", logContext); + return true; } From 9665cfee8f99af29429723b2f5ca74785d0f12d4 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 2 Sep 2026 12:16:02 +0530 Subject: [PATCH 2/5] Update checkout-cache.ts --- apps/web/lib/integrations/shopify/checkout-cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/lib/integrations/shopify/checkout-cache.ts b/apps/web/lib/integrations/shopify/checkout-cache.ts index db7f24e62eb..543228e2c40 100644 --- a/apps/web/lib/integrations/shopify/checkout-cache.ts +++ b/apps/web/lib/integrations/shopify/checkout-cache.ts @@ -69,7 +69,7 @@ export async function tryDispatchShopifyOrderJob({ checkoutToken, workspaceId: checkout.workspaceId, clickId: checkout.clickId, - confirmationNumber: checkout.order?.confirmation_number, + hasClickId: Boolean(checkout.clickId), hasOrder: Boolean(checkout.order), dispatched: Boolean(checkout.dispatched), }; From 5506df64834ded3fb6ec45dd294fda0e9b33489a Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 2 Sep 2026 12:17:02 +0530 Subject: [PATCH 3/5] Update route.ts --- apps/web/app/(ee)/api/shopify/integration/webhook/route.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts b/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts index 445f9dc9acb..dec0ae18dd8 100644 --- a/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts +++ b/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts @@ -36,11 +36,6 @@ export const POST = async (req: Request) => { .digest("base64"); if (generatedSignature !== signature) { - console.log({ - generatedSignature, - signature, - }); - return logAndRespond( "Shopify webhook signature verification failed. Skipping...", { From 735dcc120701240655c5085132190dfef856c4b1 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 2 Sep 2026 12:18:51 +0530 Subject: [PATCH 4/5] Update route.ts --- .../(ee)/api/shopify/integration/webhook/route.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts b/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts index dec0ae18dd8..a96ec590e3b 100644 --- a/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts +++ b/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts @@ -27,6 +27,12 @@ export const POST = async (req: Request) => { const headers = req.headers; const topic = headers.get("x-shopify-topic") || ""; const signature = headers.get("x-shopify-hmac-sha256") || ""; + const shopDomain = headers.get("x-shopify-shop-domain") || ""; + + console.info("Webhook event", { + shopDomain, + topic, + }); if (!isLocalDev) { // Verify signature @@ -51,7 +57,6 @@ export const POST = async (req: Request) => { } const event = JSON.parse(data); - const shopDomain = headers.get("x-shopify-shop-domain") || ""; // Find workspace const workspace = await prisma.project.findUnique({ @@ -71,12 +76,6 @@ export const POST = async (req: Request) => { ); } - console.info("Webhook event", { - workspaceId: workspace.id, - shopDomain, - topic, - }); - const requestLog = { workspaceId: workspace.id, method: req.method, From dc75f05a4a8965ab5e3985bf9e0a5e4d76232721 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Wed, 2 Sep 2026 12:19:57 +0530 Subject: [PATCH 5/5] Update route.ts --- apps/web/app/(ee)/api/shopify/integration/webhook/route.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts b/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts index a96ec590e3b..f51475c3199 100644 --- a/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts +++ b/apps/web/app/(ee)/api/shopify/integration/webhook/route.ts @@ -76,6 +76,10 @@ export const POST = async (req: Request) => { ); } + console.info("Workspace found", { + workspaceId: workspace.id, + }); + const requestLog = { workspaceId: workspace.id, method: req.method,