From 88399899c130eb76bc5fd974aa09c1e2a88dd1c8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 15:15:50 +0000 Subject: [PATCH] feat(firecms_cloud): record what visitors do on the login screen before leaving Between a third and a half of everyone who reaches this screen never clicks any sign-in method: 31.0% in May 2026 rising to 42.4% in October, which was 117 people that month. The screen only emitted "shown" and "method clicked", so someone with no Google session, someone who balked at the permissions wording and someone who only wanted a demo were one undifferentiated number. The August change that made the gated buttons live was aimed at a guess about which of those it was, and the rate kept climbing afterwards. This adds the events that would tell them apart: - `view_displayed` now says what the screen offered: whether terms were required, whether admin scopes were requested, and whether the layout was the narrow one-column form, so a phone-only drop-off is visible as such. - `terms_toggled` records engagement with the consent gate itself. - `terms_required_blocked` carries how many times that visitor was stopped. - `view_abandoned` fires when someone leaves having attempted nothing, carrying time on screen, whether terms were ticked and how often they were blocked. It listens on `pagehide`, which fires on mobile where `beforeunload` does not, and on unmount for in-app navigation. Both paths are guarded so it is sent at most once, and never after an attempt, so a successful sign-in does not read as an abandonment. The callback is read through a ref in that effect because host apps pass a fresh closure each render, which would otherwise resubscribe and fire the cleanup on every render. Firing of the existing events is unchanged. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_011VZh1qoNGKbXQrrrFiDoeQ --- .../components/auth/FireCMSCloudLoginView.tsx | 66 +++++++++++++++++-- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/packages/firecms_cloud/src/components/auth/FireCMSCloudLoginView.tsx b/packages/firecms_cloud/src/components/auth/FireCMSCloudLoginView.tsx index f2f3f30cc..a524b672a 100644 --- a/packages/firecms_cloud/src/components/auth/FireCMSCloudLoginView.tsx +++ b/packages/firecms_cloud/src/components/auth/FireCMSCloudLoginView.tsx @@ -75,6 +75,26 @@ export function FireCMSCloudLoginView({ const [fadeIn, setFadeIn] = useState(false); const [passwordLoginSelected, setPasswordLoginSelected] = useState(false); + // Why people leave this screen is the funnel's largest unknown: between a + // third and a half of everyone who reaches it never clicks any method, and + // the only events were "screen shown" and "method clicked", with nothing in + // between to tell those cases apart. These refs let the view say what the + // visitor did before they went. + const attemptedRef = React.useRef(false); + const abandonReportedRef = React.useRef(false); + const shownAtRef = React.useRef(Date.now()); + const timesBlockedRef = React.useRef(0); + const termsAcceptedRef = React.useRef(false); + // Host apps pass a fresh closure on every render, so the abandonment effect + // reads the callback through a ref and never re-subscribes on it. + const onAnalyticsEventRef = React.useRef(onAnalyticsEvent); + onAnalyticsEventRef.current = onAnalyticsEvent; + + const attemptMethod = (event: string) => { + attemptedRef.current = true; + onAnalyticsEvent?.(event); + }; + // The consent checkbox gates sign in, but it used to do it by disabling both // buttons, so a click landed on a dead control that never said why. Roughly // a third of everyone who reached this screen left without attempting any @@ -86,7 +106,8 @@ export function FireCMSCloudLoginView({ return true; } setTermsMissing(true); - onAnalyticsEvent?.("terms_required_blocked"); + timesBlockedRef.current += 1; + onAnalyticsEvent?.("terms_required_blocked", { times_blocked: timesBlockedRef.current }); termsRowRef.current?.querySelector("button")?.focus(); return false; }; @@ -95,10 +116,43 @@ export function FireCMSCloudLoginView({ const timer = setTimeout(() => { setFadeIn(true); }, 10); - onAnalyticsEvent?.("view_displayed", { variant }); + onAnalyticsEvent?.("view_displayed", { + variant, + terms_required: includeTermsAndNewsLetter, + admin_scopes: includeGoogleAdminScopes, + // Narrow is the stacked one-column layout, so a drop-off that is + // only happening on phones can be told from a general one. + layout: typeof window === "undefined" + ? "unknown" + : (window.innerWidth < 1024 ? "narrow" : "wide") + }); return () => clearTimeout(timer); }, [onAnalyticsEvent, variant]); + // Leaving without trying to sign in. `pagehide` is the signal that fires on + // mobile, where `beforeunload` does not; the cleanup covers navigating away + // inside the app. Both are guarded so this is sent at most once, and never + // once a method has been attempted — a successful sign-in unmounts this + // view and must not look like an abandonment. + useEffect(() => { + const report = (reason: string) => { + if (attemptedRef.current || abandonReportedRef.current) return; + abandonReportedRef.current = true; + onAnalyticsEventRef.current?.("view_abandoned", { + reason, + seconds_on_screen: Math.round((Date.now() - shownAtRef.current) / 1000), + terms_accepted: termsAcceptedRef.current, + times_blocked: timesBlockedRef.current + }); + }; + const onPageHide = () => report("page_hidden"); + window.addEventListener("pagehide", onPageHide); + return () => { + window.removeEventListener("pagehide", onPageHide); + report("unmounted"); + }; + }, []); + function buildErrorView() { let errorView: any; const ignoredCodes = ["auth/popup-closed-by-user", "auth/cancelled-popup-request"]; @@ -170,7 +224,7 @@ export function FireCMSCloudLoginView({ { - onAnalyticsEvent?.("google_attempt"); + attemptMethod("google_attempt"); fireCMSBackend.googleLogin(includeGoogleAdminScopes).then((user) => { onAnalyticsEvent?.("google_success"); }).catch((error) => { @@ -306,7 +360,9 @@ export function FireCMSCloudLoginView({ checked={termsAccepted} onCheckedChange={(checked) => { setTermsAccepted(checked); + termsAcceptedRef.current = checked; if (checked) setTermsMissing(false); + onAnalyticsEvent?.("terms_toggled", { accepted: checked }); }} size="small" /> @@ -353,7 +409,7 @@ export function FireCMSCloudLoginView({ {!passwordLoginSelected && { if (!consentSatisfied()) return; - onAnalyticsEvent?.("google_attempt"); + attemptMethod("google_attempt"); fireCMSBackend.googleLogin(includeGoogleAdminScopes).then((user) => { onAnalyticsEvent?.("google_success"); if (subscribeToNewsletter && user?.email) { @@ -369,7 +425,7 @@ export function FireCMSCloudLoginView({ icon={} onClick={() => { if (!consentSatisfied()) return; - onAnalyticsEvent?.("password_method_selected"); + attemptMethod("password_method_selected"); setPasswordLoginSelected(true); }}/>}