Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
fix(ga4): hide every GA4 connect surface until the OAuth app is approved (#466)
Ben Senescu45403aa06f5e
diff --git a/src/client/features/ai-mcp/AvailableTools.tsx b/src/client/features/ai-mcp/AvailableTools.tsxindex 97d6881c..acb5f665 100644--- a/src/client/features/ai-mcp/AvailableTools.tsx+++ b/src/client/features/ai-mcp/AvailableTools.tsx@@ -1,3 +1,5 @@+import { GA4_OAUTH_APP_PENDING } from "@/shared/ga4";+type McpTool = {name: string;title: string;@@ -207,11 +209,7 @@ const toolCategories: ToolCategory[] = [},];-// Google hasn't approved the GA4 OAuth app yet, so connecting fails.-// Flip to false once the app is approved.-const GA4_TOOLS_HIDDEN = true;--const visibleCategories = GA4_TOOLS_HIDDEN+const visibleCategories = GA4_OAUTH_APP_PENDING? toolCategories.filter((cat) => cat.label !== "Google Analytics"): toolCategories;diff --git a/src/client/features/dashboard/DashboardPage.tsx b/src/client/features/dashboard/DashboardPage.tsxindex de98772b..9644d409 100644--- a/src/client/features/dashboard/DashboardPage.tsx+++ b/src/client/features/dashboard/DashboardPage.tsx@@ -25,12 +25,9 @@ import {refreshDashboardBacklinkSnapshot,} from "@/serverFunctions/dashboard";import { setProjectDomain } from "@/serverFunctions/projects";+import { GA4_OAUTH_APP_PENDING } from "@/shared/ga4";import type { DashboardHeroStep } from "@/types/schemas/dashboard";-// Google hasn't approved the GA4 OAuth app yet, so connecting fails.-// Flip to false once the app is approved.-const GA4_CARD_HIDDEN = true;-const HERO_COPY: Record<DashboardHeroStep,{ title: string; body: string; cta: string }@@ -336,7 +333,7 @@ export function DashboardPage({ projectId }: { projectId: string }) {hasData: gscConnected,node: <GscCard projectId={projectId} connected={gscConnected} />,},- ...(!GA4_CARD_HIDDEN &&+ ...(!GA4_OAUTH_APP_PENDING &&(ga4Connected || !activation.ga4.cardDismissedAt)? [{diff --git a/src/client/features/ga4/GoogleAnalyticsConnectionCard.tsx b/src/client/features/ga4/GoogleAnalyticsConnectionCard.tsxindex 2c9eb736..8ba977fb 100644--- a/src/client/features/ga4/GoogleAnalyticsConnectionCard.tsx+++ b/src/client/features/ga4/GoogleAnalyticsConnectionCard.tsx@@ -19,7 +19,10 @@ import {listGa4Properties,setGa4Property,} from "@/serverFunctions/ga4";-import { GA4_SELF_HOSTED_SETUP_DOCS_URL } from "@/shared/ga4";+import {+ GA4_OAUTH_APP_PENDING,+ GA4_SELF_HOSTED_SETUP_DOCS_URL,+} from "@/shared/ga4";export function GoogleAnalyticsConnectionCard({projectId,@@ -43,6 +46,14 @@ export function GoogleAnalyticsConnectionCard({});const connection = connectionQuery.data;const connected = Boolean(connection?.connected);+ // Hide the hosted connect surface while the OAuth app awaits Google's+ // approval, but keep the card for users who already hold a grant so they+ // can finish property selection or disconnect.+ const hiddenPendingApproval =+ GA4_OAUTH_APP_PENDING &&+ hosted &&+ !connected &&+ !connection?.currentUserHasGrant;const selfHostedNeedsSetup =!hosted && connectionQuery.isSuccess && !connection?.googleOAuthConfigured;const showPicker = picking || (connection?.currentUserHasGrant && !connected);@@ -101,6 +112,8 @@ export function GoogleAnalyticsConnectionCard({});const handleConnect = () => void startGoogleLink("ga4", window.location.href);+ if (hiddenPendingApproval) return null;+return (<IntegrationConnectionCardtitle="Google Analytics"diff --git a/src/shared/ga4.ts b/src/shared/ga4.tsindex 2044762c..c2ba748c 100644--- a/src/shared/ga4.ts+++ b/src/shared/ga4.ts@@ -1,6 +1,12 @@/** Better Auth provider ID for the dedicated Google Analytics grant. */export const GA4_OAUTH_PROVIDER_ID = "google-analytics";+// Google hasn't approved the GA4 OAuth app yet, so hosted connect attempts+// show Google's "unverified app" warning. Gates every GA4 connect surface;+// flip to false once the app is approved. Self-hosted deployments use their+// own OAuth app, so only hosted mode is gated.+export const GA4_OAUTH_APP_PENDING = true;+export const GA4_OAUTH_SCOPES = ["openid","email",