1import{z as S,D as C,E as $,e as j,P as R,r as F,f as b,j as e,C as N,a as P,b as E,d as f,N as x,k as L}from"./index-DHwBXtP2.js";import{u as _}from"./auth-context-CZDSnG7n.js";import{A}from"./analytics-subnav-DU9k3OM0.js";const B=S({method:"GET"}).middleware([C]).handler($("src_lib_funnel-roi_functions_ts--getFunnelRoi_createServerFn_handler")),q=[7,14,30,60,90];function U(){const a=j(R),o=j(B),{session:c}=_(),[i,y]=F.useState(30),{data:v}=b({queryKey:["workspaces"],queryFn:()=>a({}),enabled:!!c}),u=v?.[0],{data:p,isLoading:n}=b({queryKey:["funnel-roi",u?.id,i],queryFn:()=>o({data:{workspaceId:u.id,days:i}}),enabled:!!u,staleTime:300*1e3}),m=p?.rows??[],t=p?.totals,h=p?.spendUsd??0,w=t&&t.views>0?t.submits/t.views:0,k=t&&t.submits>0?t.bookings/t.submits:0,g=t&&t.submits>0?Math.round(h/t.submits*100)/100:null;return e.jsxs("div",{className:"space-y-6",children:[e.jsx(A,{}),e.jsxs("header",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:"Funnel ROI"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Per-landing-page funnel economics â views, opt-in rate, bookings, exit-intent saves, and allocated ad spend. Use this to spot which variant is actually moving money."})]}),e.jsx("div",{className:"flex items-center gap-2",children:q.map(s=>e.jsxs("button",{onClick:()=>y(s),className:`rounded-md border px-3 py-1 text-xs ${i===s?"bg-primary text-primary-foreground":"bg-card"}`,children:[s,"d"]},s))})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-5",children:[e.jsx(r,{label:"Total views",value:l(t?.views??0),loading:n}),e.jsx(r,{label:"Opt-ins",value:l(t?.submits??0),loading:n,sub:`${d(w)} CVR`}),e.jsx(r,{label:"Bookings",value:l(t?.bookings??0),loading:n,sub:`${d(k)} of opt-ins`}),e.jsx(r,{label:"Exit-intent saves",value:l(t?.exitIntent??0),loading:n,sub:"recoverable abandoners"}),e.jsx(r,{label:"Blended CPL",value:g!=null?`$${g}`:"â",loading:n,sub:`$${l(h)} ad spend`})]}),e.jsxs(N,{children:[e.jsx(P,{children:e.jsx(E,{className:"text-base",children:"Per-variant breakdown"})}),e.jsx(f,{className:"overflow-x-auto p-0",children:n?e.jsxs("div",{className:"space-y-2 p-6",children:[e.jsx(x,{className:"h-8 w-full"}),e.jsx(x,{className:"h-8 w-full"}),e.jsx(x,{className:"h-8 w-full"})]}):m.length===0?e.jsx("p",{className:"p-6 text-sm text-muted-foreground",children:"No landing-page traffic in this window yet. Once visitors land on a published Brain LP, you'll see per-variant funnel ROI here."}):e.jsxs("table",{className:"w-full min-w-[920px] border-collapse text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left",children:"Variant"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Views"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Opt-ins"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"CVR"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Bookings"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Book%"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Scroll"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Exit"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Spend"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"CPL"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"CPA"})]})}),e.jsx("tbody",{children:m.map(s=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"max-w-[280px] px-4 py-3",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("a",{href:`/lp/${s.slug}`,target:"_blank",rel:"noreferrer",className:"truncate text-sm font-medium hover:underline",children:s.headline??s.slug}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["/",s.slug]}),s.stage&&e.jsx(L,{variant:"outline",className:"h-4 px-1 text-[10px]",children:s.stage})]})]})}),e.jsx("td",{className:"px-3 py-3 text-right tabular-nums",children:l(s.views)}),e.jsx("td",{className:"px-3 py-3 text-right tabular-nums",children:l(s.submits)}),e.jsx("td",{className:"px-3 py-3 text-right tabular-nums",children:d(s.leadRate)}),e.jsx("td",{className:"px-3 py-3 text-right tabular-nums",children:l(s.bookings)}),e.jsx("td",{className:"px-3 py-3 text-right tabular-nums",children:d(s.bookRate)}),e.jsx("td",{className:"px-3 py-3 text-right tabular-nums",children:s.avgScroll!=null?`${s.avgScroll}%`:"â"}),e.jsx("td",{className:"px-3 py-3 text-right tabular-nums",children:l(s.exitIntent)}),e.jsxs("td",{className:"px-3 py-3 text-right tabular-nums",children:["$",l(s.allocSpendUsd)]}),e.jsx("td",{className:"px-3 py-3 text-right tabular-nums",children:s.cpl!=null?`$${s.cpl}`:"â"}),e.jsx("td",{className:"px-3 py-3 text-right tabular-nums",children:s.cpa!=null?`$${s.cpa}`:"â"})]},s.id))})]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Spend is allocated proportionally to each LP's share of total views. CPL / CPA reflect that allocation against actual opt-ins and bookings."})]})}function r({label:a,value:o,sub:c,loading:i}){return e.jsx(N,{children:e.jsxs(f,{className:"p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:a}),i?e.jsx(x,{className:"mt-2 h-6 w-20"}):e.jsx("div",{className:"mt-1 text-2xl font-semibold tabular-nums",children:o}),c&&e.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:c})]})})}function l(a){return Number.isFinite(a)?Math.abs(a)>
1=1e3?a.toLocaleString():String(a):"â"}function d(a){return`${Math.round(a*1e3)/10}%`}export{U as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.