Skip to content

Commit e5ee3e9

Browse files
committed
feat(ui): track guest draft migration flow
1 parent fc76814 commit e5ee3e9

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/app/[locale]/login/page.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { useState, Suspense } from "react";
44
import { signIn } from "next-auth/react";
55
import { useSearchParams } from "next/navigation";
66
import { Link } from "@/i18n/routing";
7-
import { GUEST_STORAGE_KEY } from "@/lib/constants";
7+
import { trackUsageEvent } from "@/actions/usage-event";
8+
import { GUEST_MIGRATION_META_KEY, GUEST_STORAGE_KEY } from "@/lib/constants";
9+
import { USAGE_EVENTS } from "@/lib/usage-events";
810

911
function LoginForm() {
1012
const [email, setEmail] = useState("");
@@ -45,13 +47,22 @@ function LoginForm() {
4547
try {
4648
const stored = localStorage.getItem(GUEST_STORAGE_KEY);
4749
if (stored) {
50+
const rawMeta = localStorage.getItem(GUEST_MIGRATION_META_KEY);
51+
const metadata = rawMeta ? JSON.parse(rawMeta) : null;
52+
void trackUsageEvent(USAGE_EVENTS.GUEST_MIGRATION_STARTED, {
53+
source: metadata?.source || "unknown",
54+
});
55+
4856
const parsed = JSON.parse(stored);
4957
const response = await fetch("/api/resume/guest", {
5058
method: "POST",
5159
headers: {
5260
"Content-Type": "application/json",
5361
},
54-
body: JSON.stringify(parsed),
62+
body: JSON.stringify({
63+
...parsed,
64+
metadata,
65+
}),
5566
});
5667

5768
if (!response.ok) {
@@ -60,12 +71,18 @@ function LoginForm() {
6071

6172
const resume = await response.json();
6273
localStorage.removeItem(GUEST_STORAGE_KEY);
74+
localStorage.removeItem(GUEST_MIGRATION_META_KEY);
75+
void trackUsageEvent(USAGE_EVENTS.GUEST_MIGRATION_SUCCEEDED, {
76+
resumeId: resume.id,
77+
});
6378
window.location.href = `/builder/${resume.id}`;
6479
return;
6580
}
6681
} catch {
6782
// If migration fails, fall through to normal redirect
6883
localStorage.removeItem(GUEST_STORAGE_KEY);
84+
localStorage.removeItem(GUEST_MIGRATION_META_KEY);
85+
void trackUsageEvent(USAGE_EVENTS.GUEST_MIGRATION_FAILED);
6986
}
7087
window.location.href = callbackUrl;
7188
}

0 commit comments

Comments
 (0)