Skip to content

Open source alternative to Semrush and Ahrefs

Bring Search Console back into signup before agent setup (#592)

Ben Senescu0b40de6f1199
diff --git a/src/client/features/onboarding/PostSignupOnboarding.tsx b/src/client/features/onboarding/PostSignupOnboarding.tsx
index 9a01cc3a..23fa861a 100644
--- a/src/client/features/onboarding/PostSignupOnboarding.tsx
+++ b/src/client/features/onboarding/PostSignupOnboarding.tsx
@@ -13,6 +13,7 @@ import {
WORK_FOR_OPTIONS,
} from "@/client/features/onboarding/onboardingModel";
import { AgentSetup } from "@/client/features/ai-mcp/AgentSetup";
+import { SearchConsoleOnboardingStep } from "@/client/features/onboarding/SearchConsoleOnboardingStep";
type PostSignupOnboardingProps = {
step: number;
@@ -100,6 +101,8 @@ export function PostSignupOnboarding({
otherValue={answers.sourceOther}
onOtherChange={(sourceOther) => updateAnswers({ sourceOther })}
/>
+ ) : step === 3 ? (
+ <SearchConsoleOnboardingStep />
) : (
<AgentSetup
initialIntent={answers.mcpSetupIntent}
diff --git a/src/client/features/onboarding/SearchConsoleOnboardingStep.tsx b/src/client/features/onboarding/SearchConsoleOnboardingStep.tsx
new file mode 100644
index 00000000..8772217f
--- /dev/null
+++ b/src/client/features/onboarding/SearchConsoleOnboardingStep.tsx
@@ -0,0 +1,173 @@
+import * as React from "react";
+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
+import { Check } from "lucide-react";
+import { toast } from "sonner";
+import { GoogleGlyph } from "@/client/features/gsc/GoogleGlyph";
+import { GoogleLinkErrorAlert } from "@/client/features/integrations/GoogleLinkErrorAlert";
+import { SelfHostedSetupWarning } from "@/client/features/gsc/SelfHostedSetupWarning";
+import {
+ SitePicker,
+ type GscSiteSelection,
+} from "@/client/features/gsc/SitePicker";
+import { startGoogleLink } from "@/client/features/integrations/startGoogleLink";
+import { getStandardErrorMessage } from "@/client/lib/error-messages";
+import { captureClientEvent } from "@/client/lib/posthog";
+import {
+ getGscConnection,
+ listGscSites,
+ setGscSite,
+} from "@/serverFunctions/gsc";
+import { getProjects } from "@/serverFunctions/projects";
+
+const GRANT_STATUS_KEY = ["gscGrantStatus"];
+
+/**
+ * Onboarding step for connecting Google Search Console: link the account-level
+ * OAuth grant, then bind a verified property to the user's first project — the
+ * same binding the project's Integrations page does. The step lives before the
+ * agent-setup screen because most users leave onboarding from that screen.
+ */
+export function SearchConsoleOnboardingStep() {
+ const projectsQuery = useQuery({
+ queryKey: ["projects"],
+ queryFn: () => getProjects(),
+ });
+ const project = projectsQuery.data?.[0];
+
+ return (
+ <div className="space-y-4">
+ <div>
+ <h1 className="text-2xl font-semibold tracking-tight">
+ Connect Google Search Console now?
+ </h1>
+ <p className="mt-3 text-sm leading-relaxed text-base-content/60">
+ Bring your real clicks and queries into OpenSEO and your AI agent. You
+ can also do this later from the dashboard.
+ </p>
+ </div>
+
+ {project ? <GscConnect projectId={project.id} /> : <Checking />}
+ </div>
+ );
+}
+
+/** Connect + pick-a-property flow, scoped to a known project. */
+function GscConnect({ projectId }: { projectId: string }) {
+ const queryClient = useQueryClient();
+ const [selection, setSelection] = React.useState<GscSiteSelection | null>(
+ null,
+ );
+
+ const connectionKey = ["gscConnection", projectId];
+ const connectionQuery = useQuery({
+ queryKey: connectionKey,
+ queryFn: () => getGscConnection({ data: { projectId } }),
+ });
+ const connection = connectionQuery.data;
+ const connected = Boolean(connection?.connected);
+ const hasGrant = Boolean(connection?.currentUserHasGrant);
+ const needsSetup =
+ connectionQuery.isSuccess && !connection?.googleOAuthConfigured;
+
+ const sitesQuery = useQuery({
+ queryKey: ["gscSites", projectId],
+ queryFn: () => listGscSites({ data: { projectId } }),
+ enabled: hasGrant && !connected && !needsSetup,
+ });
+ const accounts = React.useMemo(
+ () => sitesQuery.data?.accounts ?? [],
+ [sitesQuery.data?.accounts],
+ );
+ const requiresReconnect = accounts.some(
+ (account) => account.requiresReconnect,
+ );
+
+ React.useEffect(() => {
+ if (!requiresReconnect) return;
+
+ void queryClient.invalidateQueries({
+ queryKey: ["gscConnection", projectId],
+ });
+ void queryClient.invalidateQueries({ queryKey: GRANT_STATUS_KEY });
+ }, [requiresReconnect, queryClient, projectId]);
+
+ const setSiteMutation = useMutation({
+ mutationFn: (selected: GscSiteSelection) =>
+ setGscSite({ data: { projectId, ...selected } }),
+ onSuccess: () => {
+ captureClientEvent("gsc:property_select");
+ void queryClient.invalidateQueries({ queryKey: connectionKey });
+ // The dashboard checklist reads the same connection state.
+ void queryClient.invalidateQueries({ queryKey: ["projects"] });
+ },
+ onError: (error) => toast.error(getStandardErrorMessage(error)),
+ });
+
+ const handleConnect = () => {
+ captureClientEvent("onboarding:gsc_connect_clicked");
+ // Google sends the user back to this URL, and the step lives in the URL,
+ // so they land on this screen again with the grant in place.
+ void startGoogleLink("gsc", window.location.href);
+ };
+
+ if (connectionQuery.isLoading) return <Checking />;
+
+ if (needsSetup) {
+ return <SelfHostedSetupWarning />;
+ }
+
+ if (connected) {
+ return (
+ <div className="flex items-center gap-3 rounded-lg border border-success/30 bg-success/10 p-3.5 text-sm">
+ <span className="flex size-6 shrink-0 items-center justify-center rounded-full bg-success/20 text-success">
+ <Check className="size-3.5" />
+ </span>
+ <span className="text-base-content/80">
+ Connected to <span className="font-mono">{connection?.siteUrl}</span>.
+ </span>
+ </div>
+ );
+ }
+
+ if (hasGrant) {
+ return (
+ <div className="space-y-4">
+ <GoogleLinkErrorAlert provider="gsc" />
+ <SitePicker
+ loading={sitesQuery.isLoading}
+ error={sitesQuery.isError}
+ accounts={accounts}
+ selection={selection}
+ onSelect={setSelection}
+ onSave={() => selection && setSiteMutation.mutate(selection)}
+ saving={setSiteMutation.isPending}
+ onRetry={() => void sitesQuery.refetch()}
+ onReconnect={handleConnect}
+ />
+ </div>
+ );
+ }
+
+ return (
+ <div className="space-y-4">
+ <GoogleLinkErrorAlert provider="gsc" />
+ <button
+ type="button"
+ onClick={handleConnect}
+ className="inline-flex items-center gap-2.5 rounded-lg border border-base-300 bg-base-100 px-4 py-2.5 text-sm font-semibold text-base-content shadow-sm transition hover:bg-base-200 hover:shadow focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
+ >
+ <GoogleGlyph className="size-[18px]" />
+ Connect with Google
+ </button>
+ </div>
+ );
+}
+
+function Checking() {
+ return (
+ <div className="flex items-center gap-2 text-sm text-base-content/50">
+ <span className="loading loading-spinner loading-sm" />
+ Checking…
+ </div>
+ );
+}
diff --git a/src/client/features/onboarding/onboardingModel.test.ts b/src/client/features/onboarding/onboardingModel.test.ts
index d884cdad..17189399 100644
--- a/src/client/features/onboarding/onboardingModel.test.ts
+++ b/src/client/features/onboarding/onboardingModel.test.ts
@@ -20,7 +20,7 @@ describe("historical onboarding values", () => {
const answers = restoreOnboardingAnswers({ ...saved, foundVia: "Google" });
expect(answers.source).toBe("Google");
expect(answers.sourceOther).toBe("");
- expect(buildOnboardingPayload(answers, 3).foundVia).toBe("Google");
+ expect(buildOnboardingPayload(answers, 4).foundVia).toBe("Google");
});
it.each(["My own startup or business", "My employer's website"])(
@@ -29,7 +29,7 @@ describe("historical onboarding values", () => {
const answers = restoreOnboardingAnswers({ ...saved, workFor });
expect(answers.workFor).toBe(workFor);
expect(answers.workForOther).toBe("");
- expect(buildOnboardingPayload(answers, 3).workFor).toBe(workFor);
+ expect(buildOnboardingPayload(answers, 4).workFor).toBe(workFor);
},
);
@@ -38,7 +38,7 @@ describe("historical onboarding values", () => {
const answers = restoreOnboardingAnswers({ ...saved, interestedFeatures });
expect(answers.selectedInterests).toEqual(interestedFeatures);
expect(answers.interestOther).toBe("");
- expect(buildOnboardingPayload(answers, 3).interestedFeatures).toEqual(
+ expect(buildOnboardingPayload(answers, 4).interestedFeatures).toEqual(
interestedFeatures,
);
});
@@ -50,20 +50,20 @@ describe("signup agent setup", () => {
...restoreOnboardingAnswers(saved),
mcpSetupIntent: "yes" as const,
};
- expect(buildOnboardingPayload(answers, 2)).not.toHaveProperty(
+ expect(buildOnboardingPayload(answers, 3)).not.toHaveProperty(
"mcpSetupIntent",
);
expect(
- buildOnboardingPayload(answers, 3, { completed: true }),
+ buildOnboardingPayload(answers, 4, { completed: true }),
).toMatchObject({ mcpSetupIntent: "yes", completed: true });
});
it("lets users finish without an agent or without making a choice", () => {
const answers = restoreOnboardingAnswers(saved);
expect(
- buildOnboardingPayload(answers, 3, { completed: true }),
+ buildOnboardingPayload(answers, 4, { completed: true }),
).toMatchObject({ completed: true });
expect(
- buildOnboardingPayload({ ...answers, mcpSetupIntent: "no" }, 3, {
+ buildOnboardingPayload({ ...answers, mcpSetupIntent: "no" }, 4, {
completed: true,
}),
).toMatchObject({ mcpSetupIntent: "no", completed: true });
@@ -74,7 +74,7 @@ describe("signup agent setup", () => {
mcpSetupIntent: "yes" as const,
};
expect(
- buildOnboardingPayload(answers, 3, {
+ buildOnboardingPayload(answers, 4, {
completed: true,
mcpSetupIntent: "no",
}),
diff --git a/src/client/features/onboarding/onboardingModel.ts b/src/client/features/onboarding/onboardingModel.ts
index 1250d1fa..e58cfd0a 100644
--- a/src/client/features/onboarding/onboardingModel.ts
+++ b/src/client/features/onboarding/onboardingModel.ts
@@ -1,7 +1,8 @@
import { queryOptions } from "@tanstack/react-query";
import { getOnboardingAnswers } from "@/serverFunctions/onboarding";
-export const ONBOARDING_LAST_STEP = 3;
+// 0 interests · 1 who for · 2 source · 3 Search Console · 4 agent setup
+export const ONBOARDING_LAST_STEP = 4;
// Option values below are persisted and used by analytics. Change display copy
// here instead of renaming those values, so historical answers stay comparable.
@@ -149,7 +150,7 @@ export function buildOnboardingPayload(
...(step >= 0 ? { interestedFeatures } : {}),
...(step >= 1 ? { workFor, clientWebsiteCount } : {}),
...(step >= 2 ? { foundVia } : {}),
- ...(step >= 3 && answers.mcpSetupIntent
+ ...(step >= ONBOARDING_LAST_STEP && answers.mcpSetupIntent
? { mcpSetupIntent: answers.mcpSetupIntent }
: {}),
...extra,