The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
address CR feedback
Steven Teya46b29aaef10
diff --git a/apps/web/app/(ee)/api/google-ads/conversion-actions/route.ts b/apps/web/app/(ee)/api/google-ads/conversion-actions/route.tsindex 7395c04e51..6605dd7664 100644--- a/apps/web/app/(ee)/api/google-ads/conversion-actions/route.ts+++ b/apps/web/app/(ee)/api/google-ads/conversion-actions/route.ts@@ -57,6 +57,7 @@ export const GET = withWorkspace(const candidates = getLoginCustomerIdCandidates({customers: currentSettings.customers,selectedCustomerId: customerId,+ loginCustomerId: currentSettings.loginCustomerId,});let lastError: unknown;diff --git a/apps/web/lib/integrations/google-ads/api.ts b/apps/web/lib/integrations/google-ads/api.tsindex ee8751c2b4..8f44e5c92a 100644--- a/apps/web/lib/integrations/google-ads/api.ts+++ b/apps/web/lib/integrations/google-ads/api.ts@@ -134,21 +134,28 @@ const dataManagerFetch = async <T>({return data as T;};-const formatApiErrorDetail = (data: any, rawText: string) => {+export const formatApiErrorDetail = (data: any, rawText: string) => {const payload = Array.isArray(data) ? data[0] : data;- const googleAdsError = payload?.error?.details?.[0]?.errors?.[0]?.message;+ const adsError = payload?.error?.details?.[0]?.errors?.[0];+ const authorizationError = adsError?.errorCode?.authorizationError;+ const googleAdsError = adsError?.message;- return (+ const detail =googleAdsError ??payload?.error?.message ??- (data ? JSON.stringify(data) : rawText)- );+ (data ? JSON.stringify(data) : rawText);++ if (authorizationError && !String(detail).includes(authorizationError)) {+ return `${authorizationError}: ${detail}`;+ }++ return detail;};const normalizeGoogleAdsCustomerId = (customerId: string) =>customerId.replace(/-/g, "").replace(/^customers\//, "");-const isGoogleAdsPermissionDenied = (error: unknown) => {+export const isGoogleAdsPermissionDenied = (error: unknown) => {const message = error instanceof Error ? error.message : String(error);return message.includes("USER_PERMISSION_DENIED");};@@ -534,6 +541,7 @@ export const inferLoginCustomerId = ({export const getLoginCustomerIdCandidates = ({customers,selectedCustomerId,+ loginCustomerId,}: {customers: {id: string;@@ -541,7 +549,10 @@ export const getLoginCustomerIdCandidates = ({loginCustomerId?: string | null;}[];selectedCustomerId: string;+ loginCustomerId?: string | null;}) => {+ const persistedLoginCustomerId = loginCustomerId?.replace(/-/g, "") || null;+const managerIds = customers.filter((customer) => {if (!customer.manager) {@@ -549,14 +560,18 @@ export const getLoginCustomerIdCandidates = ({}const id = customer.id.replace(/-/g, "");- const loginCustomerId = customer.loginCustomerId?.replace(/-/g, "");+ const customerLoginCustomerId = customer.loginCustomerId?.replace(+ /-/g,+ "",+ );// Sub-managers discovered via hierarchy aren't valid login-customer-ids.- return !loginCustomerId || loginCustomerId === id;+ return !customerLoginCustomerId || customerLoginCustomerId === id;}).map((customer) => customer.id.replace(/-/g, ""));const candidates: (string | null)[] = [+ ...(persistedLoginCustomerId ? [persistedLoginCustomerId] : []),inferLoginCustomerId({ customers, selectedCustomerId }),null,...managerIds,diff --git a/apps/web/lib/integrations/google-ads/ui/settings.tsx b/apps/web/lib/integrations/google-ads/ui/settings.tsxindex 51d86d3d53..8144803409 100644--- a/apps/web/lib/integrations/google-ads/ui/settings.tsx+++ b/apps/web/lib/integrations/google-ads/ui/settings.tsx@@ -226,7 +226,7 @@ export const GoogleAdsSettings = ({</p><p className="mb-4 text-sm leading-normal text-neutral-600">Map Dub lead events to an existing Google Ads conversion- action with type UPLOAD_CLICKS.+ action.</p><Controllername="leadConversionAction"@@ -264,7 +264,7 @@ export const GoogleAdsSettings = ({</p><p className="mb-4 text-sm leading-normal text-neutral-600">Map Dub sale events to an existing Google Ads conversion- action with type UPLOAD_CLICKS.+ action.</p><Controllername="saleConversionAction"diff --git a/apps/web/tests/misc/google-ads-api-error.test.ts b/apps/web/tests/misc/google-ads-api-error.test.tsnew file mode 100644index 0000000000..869a6f221f--- /dev/null+++ b/apps/web/tests/misc/google-ads-api-error.test.ts@@ -0,0 +1,57 @@+import {+ formatApiErrorDetail,+ isGoogleAdsPermissionDenied,+} from "@/lib/integrations/google-ads/api";+import { describe, expect, it } from "vitest";++// searchStream 403s arrive as a JSON array. The human message omits the+// authorization error-code enum that retry classification depends on.+const permissionDeniedWithoutCodeInMessage = [+ {+ error: {+ code: 403,+ message: "The caller does not have permission",+ status: "PERMISSION_DENIED",+ details: [+ {+ "@type":+ "type.googleapis.com/google.ads.googleads.v22.errors.GoogleAdsFailure",+ errors: [+ {+ errorCode: {+ authorizationError: "USER_PERMISSION_DENIED",+ },+ message:+ "User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header.",+ },+ ],+ requestId: "RWSdEB8C1WuiLgZl38biSQ",+ },+ ],+ },+ },+];++describe("formatApiErrorDetail", () => {+ it("preserves USER_PERMISSION_DENIED when the message omits the error code", () => {+ const adsMessage =+ permissionDeniedWithoutCodeInMessage[0].error.details[0].errors[0]+ .message;++ expect(adsMessage).not.toContain("USER_PERMISSION_DENIED");++ const detail = formatApiErrorDetail(+ permissionDeniedWithoutCodeInMessage,+ "",+ );++ expect(detail).toContain("USER_PERMISSION_DENIED");+ expect(+ isGoogleAdsPermissionDenied(+ new Error(+ `[Google Ads API] Request failed for searchStream (403): ${detail}`,+ ),+ ),+ ).toBe(true);+ });+});