PageSourceSearch

https://founder-spark-63.lovable.app/assets/PlatformAnalytics-ChlgATBk.js

js founder-spark-63.lovable.app collected 2026-10-03 03:32:05 UTC 32,978 bytes, 16 lines download raw bytes

1import{j as e}from"./query-_koPiPsI.js";import{r as v,f as Ce,L as Te}from"./react-vendor-h1rQ_Bae.js";import{c as B,Q as ke,ax as Ae,K as C,m as Pe,l as _e,J as ee,M as $e,C as j,s as w,z as Le,S as Ie,ao as Me,aE as se,al as M,aM as te,e as $,F as Oe,aq as De,ah as Ee,f as Fe,U as Y,N as Re,B as Ve,ai as Be,T as Ge,a as qe,b as Q,d as K}from"./index-Dq2zLArw.js";import{S as ze,a as Ue,b as We,c as Ye,d as L}from"./select-S0HS5dUY.js";import{b as Qe,P as Ke,f as Xe}from"./ui-radix-CKwvnS8F.js";import{R as re,P as He,d as Je,e as Ze,T as ae,f as es,S as ss,L as ts,C as rs,X as as,Y as ns,a as is}from"./charts-Xu79y1bN.js";import{F as ls}from"./facebook-xAXyhiI1.js";import{L as os}from"./link-CKRegxtG.js";import{M as cs}from"./message-circle-DOC4xMUm.js";import{f as ds}from"./format-Bq4KMpNp.js";import{T as ms,a as xs,b as V,c as I,d as us,e as _}from"./table-BzZXAQMZ.js";import{M as ps,T as hs,S as gs}from"./tablet-CTHy_2cF.js";import{A as fs}from"./activity-cfZN1jba.js";import{C as js}from"./circle-check-big-BlhODvES.js";import{M as bs}from"./message-square-C6C943k8.js";import{W as vs}from"./wrench-LyUHElFj.js";import{U as ne}from"./users-B5SvTFTu.js";import{L as X}from"./lightbulb-DmQhwTLA.js";import{C as Ns,a as ys}from"./CaseStudyPublisher-Vw36WQXE.js";import{E as H}from"./eye-DeaWVGHm.js";import"./supabase-DL6nu9mS.js";import"./motion-nVmI7L5T.js";import"./chevron-up-Dbq7Df3-.js";import"./arrow-up-1-Rt-S8S.js";import"./collapsible-BqfEIKWx.js";import"./slopDetector-DWJy3eHD.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ws=B("Award",[["path",{d:"m15.477 12.89 1.515 8.526a.5.5 0 0 1-.81.47l-3.58-2.687a1 1 0 0 0-1.197 0l-3.586 2.686a.5.5 0 0 1-.81-.469l1.514-8.526",key:"1yiouv"}],["circle",{cx:"12",cy:"8",r:"6",key:"1vp47v"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Ss=B("Instagram",[["rect",{width:"20",height:"20",x:"2",y:"2",rx:"5",ry:"5",key:"2e1cvw"}],["path",{d:"M16 11.37A4 4 0 1 1 12.63 8 4 4 0 0 1 16 11.37z",key:"9exkf1"}],["line",{x1:"17.5",x2:"17.51",y1:"6.5",y2:"6.5",key:"r4j83e"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const Cs=B("Youtube",[["path",{d:"M2.5 17a24.12 24.12 0 0 1 0-10 2 2 0 0 1 1.4-1.4 49.56 49.56 0 0 1 16.2 0A2 2 0 0 1 21.5 7a24.12 24.12 0 0 1 0 10 2 2 0 0 1-1.4 1.4 49.55 49.55 0 0 1-16.2 0A2 2 0 0 1 2.5 17",key:"1q2vi4"}],["path",{d:"m10 15 5-3-5-3z",key:"1jp15x"}]]);var ie="Toggle",le=v.forwardRef((i,t)=>{const{pressed:l,defaultPressed:r,onPressedChange:p,...o}=i,[a,m]=Qe({prop:l,onChange:p,defaultProp:r??!1,caller:ie});return e.jsx(Ke.button,{type:"button","aria-pressed":a,"data-state":a?"on":"off","data-disabled":i.disabled?"":void 0,...o,ref:t,onClick:Xe(i.onClick,()=>{i.disabled||m(!a)})})});le.displayName=ie;var oe=le;const Ts=Ae("inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"},size:{default:"h-10 px-3",sm:"h-9 px-2.5",lg:"h-11 px-5"}},defaultVariants:{variant:"default",size:"default"}}),O=v.forwardRef(({className:i,variant:t,size:l,...r},p)=>e.jsx(oe,{ref:p,className:ke(Ts({variant:t,size:l,className:i})),...r}));O.displayName=oe.displayName;const J={LinkedIn:"#0A66C2","Twitter/X":"#000000",Facebook:"#1877F2","Google Search":"#4285F4",Direct:"#10B981",Referral:"#8B5CF6",Email:"#F59E0B",Instagram:"#E4405F",Reddit:"#FF4500",YouTube:"#FF0000"},ce={LinkedIn:Pe,"Twitter/X":_e,Facebook:ls,"Google Search":ee,Direct:C,Referral:os,Email:$e,Instagram:Ss,Reddit:cs,YouTube:Cs},ks=({payload:i})=>e.jsx("div",{className:"flex flex-wrap justify-center gap-3 mt-4",children:i?.map((t,l)=>{const r=ce[t.value]||C;return e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:t.color}}),e.jsx(r,{className:"w-3.5 h-3.5",style:{color:t.color}}),e.jsx("span",{className:"text-muted-foreground",children:t.value})]},l)})}),As=i=>{const{cx:t,cy:l,innerRadius:r,outerRadius:p,startAngle:o,endAngle:a,fill:m}=i;return e.jsx("g",{children:e.jsx(ss,{cx:t,cy:l,innerRadius:r,outerRadius:p+8,startAngle:o,endAngle:a,fill:m,stroke:"#ffffff",strokeWidth:2,style:{filter:"drop-shadow(0 4px 6px rgba(0, 0, 0, 0.15))",transition:"all 0.2s ease-out"}})})},Ps=({data:i})=>{const[t,l]=v.useState(void 0),r=Object.entries(i).map(([a,m])=>({name:a,value:m.views,signups:m.signups,newsletters:m.newsletters})),p=(a,m)=>l(m),o=()=>l(void 0);return e.jsx(re,{width:"100%",height:300,children:e.jsxs(He,{children:[e.jsx(Je,{data:r,cx:"50%",cy:"50%",labelLine:!1,label:({percent:a})=>`${(a*100).toFixed(0)}%`,outerRadius:80,fill:"#10B981",dataKey:"value",activeIndex:t,activeShape:As,onMouseEnter:p,onMouseLeave:o,children:r.map((a,m)=>e.jsx(Ze,{fill:J[a.name]||"#6B7280",stroke:"#ffffff",strokeWidth:2},`cell-${m}`))}),e.jsx(ae,{content:({active:a,payload:m})=>
16{if(a&&m&&m[0]){const d=m[0].payload,h=ce[d.name]||C;return e.jsxs("div",{className:"bg-background border border-border rounded-lg p-3 shadow-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(h,{className:"w-4 h-4",style:{color:J[d.name]||"#6B7280"}}),e.jsx("p",{className:"font-semibold text-foreground",children:d.name})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Views: ",d.value]}),d.signups>0&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Signups: ",d.signups]}),d.newsletters>0&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Newsletters: ",d.newsletters]})]})}return null}}),e.jsx(es,{content:e.jsx(ks,{})})]})})},_s=({data:i})=>{const t=i.map(l=>({...l,formattedDate:ds(new Date(l.date),"MMM dd")}));return e.jsx(re,{width:"100%",height:300,children:e.jsxs(ts,{data:t,children:[e.jsx(rs,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(as,{dataKey:"formattedDate",stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ns,{stroke:"hsl(var(--muted-foreground))",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ae,{contentStyle:{backgroundColor:"hsl(var(--background))",border:"1px solid hsl(var(--border))",borderRadius:"8px"},labelStyle:{color:"hsl(var(--foreground))"}}),e.jsx(is,{type:"monotone",dataKey:"views",stroke:"hsl(var(--primary))",strokeWidth:2,dot:{fill:"hsl(var(--primary))"}})]})})},$s=({pages:i})=>{const t=l=>{if(l<60)return`${l}s`;const r=Math.floor(l/60),p=l%60;return`${r}m ${p}s`};return e.jsxs(j,{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Top Pages"}),e.jsxs(ms,{children:[e.jsx(xs,{children:e.jsxs(V,{children:[e.jsx(I,{children:"Page Path"}),e.jsx(I,{className:"text-right",children:"Views"}),e.jsx(I,{className:"text-right",children:"Avg Time"}),e.jsx(I,{className:"text-right",children:"Avg Scroll"})]})}),e.jsxs(us,{children:[i.map((l,r)=>e.jsxs(V,{children:[e.jsx(_,{className:"font-medium",children:l.page_path}),e.jsx(_,{className:"text-right",children:l.views.toLocaleString()}),e.jsx(_,{className:"text-right",children:t(l.avg_time)}),e.jsxs(_,{className:"text-right",children:[Math.round(l.avg_scroll),"%"]})]},r)),i.length===0&&e.jsx(V,{children:e.jsx(_,{colSpan:4,className:"text-center text-muted-foreground",children:"No page data available yet"})})]})]})]})},Ls={"United States":"🇺🇸",India:"🇮🇳","United Kingdom":"🇬🇧",Canada:"🇨🇦",Germany:"🇩🇪",France:"🇫🇷",Australia:"🇦🇺",Brazil:"🇧🇷",Japan:"🇯🇵",China:"🇨🇳"},Is=({locations:i})=>e.jsxs(j,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(C,{className:"h-5 w-5 text-primary"}),e.jsx("h3",{className:"text-lg font-semibold",children:"Geographic Distribution"})]}),e.jsxs("div",{className:"space-y-3",children:[i.map((t,l)=>{const r=Ls[t.country]||"🌍",p=t.city?`${t.city}, ${t.country}`:t.country;return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:r}),e.jsx("span",{className:"text-sm font-medium",children:p})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[t.views," views"]})]},l)}),i.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No geographic data available yet"})]})]}),Ms=({devices:i})=>{const t=i.reduce((o,a)=>(o[a.device_type]||(o[a.device_type]=0),o[a.device_type]+=a.count,o),{}),l=i.reduce((o,a)=>{const m=a.browser||"other";return o[m]||(o[m]=0),o[m]+=a.count,o},{}),r=Object.values(t).reduce((o,a)=>o+a,0),p=o=>{switch(o){case"mobile":return e.jsx(gs,{className:"h-5 w-5"});case"tablet":return e.jsx(hs,{className:"h-5 w-5"});default:return e.jsx(ps,{className:"h-5 w-5"})}};return e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(j,{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Device Type"}),e.jsxs("div",{className:"space-y-3",children:[Object.entries(t).map(([o,a])=>{const m=r>0?(a/r*100).toFixed(1):0;return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[p(o),e.jsx("span",{className:"text-sm font-medium capitalize",children:o})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[m,"%"]})]},o)}),Object.keys(t).length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No device data available yet"})]})]}),e.jsxs(j,{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Browser"}),e.jsxs("div",{className:"space-y-3",children:[Object.entries(l).sort((o,a)=>a[1]-o[1]).map(([o,a])=>{const m=r>0?(a/r*100).toFixed(1):0;return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium capitalize",children:o}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[m,"%"]})]},o)}),Object.keys(l).length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No browser data available yet"})]})]})]})},Os=()=>{const[i,t]=v.useState([]);v.useEffect(()=>{(async()=>{const{data:o}=await w.from("page_views").select("id, page_path, city, country, viewed_at").order("viewed_at",{ascending:!1}).limit(10);o&&t(o)})();const p=w.channel("page-views-realtime").on("postgres_changes",{event:"INSERT",schema:"public",table:"page_views"},o=>{const a=o.new;t(m=>[a,...m.slice(0,9)])}).subscribe();return()=>{w.removeChannel(p)}},[]);const l=r=>r.city&&r.country?`${r.city}, ${r.country}`:r.country?r.country:"Unknown location";return e.jsxs(j,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(fs,{className:"h-5 w-5 text-primary animate-pulse"}),e.jsx("h3",{className:"text-lg font-semibold",children:"Live Activity"})]}),e.jsxs("div",{className:"space-y-3 max-h-[400px] overflow-y-auto",children:[i.map(r=>e.jsxs("div",{className:"flex items-start justify-between border-l-2 border-primary pl-3 py-2 animate-in slide-in-from-top",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium",children:["Someone from ",l(r)]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["visited ",r.page_path]})]}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:Le(new Date(r.viewed_at),{addSuffix:!0})})]},r.id)),i.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"Waiting for activity..."})]})]})},Ds=[{name:"ChatGPT",description:"OpenAI is indexing your content for ChatGPT responses"},{name:"Claude",description:"Anthropic is indexing your content for Claude"},{name:"Perplexity",description:"Perplexity AI is learning from your content"},{name:"Gemini",description:"Google is indexing your content for Gemini AI"},{name:"Grok",description:"xAI is indexing your content for Grok"},{name:"Meta AI",description:"Meta AI is learning from your content"}],Z={"AI Models":{icon:M,color:"purple",bgClass:"bg-purple-500/10",textClass:"text-purple-500",borderClass:"border-purple-500/20",description:"Learning from your content"},"Search Engines":{icon:ee,color:"green",bgClass:"bg-green-500/10",textClass:"text-green-500",borderClass:"border-green-500/20",description:"Indexing for search results"},"Social Platforms":{icon:bs,color:"blue",bgClass:"bg-blue-500/10",textClass:"text-blue-500",borderClass:"border-blue-500/20",description:"Generating link previews"},"SEO Tools":{icon:vs,color:"orange",bgClass:"bg-orange-500/10",textClass:"text-orange-500",borderClass:"border-orange-500/20",description:"Analyzing your content"},Other:{icon:C,color:"gray",bgClass:"bg-muted",textClass:"text-muted-foreground",borderClass:"border-border",description:"Other automated visitors"}},Es=({data:i,botBreakdown:t=[],platformBotBreakdown:l=[]})=>{const r=i.organic+i.bot+i.self,p=s=>r===0?0:Math.round(s/r*100),a=(s=>s>=90?{label:"Excellent",color:"text-green-500"}:s>=70?{label:"Good",color:"text-emerald-500"}:s>=50?{label:"Fair",color:"text-yellow-500"}:{label:"Needs Attention",color:"text-orange-500"}
16)(i.qualityScore),m=new Map(t.map(s=>[s.name,s.count]));new Map(l.map(s=>[s.name,s.count]));const d=l.filter(s=>s.category!=="AI Models").reduce((s,x)=>{const u=x.category||"Other";return s[u]||(s[u]=[]),s[u].push(x),s},{}),h=["Search Engines","Social Platforms","SEO Tools","Other"];return e.jsxs(j,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Traffic Quality"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"h-5 w-5 text-primary"}),e.jsxs("span",{className:`text-2xl font-bold ${a.color}`,children:[i.qualityScore,"%"]}),e.jsx("span",{className:`text-sm ${a.color}`,children:a.label})]})]}),e.jsx(Me,{value:i.qualityScore,className:"h-2 mb-6"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"text-center p-3 rounded-lg bg-green-500/10 border border-green-500/20",children:[e.jsx(js,{className:"h-5 w-5 text-green-500 mx-auto mb-1"}),e.jsx("p",{className:"text-xl font-bold text-green-500",children:i.organic.toLocaleString()}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Organic (",p(i.organic),"%)"]})]}),e.jsxs("div",{className:"text-center p-3 rounded-lg bg-blue-500/10 border border-blue-500/20",children:[e.jsx(se,{className:"h-5 w-5 text-blue-500 mx-auto mb-1"}),e.jsx("p",{className:"text-xl font-bold text-blue-500",children:i.bot.toLocaleString()}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Bots (",p(i.bot),"%)"]})]}),e.jsxs("div",{className:"text-center p-3 rounded-lg bg-purple-500/10 border border-purple-500/20",children:[e.jsx(M,{className:"h-5 w-5 text-purple-500 mx-auto mb-1"}),e.jsx("p",{className:"text-xl font-bold text-purple-500",children:i.aiCrawler.toLocaleString()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"AI Crawlers"})]}),e.jsxs("div",{className:"text-center p-3 rounded-lg bg-muted border border-border",children:[e.jsx(te,{className:"h-5 w-5 text-muted-foreground mx-auto mb-1"}),e.jsx("p",{className:"text-xl font-bold text-muted-foreground",children:i.self.toLocaleString()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Self (excluded)"})]})]}),e.jsxs("div",{className:"border-t pt-4 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(M,{className:"h-4 w-4 text-purple-500"}),e.jsx("h4",{className:"text-sm font-medium",children:"Who's Discovering Your Content"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"AI models learning from your articles"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:Ds.map(s=>{const x=m.get(s.name)||0,u=x>0;return e.jsxs("div",{className:`relative p-3 rounded-lg border transition-all duration-300 ${u?"bg-purple-500/10 border-purple-500/30 shadow-[0_0_15px_rgba(168,85,247,0.15)]":"bg-muted/30 border-border/50 opacity-60"}`,title:s.description,children:[u&&e.jsx("div",{className:"absolute -top-1 -right-1 w-3 h-3 bg-purple-500 rounded-full animate-pulse"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:`text-sm font-medium ${u?"text-purple-400":"text-muted-foreground"}`,children:s.name}),e.jsx("span",{className:`text-lg font-bold ${u?"text-purple-400":"text-muted-foreground/50"}`,children:x})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1 truncate",children:u?"Indexing your content!":"Waiting to discover you"})]},s.name)})})]}),l.length>0&&e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(C,{className:"h-4 w-4 text-primary"}),e.jsx("h4",{className:"text-sm font-medium",children:"Who's Discovering ThoughtForge"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Platform-wide bot activity"}),l.filter(s=>s.category==="AI Models").length>0&&e.jsxs("div",{className:"mb-4 p-3 rounded-lg bg-purple-500/10 border border-purple-500/20",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{className:"text-sm font-medium text-purple-500",children:"AI Models"})]}
16),e.jsxs("span",{className:"text-xs text-purple-500 opacity-80",children:[l.filter(s=>s.category==="AI Models").reduce((s,x)=>s+x.count,0)," visits"]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:l.filter(s=>s.category==="AI Models").map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-background/50 text-xs",title:s.description,children:[e.jsx("span",{className:"text-purple-500",children:s.name}),e.jsxs("span",{className:"text-muted-foreground",children:["(",s.count,")"]})]},s.name))})]}),e.jsx("div",{className:"space-y-3",children:h.map(s=>{const x=d[s];if(!x||x.length===0)return null;const u=Z[s]||Z.Other,g=u.icon,T=x.reduce((S,D)=>S+D.count,0);return e.jsxs("div",{className:`p-3 rounded-lg ${u.bgClass} border ${u.borderClass}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(g,{className:`h-4 w-4 ${u.textClass}`}),e.jsx("span",{className:`text-sm font-medium ${u.textClass}`,children:s})]}),e.jsxs("span",{className:`text-xs ${u.textClass} opacity-80`,children:[T," visit",T!==1?"s":""]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:x.map(S=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-background/50 text-xs",title:S.description,children:[e.jsx("span",{className:u.textClass,children:S.name}),e.jsxs("span",{className:"text-muted-foreground",children:["(",S.count,")"]})]},S.name))})]},s)})})]})]})},Fs=({userViews:i,platformAvgViews:t,percentile:l})=>{const r=i>t,p=t>0?(i/t).toFixed(1):"0",a=(d=>d>=90?{label:"Top Creator",icon:ws,color:"text-yellow-500",bg:"bg-yellow-500/10"}:d>=70?{label:"Rising Star",icon:$,color:"text-green-500",bg:"bg-green-500/10"}:d>=50?{label:"Growing",icon:$,color:"text-blue-500",bg:"bg-blue-500/10"}:{label:"Getting Started",icon:ne,color:"text-muted-foreground",bg:"bg-muted"})(l),m=a.icon;return e.jsxs(j,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Platform Comparison"}),e.jsxs("div",{className:`flex items-center gap-2 px-3 py-1 rounded-full ${a.bg}`,children:[e.jsx(m,{className:`h-4 w-4 ${a.color}`}),e.jsx("span",{className:`text-sm font-medium ${a.color}`,children:a.label})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-3xl font-bold text-primary",children:i.toLocaleString()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your Views"})]}),e.jsxs("div",{className:"text-center border-x border-border",children:[e.jsx("p",{className:"text-3xl font-bold text-muted-foreground",children:t.toLocaleString()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Platform Avg"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:`text-3xl font-bold ${r?"text-green-500":"text-muted-foreground"}`,children:r?`${p}x`:`${p}x`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"vs Average"})]})]}),e.jsxs("div",{className:"relative h-8 bg-muted rounded-full overflow-hidden",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 bg-gradient-to-r from-primary/50 to-primary rounded-full transition-all duration-500",style:{width:`${l}%`}}),e.jsx("div",{className:"absolute inset-y-0 flex items-center justify-center text-xs font-medium",style:{left:`${Math.max(10,Math.min(90,l))}%`,transform:"translateX(-50%)"},children:e.jsxs("span",{className:"bg-background px-2 py-0.5 rounded-full border shadow-sm",children:["Top ",100-l,"%"]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground text-center mt-3",children:"Compared to other ThoughtForge creators (last 30 days)"})]})},Rs=({topPages:i,viewsOverTime:t,sourceCategories:l,totalViews:r,uniqueVisitors:p})=>{const o=[];if(i.length>0){const d=i[0],h=d.page_path.split("/").pop()||"article";o.push({icon:Oe,title:"Top Performer",description:`"${h.replace(/-/g," ")}" is your best content with ${d.views} views and ${d.avg_scroll}% avg read depth`,type:"success"})}const a=Object.entries(l).sort(([,d],[,h])=>h.views-d.views);if(a.length>0){const[d,h]=a[0],s=r>0?Math.round(h.views/r*100):0;o.push({icon:De,title:"Best Channel",description:`${d} drives ${s}% of your traffic (${h.views} views)`,type:"info"})}if(t.length>=7){const d=t.slice(-7),h=t.slice(-14,-7),s=d.reduce((u,g)=>u+g.views,0),x=h.reduce((u,g)=>u+g.views,0);if(x>0){const u=Math.round((s-x)/x*100);u>0?o.push({icon:$,title:"Growing Fast",description:`Your traffic is up ${u}% compared to the previous week`,type:"success"}):u<-10&&o.push({icon:$,title:"Traffic Dip",description:`Traffic is down ${Math.abs(u)}% this week. Consider publishing new content!`,type:"tip"})}}if(t.length>0){const d=t.reduce((s,x)=>x.views>s.views?x:s,t[0]),h=new Date(d.date).toLocaleDateString("en-US",{weekday:"long"});o.push({icon:Ee,title:"Peak Day",description:`${h} was your best day with ${d.views} views`,type:"info"})}if(r>0&&p>0){const d=Math.round((1-p/r)*100);d>20&&o.push({icon:X,title:"Returning Readers",description:`${d}% of your traffic comes from returning visitors`,type:"success"})}if(o.length===0)return null;const m=d=>{switch(d){case"success":return"bg-green-500/10 border-green-500/20 text-green-500";case"info":return"bg-blue-500/10 border-blue-500/20 text-blue-500";case"tip":return"bg-yellow-500/10 border-yellow-500/20 text-yellow-500"}};return e.jsxs(j,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(X,{className:"h-5 w-5 text-primary"}),e.jsx("h3",{className:"text-lg font-semibold",children:"Smart Insights"})]}),e.jsx("div",{className:"space-y-3",children:o.slice(0,4).map((d,h)=>{const s=d.icon;return e.jsxs("div",{className:`flex items-start gap-3 p-3 rounded-lg border ${m(d.type)}`,children:[e.jsx(s,{className:"h-5 w-5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:d.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d.description})]})]},h)})})]})};function xt({embedded:i=!1}={}){const{user:t,loading:l}=Fe();Ce();const[r,p]=v.useState("7d"),[o,a]=v.useState(!0),[m,d]=v.useState(!1),[h,s]=v.useState(!1),[x,u]=v.useState({totalViews:0,uniqueVisitors:0,avgTimeOnSite:0,topPages:[],viewsOverTime:[],locations:[],devices:[]}),[g,T]=v.useState(null),[S,D]=v.useState([]);v.useEffect(()=>{t&&de()},[t,r,m,h]);const de=async()=>{a(!0);try{const b=new Date,A={"24h":1,"7d":7,"30d":30,"90d":90}[r]||7,xe=new Date(b.getTime()-A*24*60*60*1e3),{data:P}=await w.from("profiles").select("username").eq("id",t.id).single();if(!P?.username){a(!1);return}const{data:z}=await w.from("posts").select("slug").eq("author_id",t.id).eq("status","published"),N=[];if(z?.forEach(n=>{N.push(`/user/${P.username}/${n.slug}`)}),N.push(`/user/${P.username}`),z?.forEach(n=>{N.push(`/${P.username}/${n.slug}`)}),N.push(`/${P.username}`),D(N),N.length===0){u({totalViews:0,uniqueVisitors:0,avgTimeOnSite:0,topPages:[],viewsOverTime:[],locations:[],devices:[]}),a(!1);return}const E=1e3,ue=2e5,F=[];let R=0;for(;F.length<ue;){let n=w.from("page_views").select("*").gte("viewed_at",xe.toISOString()).in("page_path",N).not("traffic_type","in","(dev,self,bot)").order("viewed_at",{ascending:!1}).range(R,R+E-1);m||(n=n.eq("is_bot",!1)),h||(n=n.neq("traffic_type","self"));const{data:c,error:f}=await n;if(f||!c||c.length===0||(F.push(...c),c.length<E))break;R+=E}const pe=["lovableproject.com","lovable.app","vercel.app","localhost","127.0.0.1"],y=F.filter(n=>{if(!n.referrer)return!0;const c=n.referrer.toLowerCase();return!pe.some(f=>c.includes(f))});if(y.length===0){u({totalViews:0,uniqueVisitors:0,avgTimeOnSite:0,topPages:[],viewsOverTime:[],locations:[],devices:[]}),a(!1);const{data:n}=await w.functions.invoke("get-traffic-sources",{body:{timeRange:r,userPaths:N,userId:t.id}});n&&T(n);return}const U=y.length,he=new Set(y.map(n=>n.session_id)).size,ge=Math.round(y.reduce((n,c)=>n+(c.time_on_page_seconds||0),0)/U),fe=y.reduce((n,c)=>(n[c.page_path]||(n[c.page_path]={views:0,totalTime:0,totalScroll:0}),n[c.page_path].views++,n[c.page_path].totalTime+=c.time_on_page_seconds||0,n[c.page_path].totalScroll+=c.scroll_depth_percent||0,n),{}),je=Object.entries(fe).map(([n,c])=>({page_path:n,views:c.views,avg_time:Math.round(c.totalTime/c.views),avg_scroll:Math.round(c.totalScroll/c.views)})).sort((n,c)=>c.views-n.views).slice(0,10),be=y.reduce((n,c)=>{const f=new Date(c.viewed_at).toISOString().split("T")[0];return n[f]=(n[f]||0)+1,n},{}),ve=Object.entries(be).map(([n,c])=>({date:n,views:c})).sort((n,c)=>n.date.localeCompare(c.date)),Ne=y.reduce((n,c)=>{if(!c.country)return n;const f=`${c.country}_${c.city||""}`;return n[f]||(n[f]={country:c.country,city:c.city,views:0}),n[f].views++,n},{}),ye=Object.values(Ne).sort((n,c)=>c.views-n.views).slice(0,10),we=y.reduce((n,c)=>{const f=`${c.device_type}_${c.browser}_${c.os}`;return n[f]||(n[f]={device_type:c.device_type||"unknown",browser:c.browser,os:c.os,count:0}),n[f].count++,n},{}),Se=Object.values(we);u({totalViews:U,uniqueVisitors:he,avgTimeOnSite:ge,topPages:je,viewsOverTime:ve,locations:ye,devices:Se});const{data:W}=await w.functions.invoke("get-traffic-sources",{body:{timeRange:r,userPaths:N,userId:t.id,includeBots:m,includeSelf:h}});W&&T(W)}catch(b){console.error("Error fetching analytics:",b)}finally{a(!1)}},me=b=>
16{if(b<60)return`${b}s`;const k=Math.floor(b/60),A=b%60;return`${k}m ${A}s`};if(l||o){const b=e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"h-12 w-64 mb-8"}),e.jsx("div",{className:"grid gap-6 md:grid-cols-4 mb-8",children:[...Array(4)].map((k,A)=>e.jsx(Y,{className:"h-32"},A))})]});return i?b:e.jsx("div",{className:"container mx-auto px-4 py-8",children:b})}const G=e.jsxs("div",{className:"flex flex-col gap-4 mb-8",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[!i&&e.jsx("h1",{className:"text-4xl font-bold",children:"Analytics Dashboard"}),e.jsxs(ze,{value:r,onValueChange:p,children:[e.jsx(Ue,{className:"w-[180px]",children:e.jsx(We,{placeholder:"Select time range"})}),e.jsxs(Ye,{children:[e.jsx(L,{value:"24h",children:"Last 24 hours"}),e.jsx(L,{value:"7d",children:"Last 7 days"}),e.jsx(L,{value:"30d",children:"Last 30 days"}),e.jsx(L,{value:"90d",children:"Last 90 days"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm text-muted-foreground mr-2",children:"Show:"}
16),e.jsxs(O,{pressed:!m&&!h,onPressedChange:()=>{d(!1),s(!1)},variant:"outline",size:"sm",className:"data-[state=on]:bg-primary data-[state=on]:text-primary-foreground",children:[e.jsx(H,{className:"h-4 w-4 mr-1"}),"Organic Only"]}),e.jsxs(O,{pressed:m,onPressedChange:d,variant:"outline",size:"sm",className:"data-[state=on]:bg-blue-500 data-[state=on]:text-white",children:[e.jsx(se,{className:"h-4 w-4 mr-1"}),"Include Bots"]}),e.jsxs(O,{pressed:h,onPressedChange:s,variant:"outline",size:"sm",className:"data-[state=on]:bg-muted data-[state=on]:text-foreground",children:[e.jsx(te,{className:"h-4 w-4 mr-1"}),"Include Self"]})]})]}),q=e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-6 md:grid-cols-4",children:[e.jsx(j,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(H,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Organic Views"}),e.jsx("p",{className:"text-2xl font-bold",children:x.totalViews.toLocaleString()})]})]})}),e.jsx(j,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ne,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Unique Visitors"}),e.jsx("p",{className:"text-2xl font-bold",children:x.uniqueVisitors.toLocaleString()})]})]})}),e.jsx(j,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(Re,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Avg Time on Site"}),e.jsx("p",{className:"text-2xl font-bold",children:me(x.avgTimeOnSite)})]})]})}),e.jsx(j,{className:"p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx($,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Top Source"}),e.jsx("p",{className:"text-2xl font-bold",children:g&&Object.keys(g.sourceCategories).length>0?Object.entries(g.sourceCategories).sort((b,k)=>k[1].views-b[1].views)[0][0]:"N/A"})]})]})})]}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[g?.trafficQuality&&e.jsx(Es,{data:g.trafficQuality,botBreakdown:g.botBreakdown,platformBotBreakdown:g.platformBotBreakdown}),g?.platformComparison&&e.jsx(Fs,{userViews:g.platformComparison.userViews,platformAvgViews:g.platformComparison.platformAvgViews,percentile:g.platformComparison.percentile})]}),g?.sourceCategories&&e.jsx(Rs,{topPages:x.topPages,viewsOverTime:x.viewsOverTime,sourceCategories:g.sourceCategories,totalViews:x.totalViews,uniqueVisitors:x.uniqueVisitors}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(j,{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Traffic Sources"}),g&&Object.keys(g.sourceCategories).length>0?e.jsx(Ps,{data:g.sourceCategories}):e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No traffic data yet"})]}),e.jsxs(j,{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Views Over Time"}),x.viewsOverTime.length>0?e.jsx(_s,{data:x.viewsOverTime}):e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No time series data yet"})]})]}),e.jsx($s,{pages:x.topPages}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(Is,{locations:x.locations}),e.jsx(Os,{})]}),e.jsx(Ms,{devices:x.devices})]});return i?e.jsxs(e.Fragment,{children:[G,q]}):e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsx("div",{className:"flex items-center gap-4 mb-8",children:e.jsx(Te,{to:"/dashboard",children:e.jsxs(Ve,{variant:"ghost",size:"sm",children:[e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Back to Dashboard"]})})}),G,e.jsxs(Ge,{defaultValue:"platform",className:"space-y-6",children:[e.jsxs(qe,{children:[e.jsx(Q,{value:"platform",children:"Platform Analytics"}),e.jsx(Q,{value:"case-studies",children:"Case Study Pipeline"})]}),e.jsx(K,{value:"platform",children:q}),e.jsx(K,{value:"case-studies",children:e.jsxs("div",{className:"space-y-6",children:[e.jsx(Ns,{}),e.jsx(ys,{})]})})]})]})}export{xt 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.