PageSourceSearch

https://iconaapp.com/assets/analytics-BHNo6FBU.js

js iconaapp.com collected 2026-10-06 15:23:54 UTC 15,093 bytes, 1 lines download raw bytes

1import{a as te,r as p,d as le,j as e,B as E,a5 as oe,a6 as ne,a7 as ie,I as K,g as de}from"./index-WHULU0jW.js";import{C as ce,b as me}from"./card-BlH5Drk3.js";import{L as _}from"./label-Cp0G8FgB.js";import{D as ue,a as he,b as pe,c as xe}from"./dropdown-menu-BdEO2wJn.js";import{S as fe,a as ve,b as ye,c as ge,d as D}from"./select-GrX3B2N2.js";import{u as we}from"./use-currency-DCGG8bRS.js";import{C as be}from"./chevron-left-CzzQDnh7.js";import{C as je}from"./chevron-right-DeJyYtwC.js";import{C as ke}from"./calendar-C_F-JVbg.js";import{C as Se}from"./chevron-down-6yZoXBwj.js";import{I as Ne}from"./info-CgmwUdS-.js";import{y as Ce,I as w,X as b,Y as j,J as Te,R as Ee,E as L,K as O,B as De,F as Le}from"./LineChart-DNj752w4.js";import"./index-DXGq4QHA.js";import"./index-B_Td0hGN.js";import"./index-BdQq_4o_.js";import"./index-BFruoVYP.js";import"./chevron-up-CBx5ZPzc.js";import"./index-B4rsJcUY.js";var U=Ce({chartName:"BarChart",GraphicalChild:w,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:b},{axisType:"yAxis",AxisComp:j}],formatAxisMap:Te});const M={sales:{label:"Estimated Sales Metrics",metrics:[{key:"sales",label:"Est. Sales",type:"currency",split:!0,timeseries:!0,available:!0},{key:"earnings",label:"Est. Earnings",type:"currency",split:!0,timeseries:!0,available:!0},{key:"aov",label:"Est. Avg Order Value",type:"currency",split:!1,timeseries:!0,available:!0},{key:"orders",label:"Est. Order Count",type:"number",split:!0,timeseries:!0,available:!0}]},user:{label:"User Metrics",metrics:[{key:"buyers",label:"Buyer Count",type:"number",split:!0,timeseries:!0,available:!0},{key:"follows",label:"Follows",type:"number",split:!1,timeseries:!1,available:!0,note:"Total current followers. A day-by-day breakdown isn't provided by the data source."},{key:"shares",label:"Buyer Shares",type:"number",split:!1,timeseries:!1,available:!1,note:"Share tracking isn't available from the data source yet."},{key:"referrals",label:"Buyer Referrals",type:"number",split:!1,timeseries:!1,available:!0,note:"Total referrals. A day-by-day breakdown isn't provided by the data source."}]},stream:{label:"Stream Metrics",metrics:[{key:"viewers",label:"Max Concurrent Viewers",type:"number",split:!1,timeseries:!1,available:!1,note:"Historical peak viewership isn't recorded by the data source yet."},{key:"lives",label:"Number of Lives",type:"number",split:!1,timeseries:!0,available:!0},{key:"streamedTime",label:"Streamed Time",type:"duration",split:!1,timeseries:!1,available:!1,note:"Stream duration isn't recorded by the data source yet."}]}},y="hsl(var(--chart-1))",W="hsl(var(--chart-5))";function Oe(t){return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`}function g(t){return Oe(t)}function Y(t){const m=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!m)return null;const h=new Date(Number(m[1]),Number(m[2])-1,Number(m[3]));return isNaN(h.getTime())?null:h}function Je(){const{user:t}=te(),{format:m}=we(),[h,A]=p.useState(()=>{const s=new Date;return s.setHours(0,0,0,0),s.setDate(s.getDate()-13),s}),[x,B]=p.useState(()=>{const s=new Date;return s.setHours(23,59,59,999),s}),[$,q]=p.useState({sales:"sales",user:"buyers",stream:"lives"}),[k,I]=p.useState("sales"),[u,X]=p.useState("all"),J=p.useMemo(()=>{const s=x.getTime()-h.getTime();return Math.max(1,Math.floor(s/864e5)+1)},[h,x]),R=s=>{const r=J*864e5;A(i=>{const d=new Date(i.getTime()+s*r);return d.setHours(0,0,0,0),d}),B(i=>{const d=new Date(i.getTime()+s*r);return d.setHours(23,59,59,999),d})},{data:o,isLoading:Q}=le({queryKey:["/api/seller/analytics",t==null?void 0:t.id,h.toISOString(),x.toISOString()],enabled:!!(t!=null&&t.id),staleTime:0,refetchOnMount:"always",queryFn:async()=>{const s=new URLSearchParams;s.set("userId",t.id),s.set("startDate",h.toISOString()),s.set("endDate",x.toISOString());const r=await de(`/api/seller/analytics?${s.toString()}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!r.ok)throw new Error(`API error: ${r.status}`);return r.json()}}),a=o==null?void 0:o.totals,f=(o==null?void 0:o.availability)??{shares:!1,maxConcurrentViewers:!1,streamedTime:!1},Z=(a==null?void 0:a.follows)??0,ee=(a==null?void 0:a.referrals)??0,F=p.useMemo(()=>((o==null?void 0:o.daily)??[]).map(r=>{const i=new Date(`${r.date}T00:00:00`),d=isNaN(i.getTime())?r.date:i.toLocaleDateString(void 0,{month:"short",day:"numeric"}),T=r.showSales+r.mpSales,c=r.showOrders+r.mpOrders;return{label:d,showSales:r.showSales,mpSales:r.mpSales,showEarnings:r.showEarnings,mpEarnings:r.mpEarnings,showOrders:r.showOrders,mpOrders:r.mpOrders,showBuyers:r.showBuyers,mpBuyers:r.mpBuyers,showAov:r.showOrders?r.showSales/r.showOrders:0,mpAov:r.mpOrders?r.mpSales/r.mpOrders:0,aov:c?T/c:0,lives:r.lives}}),[o]),l=p.useMemo(()=>{const r=((o==null?void 0:o.daily)??[]).reduce((i,d)=>i+(d.lives??0),0);return{sales:(a==null?void 0:a.sales.all)??0,showSales:(a==null?void 0:a.sales.show)??0,mpSales:(a==null?void 0:a.sales.marketplace)??0,earnings:(a==null?void 0:a.earnings.all)??0,showEarnings:(a==null?void 0:a.earnings.show)??0,mpEarnings:(a==null?void 0:a.earnings.marketplace)??0,aov:(a==null?void 0:a.aov.all)??0,showAov:(a==null?void 0:a.aov.show)??0,mpAov:(a==null?void 0:a.aov.marketplace)??0,orders:(a==null?void 0:a.orders.all)??0,showOrders:(a==null?void 0:a.orders.show)??0,mpOrders:(a==null?void 0:a.orders.marketplace)??0,buyers:(a==null?void 0:a.buyers.all)??0,showBuyers:(a==null?void 0:a.buyers.show)??0,mpBuyers:(a==null?void 0:a.buyers.marketplace)??0,lives:r,shares:(a==null?void 0:a.shares)??0,maxConcurrentViewers:(a==null?void 0:a.maxConcurrentViewers)??0,streamedSeconds:(a==null?void 0:a.streamedSeconds)??0}},[a,o==null?void 0:o.daily]),V=s=>
1{switch(s){case"sales":return u==="show"?l.showSales:u==="marketplace"?l.mpSales:l.sales;case"earnings":return u==="show"?l.showEarnings:u==="marketplace"?l.mpEarnings:l.earnings;case"aov":return l.aov;case"orders":return u==="show"?l.showOrders:u==="marketplace"?l.mpOrders:l.orders;case"buyers":return u==="show"?l.showBuyers:u==="marketplace"?l.mpBuyers:l.buyers;case"follows":return Z;case"referrals":return ee;case"shares":return f.shares?l.shares:null;case"viewers":return f.maxConcurrentViewers?l.maxConcurrentViewers:null;case"streamedTime":return f.streamedTime?l.streamedSeconds:null;case"lives":return l.lives;default:return null}},S=s=>{switch(s.key){case"shares":return f.shares;case"viewers":return f.maxConcurrentViewers;case"streamedTime":return f.streamedTime;default:return s.available}},z=s=>Q,P=(s,r)=>{if(r===null)return"N/A";if(s.type==="currency")return m(r);if(s.type==="duration"){const i=Math.floor(r/3600),d=Math.floor(r%3600/60);return`${i}h ${d}m`}return r.toLocaleString()},v=$[k],n=M[k].metrics.find(s=>s.key===v),N=p.useMemo(()=>F.map(s=>{switch(v){case"sales":return{label:s.label,show:s.showSales,marketplace:s.mpSales};case"earnings":return{label:s.label,show:s.showEarnings,marketplace:s.mpEarnings};case"orders":return{label:s.label,show:s.showOrders,marketplace:s.mpOrders};case"buyers":return{label:s.label,show:s.showBuyers,marketplace:s.mpBuyers};case"aov":return{label:s.label,value:s.aov};case"lives":return{label:s.label,value:s.lives};default:return{label:s.label,value:0}}}),[F,v]),G=u!=="marketplace",C=u!=="show",H=s=>n.type==="currency"?m(s):s.toLocaleString(),se=`${h.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})} - ${x.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})}`;return e.jsx("div",{className:"py-6",children:e.jsxs("div",{className:"px-4 sm:px-6 md:px-8",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground","data-testid":"text-analytics-title",children:"Analytics"}),e.jsxs("div",{className:"mt-6 flex flex-col gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Seller Analytics"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(E,{variant:"ghost",size:"icon",onClick:()=>R(-1),"data-testid":"button-range-prev","aria-label":"Previous period",children:e.jsx(be,{className:"h-5 w-5"})}),e.jsx("span",{className:"text-xl font-semibold text-foreground","data-testid":"text-date-range",children:se}),e.jsx(E,{variant:"ghost",size:"icon",onClick:()=>R(1),"data-testid":"button-range-next","aria-label":"Next period",children:e.jsx(je,{className:"h-5 w-5"})}),e.jsxs(oe,{children:[e.jsx(ne,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm","data-testid":"button-edit-dates",children:[e.jsx(ke,{className:"mr-2 h-4 w-4"}),"Edit Dates"]})}),e.jsxs(ie,{className:"w-72 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(_,{htmlFor:"start-date",children:"Start date"}),e.jsx(K,{id:"start-date",type:"date",value:g(h),max:g(x),onChange:s=>{const r=Y(s.target.value);r&&(r.setHours(0,0,0,0),A(r))},"data-testid":"input-start-date"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(_,{htmlFor:"end-date",children:"End date"}),e.jsx(K,{id:"end-date",type:"date",value:g(x),min:g(h),max:g(new Date),onChange:s=>{const r=Y(s.target.value);r&&(r.setHours(23,59,59,999),B(r))},"data-testid":"input-end-date"})]})]})]})]})]}),e.jsx("div",{className:"mt-6 grid grid-cols-1 gap-px overflow-hidden rounded-lg border border-border bg-border md:grid-cols-3",children:Object.keys(M).map(s=>{const r=M[s],i=r.metrics.find(c=>c.key===$[s]),d=k===s,T=V(i.key);return e.jsxs("button",{onClick:()=>I(s),"data-testid":`metric-group-${s}`,className:"relative bg-card p-5 text-left transition-colors hover:bg-accent/40 ",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:r.label}),e.jsxs(ue,{children:[e.jsx(he,{asChild:!0,onClick:c=>c.stopPropagation(),children:e.jsxs("span",{className:"flex cursor-pointer items-center gap-1 rounded-full bg-muted px-2 py-1 text-xs text-muted-foreground hover:text-foreground","data-testid":`dropdown-${s}`,children:["More ",e.jsx(Se,{className:"h-3 w-3"})]})}),e.jsx(pe,{align:"end",children:r.metrics.map(c=>e.jsxs(xe,{onClick:ae=>{ae.stopPropagation(),q(re=>({...re,[s]:c.key})),I(s)},"data-testid":`metric-option-${c.key}`,children:[e.jsx("span",{className:"flex-1",children:c.label}),!S(c)&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"N/A"})]},c.key))})]})]}),e.jsxs("div",{className:"mt-3",children:[z(i.key)?e.jsx("div",{className:"h-8 w-28 animate-pulse rounded bg-muted"}):e.jsx("div",{className:"text-2xl font-bold text-foreground","data-testid":`metric-value-${i.key}`,children:P(i,T)}),e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:i.label})]}),e.jsx("div",{className:`absolute bottom-0 left-0 h-0.5 w-full transition-colors ${d?"bg-primary":"bg-transparent"}`})]},s)})}),e.jsx(ce,{className:"mt-6 border border-border",children:e.jsxs(me,{className:"p-6",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-lg font-medium text-foreground",children:n.label}),n.split&&e.jsxs(fe,{value:u,onValueChange:s=>X(s),children:[e.jsx(ve,{className:"w-[150px]","data-testid":"select-source-filter",children:e.jsx(ye,{})}),e.jsxs(ge,{children:[e.jsx(D,{value:"all",children:"All"}),e.jsx(D,{value:"show",children:"Show"}),e.jsx(D,{value:"marketplace",children:"Marketplace"})]})]})]}),z()?e.jsx("div",{className:"h-72 animate-pulse rounded bg-muted"}):S(n)?n.timeseries?e.jsx("div",{className:"h-72","data-testid":"chart-main",children:e.jsx(Ee,{width:"100%",height:"100%",children:n.split?e.jsxs(U,{data:N,children:[e.jsx(L,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",vertical:!1}
1),e.jsx(b,{dataKey:"label",axisLine:!1,tickLine:!1,tick:{fontSize:12,fill:"hsl(var(--muted-foreground))"},interval:"preserveStartEnd",minTickGap:20}),e.jsx(j,{axisLine:!1,tickLine:!1,tick:{fontSize:12,fill:"hsl(var(--muted-foreground))"},width:56,tickFormatter:s=>n.type==="currency"?m(s).replace(/\.00$/,""):s}),e.jsx(O,{contentStyle:{background:"hsl(var(--popover))",border:"1px solid hsl(var(--border))",borderRadius:8,color:"hsl(var(--popover-foreground))"},formatter:(s,r)=>[H(s),r==="show"?"Show":"Marketplace"]}),G&&e.jsx(w,{dataKey:"show",stackId:"a",fill:y,radius:C?[0,0,0,0]:[4,4,0,0],name:"show"}),C&&e.jsx(w,{dataKey:"marketplace",stackId:"a",fill:W,radius:[4,4,0,0],name:"marketplace"})]}):v==="lives"?e.jsxs(U,{data:N,children:[e.jsx(L,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",vertical:!1}),e.jsx(b,{dataKey:"label",axisLine:!1,tickLine:!1,tick:{fontSize:12,fill:"hsl(var(--muted-foreground))"},interval:"preserveStartEnd",minTickGap:20}),e.jsx(j,{axisLine:!1,tickLine:!1,allowDecimals:!1,tick:{fontSize:12,fill:"hsl(var(--muted-foreground))"},width:40}),e.jsx(O,{contentStyle:{background:"hsl(var(--popover))",border:"1px solid hsl(var(--border))",borderRadius:8,color:"hsl(var(--popover-foreground))"},formatter:s=>[s.toLocaleString(),"Lives"]}),e.jsx(w,{dataKey:"value",fill:y,radius:[4,4,0,0],name:"Lives"})]}):e.jsxs(De,{data:N,children:[e.jsx(L,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",vertical:!1}),e.jsx(b,{dataKey:"label",axisLine:!1,tickLine:!1,tick:{fontSize:12,fill:"hsl(var(--muted-foreground))"},interval:"preserveStartEnd",minTickGap:20}),e.jsx(j,{axisLine:!1,tickLine:!1,tick:{fontSize:12,fill:"hsl(var(--muted-foreground))"},width:56,tickFormatter:s=>n.type==="currency"?m(s).replace(/\.00$/,""):s}),e.jsx(O,{contentStyle:{background:"hsl(var(--popover))",border:"1px solid hsl(var(--border))",borderRadius:8,color:"hsl(var(--popover-foreground))"},formatter:s=>[H(s),n.label]}),e.jsx(Le,{type:"monotone",dataKey:"value",stroke:y,strokeWidth:2,dot:{r:3,fill:y},name:n.label})]})})}):e.jsxs("div",{className:"flex h-72 flex-col items-center justify-center text-center",children:[e.jsx("div",{className:"text-4xl font-bold text-foreground","data-testid":"aggregate-value",children:P(n,V(v))}),e.jsx("p",{className:"mt-2 max-w-sm text-sm text-muted-foreground",children:n.note})]}):e.jsx(Me,{icon:e.jsx(Ne,{className:"mb-3 h-10 w-10 text-muted-foreground/50"}),message:n.note||"This metric isn't available yet."}),S(n)&&n.timeseries&&n.split&&e.jsxs("div",{className:"mt-4 flex items-center gap-5 text-sm",children:[G&&e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-full",style:{background:y}}),"Show"]}),C&&e.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-full",style:{background:W}}),"Marketplace"]})]}),e.jsx("p",{className:"mt-4 text-right text-xs text-muted-foreground",children:"Times shown in your local time zone. Data may take up to a day to update."})]})})]})})}function Me({icon:t,message:m}){return e.jsxs("div",{className:"flex h-72 flex-col items-center justify-center text-center",children:[t,e.jsx("p",{className:"max-w-sm text-sm text-muted-foreground",children:m})]})}export{Je 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.