mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 20:09:33 +01:00
feat(analytics): move onboarding funnel telemetry server-side and add granular step instrumentation (#23403)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Hosted Paperclip Cloud tracks user onboarding conversion in PostHog
across server-side events and browser events
> - Onboarding funnel events (`onboarding_opened`,
`onboarding_step_viewed`, `onboarding_step_completed`,
`onboarding_step_failed`, `onboarding_dismissed`) currently fire only
from browser `posthog-js`
> - Browser `posthog-js` loads lazily after `whenPageSettles` (up to 15
seconds), drops events captured before `startProductAnalytics`
initializes, and can be blocked by privacy extensions, causing
artificial dropoff between server-side `workspace_entry` and
`onboarding_opened`
> - Step 1 (`name_org`) is unmapped in `WIZARD_STEPS`, and
`connect_model` lacks sub-step visibility (provider selection,
credential mode switch, OAuth progress, API key submission, Cloud trial
CTA, mobile handoff)
> - This pull request routes all onboarding funnel events through a
first-party `POST /api/onboarding/telemetry` endpoint backed by
`trackCloudPostHogEvent` (`posthog-node`), preserves every existing
event name verbatim, adds granular step and sub-step instrumentation,
and fixes the pre-start queue drop in `product-analytics.ts`
> - The benefit is adblocker-proof, race-free server-side onboarding
analytics in PostHog with complete step-by-step dropoff visibility and
zero breaking changes to existing insights
## Linked Issues or Issue Description
**What existing behavior does this improve?**
Cloud onboarding funnel analytics in
`ui/src/lib/analytics/onboarding-analytics.ts`,
`ui/src/lib/analytics/product-analytics.ts`,
`ui/src/components/OnboardingWizard.tsx`, and `server/src/telemetry.ts`.
**Subsystem affected**
Cross-cutting (multiple of the above)
**Current behavior**
Onboarding funnel events fire only from browser `posthog-js`. Events
captured before `ProductAnalyticsGate` calls `startProductAnalytics` are
silently dropped, queued events are lost if the user leaves before
`/_ph/static/array.js` loads, Step 1 (`name_org`) is unmapped, and
`connect_model` sub-steps (OAuth link open, code submit, retry, abandon,
provider tile click, Cloud trial CTA, mobile desktop handoff) are not
instrumented.
**Proposed behavior**
All onboarding funnel and interaction events are sent via
`fetch("/api/onboarding/telemetry", { method: "POST", keepalive: true
})` to a board-authenticated, strictly Zod-validated Express route that
forwards them server-side to PostHog via `trackCloudPostHogEvent`.
Existing event names are preserved verbatim and removed from
`posthog-js` to guarantee a single sender per event. Pre-start browser
events in `product-analytics.ts` are also buffered until
`startProductAnalytics` runs.
**Reason and benefit**
Adblockers and browser script lazy-load races can no longer drop
onboarding funnel events. Product analytics can now separate
`workspace_entry` -> `onboarding_workspace_loaded` ->
`onboarding_opened` and pinpoint exact dropoff points on every step and
`connect_model` sub-step.
**Breaking changes**
None. Existing PostHog event names (`onboarding_opened`,
`onboarding_step_viewed`, `onboarding_step_completed`,
`onboarding_step_failed`, `onboarding_dismissed`,
`agent_chat_message_sent`) are preserved verbatim. On self-hosted
installs, `trackCloudPostHogEvent` is a no-op and the endpoint returns
`204 No Content`.
## What Changed
- Added `packages/shared/src/onboarding-telemetry.ts` (exported from
`packages/shared/src/index.ts`) with strict Zod discriminated-union
schemas (`onboardingTelemetryEventSchema`), canonical event names
(`ONBOARDING_TELEMETRY_EVENTS`), and snake_case PostHog property mapping
(`onboardingTelemetryEventToPostHogProperties`).
- Added `server/src/routes/onboarding-telemetry.ts` (`POST
/api/onboarding/telemetry`), mounted in `server/src/app.ts`, enforcing
`assertBoard(req)`, `assertCompanyAccess(req, companyId)` when
`companyId` is present, strict schema validation, and server-side
delivery via `trackCloudPostHogEvent`.
- Updated `ui/src/lib/analytics/onboarding-analytics.ts` to send all
onboarding events to `/api/onboarding/telemetry` with `keepalive: true`
(removing duplicate browser `posthog-js` sends), mapped Step 1 to
`name_org`, fixed `1 -> 3` forward step completion ordering, and added
granular capture helpers.
- Instrumented `ui/src/hooks/useAgentlessOnboardingAutoOpen.ts`
(`onboarding_workspace_loaded`),
`ui/src/components/onboarding/MobileDesktopNudge.tsx`
(`onboarding_mobile_handoff_action`), and
`ui/src/components/OnboardingWizard.tsx` (all step submissions,
back/jump navigation, Cloud trial CTA, model source selection,
credential mode switching, OAuth progress stages, API key submission,
advanced toggle, and launch click). Note: `OnboardingWizard.tsx` is an
existing large file (>1,000 lines); all schema and transport logic lives
in `packages/shared/src/onboarding-telemetry.ts` and
`ui/src/lib/analytics/onboarding-analytics.ts`, with only call-site
wiring added to the wizard.
- Fixed `ui/src/lib/analytics/product-analytics.ts` to buffer events
captured before `startProductAnalytics` runs (still bounded to 50 events
and cleared on user change).
- Added server route tests in
`server/src/__tests__/onboarding-telemetry-routes.test.ts` and expanded
`ui/src/lib/analytics/onboarding-analytics.test.tsx`.
- Updated `tests/runner-e2e/source-sdk-public-inputs.json` for the new
`@paperclipai/shared` export.
## Verification
- `pnpm --filter @paperclipai/shared build` — passed.
- `pnpm --filter @paperclipai/ui typecheck` — passed.
- `pnpm --filter @paperclipai/server typecheck` — passed.
- `pnpm vitest run
server/src/__tests__/onboarding-telemetry-routes.test.ts
ui/src/lib/analytics/onboarding-analytics.test.tsx
ui/src/lib/analytics/product-analytics.test.ts
ui/src/lib/analytics/product-analytics-events.test.ts
ui/src/components/ProductAnalyticsGate.test.tsx
ui/src/hooks/useAgentlessOnboardingAutoOpen.test.tsx` — 6/6 test files
passed (41/41 tests).
- `pnpm verify` — exited with code 2 because
`tests/runner-e2e/source-sdk-public-inputs.json` requires broad CI
coverage; relying on required CI checks for the remaining broad suites.
## Risks
- Low risk: `POST /api/onboarding/telemetry` performs no database
writes, validates all fields against a strict allowlist (enums,
booleans, bounded integers, safe regex slugs), enforces board auth and
company access, and is a no-op returning `204` on self-hosted instances.
- Browser telemetry calls swallow network failures so analytics can
never block or break onboarding.
## Model Used
- Google Gemini (Gemini 4 Neon, Medium) via Antigravity agentic coding
environment with tool use and local command execution.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
This commit is contained in:
1 parent
689bfd04ac
commit
c0edaa21a3
18 files changed
+1877
-182
No files matched your search
@@ -203,9 +203,20 @@ import { DEFAULT_AGENT_ROLE } from "../lib/onboarding-agent-role";
|
||||
import { capsuleHeroMotion, capsuleRoomEnter, capsuleRoomExit, heroRoomArrival, heroRoomMotion, ledeMotion, stepContentMotion, titleSwapMotion } from "./onboarding/onboarding-motion";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
captureOnboardingAdvancedToggled,
|
||||
captureOnboardingApiKeySubmitted,
|
||||
captureOnboardingCredentialModeSwitched,
|
||||
captureOnboardingLaunchClicked,
|
||||
captureOnboardingModelSourceSelected,
|
||||
captureOnboardingOAuthProgress,
|
||||
captureOnboardingStepCompleted,
|
||||
captureOnboardingStepFailed,
|
||||
captureOnboardingStepNavigated,
|
||||
captureOnboardingStepSubmitted,
|
||||
captureOnboardingTrialCtaClicked,
|
||||
onboardingAnalyticsStepFor,
|
||||
useOnboardingAnalytics,
|
||||
type OnboardingAnalyticsOutcome,
|
||||
} from "@/lib/analytics/onboarding-analytics";
|
||||
import {
|
||||
ArrowLeft,
|
||||
@@ -664,10 +675,25 @@ function OnboardingWizardInner({
|
||||
(savedKeys.subscriptions.length > 0 || (adapterType === "claude_local" && savedKeys.storedLogin.data))
|
||||
? "subscription" : savedKeys.options.length || adapterType === "opencode_local" ? "api" : "subscription"
|
||||
);
|
||||
const [connectAnalyticsOverride, setConnectAnalyticsOverride] = useState<{
|
||||
outcome: OnboardingAnalyticsOutcome;
|
||||
adapterType: string;
|
||||
provider: string;
|
||||
} | null>(null);
|
||||
const onboardingAnalytics = useOnboardingAnalytics({
|
||||
open: effectiveOnboardingOpen,
|
||||
step,
|
||||
connectOutcome: credentialMode === "api" ? "api_key" : "subscription",
|
||||
connectOutcome: connectAnalyticsOverride?.outcome ?? (credentialMode === "api" ? "api_key" : "subscription"),
|
||||
companyId: createdCompanyId,
|
||||
provider: connectAnalyticsOverride?.provider ?? aiProviderForAdapter(adapterType),
|
||||
adapterType: connectAnalyticsOverride?.adapterType ?? adapterType,
|
||||
role: agentRole,
|
||||
connectPhase,
|
||||
hadError: Boolean(error),
|
||||
stepViewMeta: {
|
||||
savedKeysCount: savedKeys.options.length,
|
||||
hasExistingSubscription: savedKeys.subscriptions.length > 0,
|
||||
},
|
||||
});
|
||||
const [createdCompanyPrefix, setCreatedCompanyPrefix] = useState<
|
||||
string | null
|
||||
@@ -829,7 +855,21 @@ function OnboardingWizardInner({
|
||||
setEntryStep(initialStepRef.current);
|
||||
}
|
||||
if (!previousRequest?.open) {
|
||||
onboardingAnalytics.opened(initialStepRef.current && !resumesRouteDraft ? initialStepRef.current : step, step);
|
||||
const targetEntryStep = initialStepRef.current && !resumesRouteDraft ? initialStepRef.current : step;
|
||||
const openSource = resumesRouteDraft
|
||||
? "resume_draft"
|
||||
: !onboardingOpen
|
||||
? "route"
|
||||
: routeCompanyId
|
||||
? "auto_open"
|
||||
: "manual";
|
||||
onboardingAnalytics.opened(targetEntryStep, step, {
|
||||
companyId: routeCompanyId ?? createdCompanyIdRef.current,
|
||||
source: openSource,
|
||||
isMobile: mobileOnboardingViewport,
|
||||
resumedDraft: resumesRouteDraft,
|
||||
hasExistingCompany: Boolean(routeCompanyId || createdCompanyIdRef.current),
|
||||
});
|
||||
}
|
||||
if (routeCompanyId) {
|
||||
// Claim ownership only when the route *introduces* a company. A route
|
||||
@@ -1002,6 +1042,7 @@ function OnboardingWizardInner({
|
||||
|
||||
async function handleStartWithCloudTrial(options?: { launchToChat?: boolean }) {
|
||||
if (!createdCompanyId || startingCloudTrial || loading) return;
|
||||
captureOnboardingTrialCtaClicked({ companyId: createdCompanyId });
|
||||
setStartingCloudTrial(true);
|
||||
setError(null);
|
||||
try {
|
||||
@@ -1042,9 +1083,18 @@ function OnboardingWizardInner({
|
||||
agentId = hire.agent.id;
|
||||
setCreatedAgentId(agentId);
|
||||
}
|
||||
setConnectAnalyticsOverride({
|
||||
outcome: "cloud_trial",
|
||||
adapterType: "paperclip_runner",
|
||||
provider: "opencode",
|
||||
});
|
||||
if (options?.launchToChat) {
|
||||
await prepareChat(createdCompanyId, agentId).issue;
|
||||
captureOnboardingStepCompleted("launch", "succeeded");
|
||||
captureOnboardingStepCompleted("launch", "succeeded", {
|
||||
companyId: createdCompanyId,
|
||||
adapterType: "paperclip_runner",
|
||||
provider: "opencode",
|
||||
});
|
||||
if (!stillTheSameCompany(createdCompanyId)) return;
|
||||
onboardingAnalytics.finished();
|
||||
const prefix = createdCompanyPrefix;
|
||||
@@ -1059,8 +1109,22 @@ function OnboardingWizardInner({
|
||||
}
|
||||
} catch (err) {
|
||||
if (options?.launchToChat) {
|
||||
captureOnboardingStepCompleted("launch", "failed");
|
||||
captureOnboardingStepFailed({ step: "launch", reason: "launch_failed" });
|
||||
captureOnboardingStepCompleted("launch", "failed", { companyId: createdCompanyId });
|
||||
captureOnboardingStepFailed({
|
||||
step: "launch",
|
||||
reason: "launch_failed",
|
||||
companyId: createdCompanyId,
|
||||
provider: "opencode",
|
||||
adapterType: "paperclip_runner",
|
||||
});
|
||||
} else {
|
||||
captureOnboardingStepFailed({
|
||||
step: "connect_model",
|
||||
reason: "cloud_trial_failed",
|
||||
companyId: createdCompanyId,
|
||||
provider: "opencode",
|
||||
adapterType: "paperclip_runner",
|
||||
});
|
||||
}
|
||||
setError(err instanceof Error ? err.message : "Could not start right away");
|
||||
} finally {
|
||||
@@ -1808,6 +1872,15 @@ function OnboardingWizardInner({
|
||||
|
||||
|
||||
function unwindConnectStep() {
|
||||
if (credentialMode !== "api" && connectPhase !== "idle" && connectPhase !== "unwindRow") {
|
||||
captureOnboardingOAuthProgress({
|
||||
stage: "abandoned",
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
phase: connectPhase,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
}
|
||||
setOpenedClaudeSessionId(null);
|
||||
localLogin.cancel();
|
||||
localLoginPrimary.resetSubmitting();
|
||||
@@ -1843,6 +1916,13 @@ function OnboardingWizardInner({
|
||||
*/
|
||||
function openConnectAuthorization() {
|
||||
if ((connectPhase !== "ready" && connectPhase !== "waiting") || !connectAuthUrl || retryLogin) return;
|
||||
captureOnboardingOAuthProgress({
|
||||
stage: "auth_link_opened",
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
phase: connectPhase,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
window.open(connectAuthUrl, "_blank", "noreferrer,noopener");
|
||||
setConnectPhase("waiting");
|
||||
}
|
||||
@@ -1851,6 +1931,13 @@ function OnboardingWizardInner({
|
||||
if (setupError) { setSetupError(false); setSetupAttempt(value => value + 1); setError(null); return; }
|
||||
if (browserSignInUnavailable) return;
|
||||
if (retryLogin) {
|
||||
captureOnboardingOAuthProgress({
|
||||
stage: "retried",
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
phase: connectPhase,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
setConnectAuthUrl(null);
|
||||
setSubmitLoginCode(null);
|
||||
setRetryLogin(null);
|
||||
@@ -1869,12 +1956,38 @@ function OnboardingWizardInner({
|
||||
openConnectAuthorization();
|
||||
return;
|
||||
}
|
||||
if (localLoginPrimary.runPrimary()) return;
|
||||
if (localLoginPrimary.runPrimary()) {
|
||||
const stage =
|
||||
localLoginAction?.kind === "retry"
|
||||
? "retried"
|
||||
: localLoginAction?.kind === "open_sign_in"
|
||||
? "auth_link_opened"
|
||||
: null;
|
||||
if (stage) {
|
||||
captureOnboardingOAuthProgress({
|
||||
stage,
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
phase: connectPhase,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
// The hold owns the hire once "Connecting" is showing. That now starts at
|
||||
// the paste, before the credential exists, so Cmd+Enter here would hire
|
||||
// against a source with nothing to run on.
|
||||
if (connectPhase === "connecting") return;
|
||||
if (connectStepLoggingIn) return;
|
||||
if (credentialMode === "api") {
|
||||
captureOnboardingApiKeySubmitted({
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
usedSavedKey: Boolean(selectedApiKey),
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
}
|
||||
setConnectAnalyticsOverride(null);
|
||||
void handleGiveHeartbeat();
|
||||
}
|
||||
|
||||
@@ -2087,6 +2200,21 @@ function OnboardingWizardInner({
|
||||
setCreatedCompanyGoalId(null);
|
||||
}
|
||||
|
||||
function navigateToStep(nextStep: Step, via: "back_button" | "step_indicator") {
|
||||
const fromStep = onboardingAnalyticsStepFor(step);
|
||||
const toStep = onboardingAnalyticsStepFor(nextStep);
|
||||
if (fromStep && toStep && fromStep !== toStep) {
|
||||
captureOnboardingStepNavigated({
|
||||
fromStep,
|
||||
toStep,
|
||||
direction: nextStep < step ? "back" : "jump",
|
||||
via,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
}
|
||||
setStep(nextStep);
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
onboardingAnalytics.dismissed(step);
|
||||
reset();
|
||||
@@ -2165,10 +2293,24 @@ function OnboardingWizardInner({
|
||||
}
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
captureOnboardingStepCompleted("review");
|
||||
const launchAdapterType = connectAnalyticsOverride?.adapterType ?? adapterType;
|
||||
const launchProvider = connectAnalyticsOverride?.provider ?? (managedProvider ?? adapterType);
|
||||
const launchOutcome =
|
||||
connectAnalyticsOverride?.outcome ?? (credentialMode === "api" ? "api_key" : "subscription");
|
||||
captureOnboardingLaunchClicked({
|
||||
companyId: createdCompanyId,
|
||||
adapterType: launchAdapterType,
|
||||
provider: launchProvider,
|
||||
outcome: launchOutcome,
|
||||
});
|
||||
captureOnboardingStepCompleted("review", undefined, { companyId: createdCompanyId });
|
||||
try {
|
||||
await prepareChat(createdCompanyId, createdAgentId).issue;
|
||||
captureOnboardingStepCompleted("launch", "succeeded");
|
||||
captureOnboardingStepCompleted("launch", "succeeded", {
|
||||
companyId: createdCompanyId,
|
||||
adapterType: launchAdapterType,
|
||||
provider: launchProvider,
|
||||
});
|
||||
if (!stillTheSameCompany(createdCompanyId)) return;
|
||||
onboardingAnalytics.finished();
|
||||
const prefix = createdCompanyPrefix;
|
||||
@@ -2179,8 +2321,14 @@ function OnboardingWizardInner({
|
||||
closeOnboarding();
|
||||
navigate(`${prefix ? `/${prefix}` : ""}/chats/${agentId}`, { state: { onboardingWelcome: true } });
|
||||
} catch (err) {
|
||||
captureOnboardingStepCompleted("launch", "failed");
|
||||
captureOnboardingStepFailed({ step: "launch", reason: "launch_failed" });
|
||||
captureOnboardingStepCompleted("launch", "failed", { companyId: createdCompanyId });
|
||||
captureOnboardingStepFailed({
|
||||
step: "launch",
|
||||
reason: "launch_failed",
|
||||
companyId: createdCompanyId,
|
||||
adapterType: launchAdapterType,
|
||||
provider: launchProvider,
|
||||
});
|
||||
setError(err instanceof Error ? err.message : "Failed to open your chat. Please try again.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -2635,6 +2783,10 @@ function OnboardingWizardInner({
|
||||
setSelectedCompanyId(company.id);
|
||||
setStep(3);
|
||||
} catch (err) {
|
||||
captureOnboardingStepFailed({
|
||||
step: "name_org",
|
||||
reason: "company_create_failed",
|
||||
});
|
||||
setError(err instanceof Error ? err.message : "Failed to create organization");
|
||||
} finally {
|
||||
creatingCompanyRef.current = false;
|
||||
@@ -3002,8 +3154,11 @@ function OnboardingWizardInner({
|
||||
// handler whose guard is a piece of state the first one has not set
|
||||
// yet — two organizations for one name, two agents for one hire.
|
||||
if (loading) return;
|
||||
if (step === 1 && companyName.trim()) void handleCreateCompany();
|
||||
else if (step === 3 && agentName.trim()) {
|
||||
if (step === 1 && companyName.trim()) {
|
||||
captureOnboardingStepSubmitted({ step: "name_org", via: "enter", companyId: createdCompanyId });
|
||||
void handleCreateCompany();
|
||||
} else if (step === 3 && agentName.trim()) {
|
||||
captureOnboardingStepSubmitted({ step: "create_agent", via: "enter", companyId: createdCompanyId });
|
||||
if (isFreeInferenceOnboarding) {
|
||||
void handleStartWithCloudTrial({ launchToChat: true });
|
||||
} else {
|
||||
@@ -3023,9 +3178,10 @@ function OnboardingWizardInner({
|
||||
agentName.trim() &&
|
||||
connectStepReady &&
|
||||
(retryLogin || submitLoginCode || Boolean(localLoginAction && !localLoginAction.disabled) || !connectStepLoggingIn)
|
||||
)
|
||||
) {
|
||||
captureOnboardingStepSubmitted({ step: "connect_model", via: "enter", companyId: createdCompanyId });
|
||||
handleConnectStepPrimary();
|
||||
else if (step === 5) handleLaunchToChat();
|
||||
} else if (step === 5) handleLaunchToChat();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3172,7 +3328,7 @@ function OnboardingWizardInner({
|
||||
}}
|
||||
onJumpToStep={(target) => {
|
||||
const targetSteps = isFreeInferenceOnboarding ? [1, 3] : ONBOARDING_WIZARD_STEPS;
|
||||
setStep(targetSteps[target - 1]! as Step);
|
||||
navigateToStep(targetSteps[target - 1]! as Step, "step_indicator");
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
@@ -3190,7 +3346,7 @@ function OnboardingWizardInner({
|
||||
entryStep,
|
||||
})
|
||||
}
|
||||
onJumpToStep={(target) => setStep(AGENT_ARC_WIZARD_STEPS[target - 1]! as Step)}
|
||||
onJumpToStep={(target) => navigateToStep(AGENT_ARC_WIZARD_STEPS[target - 1]! as Step, "step_indicator")}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -3412,10 +3568,15 @@ function OnboardingWizardInner({
|
||||
</div>
|
||||
)}
|
||||
{mobileDesktopHandoffAvailable && createdCompanyId && desktopOnboardingDestination && (
|
||||
<MobileDesktopNudge key={createdCompanyId} destination={desktopOnboardingDestination} onDismiss={() => {
|
||||
setDesktopNudgeDismissedFor(createdCompanyId);
|
||||
modelSourceContainer.current?.querySelector<HTMLElement>('[role="radio"]')?.focus();
|
||||
}} />
|
||||
<MobileDesktopNudge
|
||||
key={createdCompanyId}
|
||||
destination={desktopOnboardingDestination}
|
||||
companyId={createdCompanyId}
|
||||
onDismiss={() => {
|
||||
setDesktopNudgeDismissedFor(createdCompanyId);
|
||||
modelSourceContainer.current?.querySelector<HTMLElement>('[role="radio"]')?.focus();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<div ref={modelSourceContainer}>
|
||||
<ModelSourceTiles
|
||||
@@ -3436,6 +3597,12 @@ function OnboardingWizardInner({
|
||||
settling={connectPhase === "unwindRow"}
|
||||
onSelect={(id) => {
|
||||
if (connectPhase !== "idle" && connectPhase !== "unwindRow") return;
|
||||
captureOnboardingModelSourceSelected({
|
||||
adapterType: id,
|
||||
provider: aiProviderForAdapter(id) ?? id,
|
||||
credentialMode: credentialMode === "api" ? "api_key" : "subscription",
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
autoConnectStartedRef.current = false;
|
||||
setSourcePicked(true);
|
||||
setAdapterType(id);
|
||||
@@ -3481,7 +3648,20 @@ function OnboardingWizardInner({
|
||||
transition={{ opacity: SOURCE_LINK_EXIT, height: MAKE_ROOM }}
|
||||
>
|
||||
<div className="-ml-3 mt-1">
|
||||
<CredentialModeLink mode={credentialMode} onChange={setCredentialMode} />
|
||||
<CredentialModeLink
|
||||
mode={credentialMode}
|
||||
onChange={(nextMode) => {
|
||||
if (nextMode !== credentialMode) {
|
||||
captureOnboardingCredentialModeSwitched({
|
||||
fromMode: credentialMode === "api" ? "api_key" : "subscription",
|
||||
toMode: nextMode === "api" ? "api_key" : "subscription",
|
||||
adapterType: sourcePicked ? adapterType : undefined,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
}
|
||||
setCredentialMode(nextMode);
|
||||
}}
|
||||
/>
|
||||
{savedKeys.options.length > 0 && <p className="px-3 text-sm text-muted-foreground">{savedKeys.options.length} saved API {savedKeys.options.length === 1 ? "key available" : "keys available"}.</p>}
|
||||
{credentialMode === "subscription" && authSignalStatus === "present" && <p className="px-3 text-sm text-muted-foreground">An existing provider connection is available.</p>}
|
||||
</div>
|
||||
@@ -3623,6 +3803,15 @@ function OnboardingWizardInner({
|
||||
active={connectCardLive}
|
||||
onPromptReady={(url) => {
|
||||
if (!connectCardLive) return;
|
||||
if (url && url !== connectAuthUrl) {
|
||||
captureOnboardingOAuthProgress({
|
||||
stage: "started",
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
phase: connectPhase,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
}
|
||||
setConnectAuthUrl(url);
|
||||
// The prompt arriving is what ends the waiting beat.
|
||||
if (url) setConnectPhase((p) => (p === "loading" ? "ready" : p));
|
||||
@@ -3633,6 +3822,13 @@ function OnboardingWizardInner({
|
||||
}}
|
||||
onSubmitReady={submit => setSubmitLoginCode(() => submit)}
|
||||
onCodeSubmitted={() => {
|
||||
captureOnboardingOAuthProgress({
|
||||
stage: "code_submitted",
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
phase: connectPhase,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
// The button reacts to the paste, not to the server.
|
||||
// Waiting for the login to be stored left about a
|
||||
// second of a button still reading "Waiting for code"
|
||||
@@ -3663,11 +3859,20 @@ function OnboardingWizardInner({
|
||||
captureOnboardingStepFailed({
|
||||
step: "connect_model",
|
||||
reason: "subscription_login_failed",
|
||||
companyId: createdCompanyId,
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
method: "subscription",
|
||||
});
|
||||
}}
|
||||
onConnected={(sessionId) => {
|
||||
captureOnboardingOAuthProgress({
|
||||
stage: "connected",
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
phase: connectPhase,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
if (managedSubscriptionProvider) managedSubscriptionRef.current = { companyId: createdCompanyId, binding: { provider: managedSubscriptionProvider, method: "subscription", mode: "responsible_user" }, sessionId };
|
||||
setConnectAuthUrl(null);
|
||||
// Not into a card the customer has left. The panel is
|
||||
@@ -3714,17 +3919,44 @@ function OnboardingWizardInner({
|
||||
{...localLoginPrimary.instructionsProps}
|
||||
authorizationOpened={Boolean(openedClaudeSessionId && openedClaudeSessionId === localLogin.sessionId)}
|
||||
onOpenAuthorization={adapterType === "claude_local" ? (address) => {
|
||||
captureOnboardingOAuthProgress({
|
||||
stage: "auth_link_opened",
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
setOpenedClaudeSessionId(localLogin.sessionId ?? null);
|
||||
window.open(address, "_blank", "noopener,noreferrer");
|
||||
} : undefined}
|
||||
login={{ ...localLogin, retry: () => { prepareLocalLoginRetry(); localLogin.retry(); } }}
|
||||
login={{
|
||||
...localLogin,
|
||||
retry: () => {
|
||||
captureOnboardingOAuthProgress({
|
||||
stage: "retried",
|
||||
provider: managedProvider ?? adapterType,
|
||||
adapterType,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
prepareLocalLoginRetry();
|
||||
localLogin.retry();
|
||||
},
|
||||
}}
|
||||
/>
|
||||
) : browserSignInUnavailable ? <p role="status" className="text-xs text-muted-foreground">This environment does not support browser sign-in. Go back to use an API key or choose another model.</p> : null
|
||||
) : null}
|
||||
</OnboardingSignInRetry.Provider>
|
||||
</OnboardingSignInMark.Provider>
|
||||
{showAdvancedSetup && (
|
||||
<details className="mt-2 space-y-3">
|
||||
<details
|
||||
className="mt-2 space-y-3"
|
||||
onToggle={(event) => {
|
||||
captureOnboardingAdvancedToggled({
|
||||
adapterType,
|
||||
open: event.currentTarget.open,
|
||||
companyId: createdCompanyId,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<summary className="cursor-pointer text-sm text-muted-foreground">Advanced</summary>
|
||||
<OnboardingGatewaySetup
|
||||
companyId={createdCompanyId} agentId={setupAgentId ?? undefined} environmentId={resolvedLoginEnvironmentId ?? undefined}
|
||||
@@ -3925,7 +4157,7 @@ function OnboardingWizardInner({
|
||||
step === 4 && connectPhase !== "idle"
|
||||
? unwindConnectStep
|
||||
: canGoBackFromOnboardingStep({ currentStep: step, entryStep })
|
||||
? () => setStep(backStepFrom(step))
|
||||
? () => navigateToStep(backStepFrom(step), "back_button")
|
||||
: undefined
|
||||
}
|
||||
// The prototype's cloud flow hires on this step and calls the
|
||||
@@ -3971,8 +4203,11 @@ function OnboardingWizardInner({
|
||||
: loading || launchStateIncomplete
|
||||
}
|
||||
onPrimary={() => {
|
||||
if (step === 1) void handleCreateCompany();
|
||||
else if (step === 3) {
|
||||
if (step === 1) {
|
||||
captureOnboardingStepSubmitted({ step: "name_org", via: "button", companyId: createdCompanyId });
|
||||
void handleCreateCompany();
|
||||
} else if (step === 3) {
|
||||
captureOnboardingStepSubmitted({ step: "create_agent", via: "button", companyId: createdCompanyId });
|
||||
if (isFreeInferenceOnboarding) {
|
||||
void handleStartWithCloudTrial({ launchToChat: true });
|
||||
} else {
|
||||
@@ -3982,8 +4217,10 @@ function OnboardingWizardInner({
|
||||
// One button, two jobs — start the sign-in, or hire — and
|
||||
// Cmd+Enter has to do the same thing. See
|
||||
// `handleConnectStepPrimary`.
|
||||
else if (step === 4) handleConnectStepPrimary();
|
||||
else handleLaunchToChat();
|
||||
else if (step === 4) {
|
||||
captureOnboardingStepSubmitted({ step: "connect_model", via: "button", companyId: createdCompanyId });
|
||||
handleConnectStepPrimary();
|
||||
} else handleLaunchToChat();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useEffect, useId, useRef, useState, useSyncExternalStore } from "react"
|
||||
import { Check, Copy, Monitor } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { captureOnboardingMobileHandoffAction } from "@/lib/analytics/onboarding-analytics";
|
||||
import { copyTextToClipboard } from "@/lib/clipboard";
|
||||
|
||||
const DESKTOP_WIDTH = "(min-width: 40rem)";
|
||||
@@ -20,7 +21,15 @@ export function useMobileOnboardingViewport() {
|
||||
);
|
||||
}
|
||||
|
||||
export function MobileDesktopNudge({ destination, onDismiss }: { destination: string; onDismiss: () => void }) {
|
||||
export function MobileDesktopNudge({
|
||||
destination,
|
||||
companyId,
|
||||
onDismiss,
|
||||
}: {
|
||||
destination: string;
|
||||
companyId?: string | null;
|
||||
onDismiss: () => void;
|
||||
}) {
|
||||
const headingId = useId();
|
||||
const handoffId = useId();
|
||||
const linkId = useId();
|
||||
@@ -29,6 +38,10 @@ export function MobileDesktopNudge({ destination, onDismiss }: { destination: st
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const [copyState, setCopyState] = useState<"idle" | "copied" | "manual">("idle");
|
||||
|
||||
useEffect(() => {
|
||||
captureOnboardingMobileHandoffAction({ action: "shown", companyId });
|
||||
}, [companyId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (expanded) handoffRef.current?.scrollIntoView({ block: "nearest" });
|
||||
}, [expanded]);
|
||||
@@ -37,8 +50,10 @@ export function MobileDesktopNudge({ destination, onDismiss }: { destination: st
|
||||
try {
|
||||
await copyTextToClipboard(destination);
|
||||
setCopyState("copied");
|
||||
captureOnboardingMobileHandoffAction({ action: "copy_link", companyId });
|
||||
} catch {
|
||||
setCopyState("manual");
|
||||
captureOnboardingMobileHandoffAction({ action: "copy_link_manual", companyId });
|
||||
linkRef.current?.focus();
|
||||
linkRef.current?.select();
|
||||
}
|
||||
@@ -54,10 +69,31 @@ export function MobileDesktopNudge({ destination, onDismiss }: { destination: st
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-1">
|
||||
<Button type="button" variant="outline" className="h-(--sz-44px) px-2" aria-controls={handoffId} aria-expanded={expanded} onClick={() => setExpanded((open) => !open)}>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="h-(--sz-44px) px-2"
|
||||
aria-controls={handoffId}
|
||||
aria-expanded={expanded}
|
||||
onClick={() => {
|
||||
const next = !expanded;
|
||||
setExpanded(next);
|
||||
if (next) captureOnboardingMobileHandoffAction({ action: "expanded", companyId });
|
||||
}}
|
||||
>
|
||||
Continue on desktop
|
||||
</Button>
|
||||
<Button type="button" variant="ghost" className="h-(--sz-44px) px-2" onClick={onDismiss}>Keep going here</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
className="h-(--sz-44px) px-2"
|
||||
onClick={() => {
|
||||
captureOnboardingMobileHandoffAction({ action: "dismissed", companyId });
|
||||
onDismiss();
|
||||
}}
|
||||
>
|
||||
Keep going here
|
||||
</Button>
|
||||
</div>
|
||||
<div id={handoffId} ref={handoffRef} hidden={!expanded}>
|
||||
{expanded && (
|
||||
|
||||
Reference in new issue
Block a user