Skip to content

Open source alternative to Semrush and Ahrefs

Finish onboarding when the agent connects or the user goes to the dashboard (EVE-439) (#994)

Carter Smithb5f9f04a2378
diff --git a/src/client/features/ai-mcp/AgentSetup.tsx b/src/client/features/ai-mcp/AgentSetup.tsx
index 196ff9bc..9b6120fa 100644
--- a/src/client/features/ai-mcp/AgentSetup.tsx
+++ b/src/client/features/ai-mcp/AgentSetup.tsx
@@ -1,3 +1,4 @@
+import { useState } from "react";
import { ArrowRight } from "lucide-react";
import { AgentList } from "./AgentList";
import { AgentSetupPanel, AGENT_SETUP_DESCRIPTION } from "./AgentSetupPanel";
@@ -6,21 +7,20 @@ import { captureClientEvent } from "@/client/lib/posthog";
import { WizardFooter } from "@/client/features/onboarding/WizardFooter";
import { Button } from "@/client/components/ui/button";
+/** Last onboarding step. Onboarding finishes when the user clicks Go to
+ * dashboard, or when their agent connects over MCP (the server marks it). */
export function AgentSetup({
- onNext,
+ onFinish,
onBack,
- nextLabel = "Finish",
- disabled = false,
}: {
- onNext: () => void;
+ onFinish: () => void;
onBack: () => void;
- nextLabel?: string;
- disabled?: boolean;
}) {
const prompt = getAgentSetupPrompt(window.location.origin);
+ const [copied, setCopied] = useState(false);
return (
- <fieldset disabled={disabled}>
+ <div>
<div className="mb-8">
<h1 className="text-2xl font-semibold tracking-tight">
Set up your agent
@@ -32,8 +32,18 @@ export function AgentSetup({
</div>
<AgentSetupPanel
prompt={prompt}
- onCopy={() => captureClientEvent("onboarding:setup_prompt_copy")}
- />
+ copyVariant={copied ? "outline" : "default"}
+ onCopy={() => {
+ setCopied(true);
+ captureClientEvent("onboarding:setup_prompt_copy");
+ }}
+ >
+ {copied ? (
+ <p className="mt-3 text-center text-xs text-muted-foreground">
+ Paste it into your agent and approve the connection.
+ </p>
+ ) : null}
+ </AgentSetupPanel>
<div className="mt-7 border-t border-border pt-5">
<WizardFooter
className="mt-0"
@@ -41,15 +51,19 @@ export function AgentSetup({
continueAction={
<Button
type="button"
- variant="ghost"
- className="h-8 gap-2 px-3 text-xs font-semibold"
- onClick={onNext}
+ variant={copied ? "default" : "ghost"}
+ className={
+ copied
+ ? "font-semibold"
+ : "h-8 gap-2 px-3 text-xs font-semibold"
+ }
+ onClick={onFinish}
>
- {nextLabel} <ArrowRight className="size-4" />
+ Go to dashboard <ArrowRight className="size-4" />
</Button>
}
/>
</div>
- </fieldset>
+ </div>
);
}
diff --git a/src/client/features/ai-mcp/AgentSetupPanel.tsx b/src/client/features/ai-mcp/AgentSetupPanel.tsx
index 34840b36..b2da9e5a 100644
--- a/src/client/features/ai-mcp/AgentSetupPanel.tsx
+++ b/src/client/features/ai-mcp/AgentSetupPanel.tsx
@@ -1,3 +1,4 @@
+import type { ComponentProps, ReactNode } from "react";
import { Package } from "lucide-react";
import { CopyButton } from "@/client/components/CopyButton";
@@ -7,9 +8,14 @@ export const AGENT_SETUP_DESCRIPTION =
export function AgentSetupPanel({
prompt,
onCopy,
+ copyVariant = "default",
+ children,
}: {
prompt: string;
onCopy?: () => void;
+ copyVariant?: ComponentProps<typeof CopyButton>["variant"];
+ /** Shown under the copy button, e.g. what to do after copying. */
+ children?: ReactNode;
}) {
return (
<>
@@ -26,7 +32,7 @@ export function AgentSetupPanel({
</div>
</div>
<CopyButton
- variant="default"
+ variant={copyVariant}
size="lg"
className="w-full"
value={prompt}
@@ -34,6 +40,7 @@ export function AgentSetupPanel({
successMessage="Setup prompt copied"
onCopy={onCopy}
/>
+ {children}
</div>
<div className="mt-4 text-center">
<a
diff --git a/src/client/features/gsc/GscReEngagementModal.tsx b/src/client/features/gsc/GscReEngagementModal.tsx
index 9844e024..8c728e49 100644
--- a/src/client/features/gsc/GscReEngagementModal.tsx
+++ b/src/client/features/gsc/GscReEngagementModal.tsx
@@ -57,10 +57,11 @@ export function GscReEngagementModal({
},
});
- // Users who finished onboarding without seeing the Search Console step have no
+ // Users who finished onboarding outside the wizard have no
// gscNudgeDismissedAt set: legacy users from before the step existed, and
- // users whose agent completed onboarding via create_project. Anyone who
- // completes the wizard gets it stamped, and dismissing/connecting clears it.
+ // users whose agent completed onboarding by connecting over MCP or calling
+ // create_project. Anyone who completes the wizard gets it stamped, and
+ // dismissing/connecting clears it.
const eligible =
hosted &&
!suppressed &&
diff --git a/src/client/features/onboarding/AnalyticsOnboardingStep.tsx b/src/client/features/onboarding/AnalyticsOnboardingStep.tsx
index 7aff6749..4c1fb824 100644
--- a/src/client/features/onboarding/AnalyticsOnboardingStep.tsx
+++ b/src/client/features/onboarding/AnalyticsOnboardingStep.tsx
@@ -1,4 +1,5 @@
import { useMutation } from "@tanstack/react-query";
+import { ArrowRight } from "lucide-react";
import * as React from "react";
import { toast } from "sonner";
import { Button } from "@/client/components/ui/button";
@@ -13,15 +14,15 @@ import { setProductUpdatesOptIn } from "@/serverFunctions/product-updates";
import type { PrivacyChoices } from "@/shared/privacy-choices";
import { PRIVACY_URL } from "@/shared/terms";
-/** Last onboarding step on the hosted app: usage analytics and product-update
- * emails. Each switch starts from the current choice, which is the region
- * default until the user picks. Finish saves both. */
+/** Onboarding step for usage analytics and product-update emails. Each switch
+ * starts from the current choice, which is the region default until the user
+ * picks. Continue saves both. */
export function AnalyticsOnboardingStep({
onBack,
- onFinish,
+ onNext,
}: {
onBack: () => void;
- onFinish: () => void;
+ onNext: () => void;
}) {
const choices = usePrivacyChoices();
const { data: session, refetch } = useSession();
@@ -29,7 +30,7 @@ export function AnalyticsOnboardingStep({
const [analytics, setAnalytics] = React.useState<boolean>();
const [productUpdates, setProductUpdates] = React.useState<boolean>();
- const finish = useMutation({
+ const save = useMutation({
// The email choice is only sent when the switch was flipped: signup
// already applied the region default.
mutationFn: async (next: {
@@ -51,7 +52,7 @@ export function AnalyticsOnboardingStep({
toast.error(
"We couldn't save your email choice. You can change it in Settings.",
),
- onSettled: onFinish,
+ onSettled: onNext,
});
if (!choices) return null;
@@ -110,15 +111,16 @@ export function AnalyticsOnboardingStep({
<Button
type="button"
className="font-semibold"
- pending={finish.isPending}
+ pending={save.isPending}
onClick={() =>
- finish.mutate({
+ save.mutate({
privacy: { ...choices, analytics: analyticsOn },
productUpdates,
})
}
>
- Finish
+ Continue
+ <ArrowRight className="size-4" />
</Button>
}
/>
diff --git a/src/client/features/onboarding/PostSignupOnboarding.tsx b/src/client/features/onboarding/PostSignupOnboarding.tsx
index 88c3eae0..d0c5fff8 100644
--- a/src/client/features/onboarding/PostSignupOnboarding.tsx
+++ b/src/client/features/onboarding/PostSignupOnboarding.tsx
@@ -5,7 +5,6 @@ import { WebsiteOnboardingStep } from "./WebsiteOnboardingStep";
import { AgentSetup } from "@/client/features/ai-mcp/AgentSetup";
import { SearchConsoleOnboardingStep } from "./SearchConsoleOnboardingStep";
import { AnalyticsOnboardingStep } from "./AnalyticsOnboardingStep";
-import { isHostedClientAuthMode } from "@/lib/auth-mode";
type PostSignupOnboardingProps = {
step: number;
@@ -31,8 +30,6 @@ export function PostSignupOnboarding({
accountMenu,
suggestedDomain,
}: PostSignupOnboardingProps) {
- // Hosted only: self-hosted installs don't run PostHog.
- const askAnalytics = isHostedClientAuthMode();
return (
<>
{accountMenu}
@@ -41,8 +38,8 @@ export function PostSignupOnboarding({
steps={[
"Website",
"Google Search Console",
+ "Preferences",
"Agent setup",
- ...(askAnalytics ? ["Preferences"] : []),
]}
onStepChange={onStepChange}
disabled={isSaving}
@@ -60,15 +57,10 @@ export function PostSignupOnboarding({
onBack={onBack}
onSkip={onSkip}
/>
- ) : ONBOARDING_STEPS[step] === "agent_setup" || !askAnalytics ? (
- <AgentSetup
- onNext={askAnalytics ? onNext : onFinish}
- nextLabel={askAnalytics ? "Continue" : "Finish"}
- onBack={onBack}
- disabled={isSaving}
- />
+ ) : ONBOARDING_STEPS[step] === "analytics" ? (
+ <AnalyticsOnboardingStep onBack={onBack} onNext={onNext} />
) : (
- <AnalyticsOnboardingStep onBack={onBack} onFinish={onFinish} />
+ <AgentSetup onFinish={onFinish} onBack={onBack} />
)}
</fieldset>
</OnboardingCard>
diff --git a/src/client/features/onboarding/onboardingModel.ts b/src/client/features/onboarding/onboardingModel.ts
index ce3d7e7f..712017a2 100644
--- a/src/client/features/onboarding/onboardingModel.ts
+++ b/src/client/features/onboarding/onboardingModel.ts
@@ -1,13 +1,14 @@
import { queryOptions } from "@tanstack/react-query";
import { getOnboardingAnswers } from "@/serverFunctions/onboarding";
-// Preserve main's setup step indices for existing links and OAuth returns.
+// Keep website and search_console first: Google's OAuth return lands on the
+// Search Console step by its index in the URL. Agent setup is last so leaving
+// to paste the prompt into an agent doesn't skip a step.
export const ONBOARDING_STEPS = [
"website",
"search_console",
- "agent_setup",
- // Hosted only (PostSignupOnboarding).
"analytics",
+ "agent_setup",
] as const;
export const ONBOARDING_LAST_STEP = ONBOARDING_STEPS.length - 1;
diff --git a/src/server/mcp/oauth-provider.ts b/src/server/mcp/oauth-provider.ts
index ed726796..0e952ea5 100644
--- a/src/server/mcp/oauth-provider.ts
+++ b/src/server/mcp/oauth-provider.ts
@@ -16,6 +16,7 @@ import {
} from "@/lib/oauth-resource";
import { asAppError } from "@/server/lib/errors";
import { recordMcpAuthorized } from "@/server/features/activation/mcpActivation";
+import { ActivationRepository } from "@/server/features/activation/repositories/ActivationRepository";
import { markOnboardingMilestone } from "@/server/email/onboarding-drip";
import { captureServerEvent } from "@/server/lib/posthog";
import {
@@ -357,6 +358,15 @@ async function handleOAuthConsentResponse(
});
await recordMcpAuthorized(context.organizationId);
+ // Connecting an agent is the last onboarding step, so this finishes
+ // onboarding for people who paste the setup prompt and never return to the
+ // wizard. Best-effort: the authorization already succeeded.
+ await ActivationRepository.markOnboardingCompleted(
+ context.userId,
+ context.organizationId,
+ ).catch((error: unknown) => {
+ console.error("oauth consent: onboarding completion failed", error);
+ });
await markOnboardingMilestone(context, "mcpConnected");
waitUntil(