1import{r as n,j as e}from"./react-vendor-DBDodRiA.js";const o=s=>(s*100).toFixed(1)+"%",c=s=>s>=1e3?(s/1e3).toFixed(1)+"k":String(s);function v(s){return s.uniqueVisitors===0?{text:"no traffic",tone:"text-white/25"}:s.bought>0?{text:`converted ${s.bought}`,tone:"text-emerald-400"}:s.reachedCheckout>0?{text:"checkout, no buy",tone:"text-amber-400"}:s.checkoutFailed>0?{text:"checkout failed",tone:"text-rose-400"}:s.ctaClicks>0?{text:"clicked, no checkout",tone:"text-amber-300/80"}:{text:"traffic, no intent",tone:"text-white/35"}}function k(){const[s,l]=n.useState(14),[a,h]=n.useState("day"),[r,b]=n.useState(null),[f,m]=n.useState(!1),[p,w]=n.useState(null),g=n.useCallback(async()=>{m(!0),w(null);try{const t=await fetch(`/api/admin/campaigns?days=${s}&granularity=${a}`,{credentials:"include"});if(!t.ok)throw new Error("HTTP "+t.status);b(await t.json())}catch(t){w(t?.message??"failed")}finally{m(!1)}},[s,a]);n.useEffect(()=>{g()},[g]);const i=r?.totals;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-white",children:"Campaigns"}),e.jsxs("p",{className:"text-sm text-white/40 mt-0.5",children:["Per-",a," read on each day's ad. Unique visitors, visits and page views kept distinct, plus the checkout funnel."]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"inline-flex rounded-lg border border-white/10 overflow-hidden",children:[7,14,30,90].map(t=>e.jsxs("button",{onClick:()=>l(t),className:`px-3 py-1.5 text-xs font-semibold ${s===t?"bg-fuchsia-500/20 text-fuchsia-300":"text-white/40 hover:text-white/70"}`,children:[t,"d"]},t))}),e.jsx("div",{className:"inline-flex rounded-lg border border-white/10 overflow-hidden",children:["day","hour"].map(t=>e.jsx("button",{onClick:()=>h(t),className:`px-3 py-1.5 text-xs font-semibold uppercase ${a===t?"bg-fuchsia-500/20 text-fuchsia-300":"text-white/40 hover:text-white/70"}`,children:t},t))})]})]}),p&&e.jsx("div",{className:"rounded-lg border border-rose-500/30 bg-rose-500/10 p-3 text-sm text-rose-300",children:p}),r?.capped&&e.jsx("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/10 p-2 text-xs text-amber-300",children:"High volume: counts in this window are sampled to the cap and may slightly under-report."}),f&&!r&&e.jsx("div",{className:"text-white/40 text-sm py-8 text-center",children:"Loadingâ¦"}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-3",children:[e.jsx(d,{label:"Unique Visitors",sub:"distinct people",value:c(i.uniqueVisitors),accent:!0}),e.jsx(d,{label:"Visits",sub:"incl. repeats",value:c(i.visits)}),e.jsx(d,{label:"Page Views",sub:"all page hits",value:c(i.pageViews)}),e.jsx(d,{label:"Reached Checkout",sub:o(i.checkoutRate)+" of visitors",value:c(i.reachedCheckout)}),e.jsx(d,{label:"Checkout Failed",value:c(i.checkoutFailed),tone:i.checkoutFailed?"text-rose-400":void 0}),e.jsx(d,{label:"Bought",sub:o(i.buyRate)+" buy rate",value:c(i.bought),tone:"text-emerald-400"}),e.jsx(d,{label:"Revenue",sub:o(i.closeRate)+" close",value:"$"+c(i.revenue),tone:"text-emerald-400"})]}),e.jsxs("div",{className:"rounded-xl border border-white/10 bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-wider text-white/40 mb-2",children:["Funnel (",r.days,"d): where they fall out"]}),e.jsx(N,{steps:[{k:"Visited",v:i.uniqueVisitors,c:"bg-fuchsia-500"},{k:"Reached checkout",v:i.reachedCheckout,c:"bg-violet-500"},{k:"Bought",v:i.bought,c:"bg-emerald-500"}]}),e.jsxs("div",{className:"mt-2 text-xs text-white/40",children:[i.uniqueVisitors-i.reachedCheckout," left before checkout · ",i.reachedCheckout-i.bought," abandoned at checkout",i.checkoutFailed?` · ${i.checkoutFailed} payment failures`:""]})]}),e.jsx("div",{className:"rounded-xl border border-white/10 overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-white/[0.03] text-white/40 text-[11px] uppercase tracking-wider",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-3 py-2",children:a==="hour"?"Hour":"Day"}),e.jsx("th",{className:"text-right px-3 py-2",children:"Unique"}),e.jsx("th",{className:"text-right px-3 py-2",children:"Visits"}),e.jsx("th",{className:"text-right px-3 py-2",children:"Views"}),e.jsx("th",{className:"text-right px-3 py-2",children:"Checkout"}),e.jsx("th",{className:"text-right px-3 py-2",children:"Failed"}),e.jsx("th",{className:"text-right px-3 py-2",children:"Bought"}),e.jsx("th",{className:"text-right px-3 py-2",children:"Buy%"}),e.jsx("th",{className:"text-left px-3 py-2",children:"Read"})]})}),e.jsxs("tbody",{children:[[...r.series].reverse().map(t=>{const x=v(t);return e.jsxs("tr",{className:"border-t border-white/[0.06] hover:bg-white/[0.02]",children:[e.jsx("td",{className:"px-3 py-2 font-mono text-xs text-white/70 whitespace-nowrap",children:t.bucket.replace("T"," ")}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums font-semibold text-fuchsia-300",children:t.uniqueVisitors}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-white/70",children:t.visits}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-white/50",children:t.pageViews}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-violet-300",children:t.reachedCheckout||""}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-rose-400/80",children:t.checkoutFailed||""}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-emerald-400 font-semibold",children:t.bought||""}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-white/60",children:t.uniqueVisitors?o(t.bought/t.uniqueVisitors):""}),e.jsx("td",{className:`px-3 py-2 text-xs ${x.tone}`,children:x.text})]},t.bucket)}),r.series.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:9,className:"px-3 py-8 text-center text-white/30",children:"No traffic in this window."})})]})]})}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsx(u,{title:"Pages visited",children:r.topPages.map(t=>e.jsx(j,{left:e.jsx("span",{className:"font-mono text-xs text-white/70 truncate",children:t.path}),right:`${c(t.views)} views`,frac:t.views/(r.topPages[0]?.views||1)},t.path))}),e.jsx(u,{title:"Traffic sources (ad attribution)",children:r.topSources.map(t=>e.jsx(j,{left:e.jsx("span",{className:"text-sm text-white/70 truncate",children:t.source}),right:`${c(t.views)}`,frac:t.views/(r.topSources[0]?.views||1)},t.source))})]}),e.jsxs(u,{title:`Checkout abandons (${i.abandonCount}) â clicked checkout, never bought`,children:[r.abandons.length===0&&e.jsx("div",{className:"text-white/30 text-sm py-2",children:"None in this window."}),r.abandons.map((t,x)=>e.jsxs("div",{className:"flex items-center justify-between gap-2 py-1.5 border-t border-white/[0.05] text-xs",children:[e.jsxs("span",{className:"font-mono text-white/50 truncate",children:[t.id,t.identified?"":" (anon)"]}),e.jsx("span",{className:"text-white/60",children:t.plan??"â"}),e.jsx("span",{className:"text-white/35 whitespace-nowrap",children:new Date(t.when).toLocaleStr
1ing([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})})]},x))]})]})]})}function d({label:s,value:l,sub:a,accent:h,tone:r}){return e.jsxs("div",{className:`rounded-xl border p-3 ${h?"border-fuchsia-500/30 bg-fuchsia-500/[0.06]":"border-white/10 bg-white/[0.02]"}`,children:[e.jsx("div",{className:`text-xl font-bold tabular-nums ${r??(h?"text-fuchsia-300":"text-white")}`,children:l}),e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-white/40 mt-0.5 leading-tight",children:s}),a&&e.jsx("div",{className:"text-[10px] text-white/30 mt-0.5",children:a})]})}function N({steps:s}){const l=Math.max(1,s[0]?.v??1);return e.jsx("div",{className:"space-y-1.5",children:s.map(a=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-32 text-xs text-white/50 shrink-0",children:a.k}),e.jsx("div",{className:"flex-1 h-5 rounded bg-white/[0.04] overflow-hidden",children:e.jsx("div",{className:`h-full ${a.c} rounded`,style:{width:`${Math.max(2,a.v/l*100)}%`}})}),e.jsx("div",{className:"w-12 text-right text-xs tabular-nums text-white/70",children:a.v})]},a.k))})}function u({title:s,children:l}){return e.jsxs("div",{className:"rounded-xl border border-white/10 bg-white/[0.02] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-white/40 mb-2",children:s}),e.jsx("div",{children:l})]})}function j({left:s,right:l,frac:a}){return e.jsxs("div",{className:"py-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0",children:s}),e.jsx("span",{className:"text-xs text-white/40 tabular-nums shrink-0",children:l})]}),e.jsx("div",{className:"h-1 rounded-full bg-white/[0.05] mt-1 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-fuchsia-500/40",style:{width:`${Math.min(100,a*100)}%`}})})]})}export{k as default};
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.