PageSourceSearch

https://analyticsindiamag.com/assets/SEOCtrRescue-CyzoBbTn.js

js analyticsindiamag.com collected 2026-09-24 08:27:23 UTC 9,092 bytes, 1 lines download raw bytes

1import{a as I,r as i,j as e,I as j,B as w,L as y,aq as J,y as K,N as O,E as Q,s as C}from"./index-KSWbwNeY.js";import{A as V}from"./AdminNav-DsaLvjFx.js";import{T as X}from"./textarea-BXv-lbww.js";import{L as x}from"./label-ndOKmXJw.js";import{C as Y}from"./chevron-down-D7IdZFzc.js";import{S as Z}from"./save-xjMYTeam.js";import"./index-DsYLezIw.js";import"./user-cog-DvqSS7bY.js";import"./trash-2-CwcwS_bf.js";import"./book-open-DS7Nmuzn.js";import"./receipt-DgWJf9Ou.js";function B(h){try{const o=new URL(h);if(!o.hostname.endsWith("analyticsindiamag.com")||o.hostname.split(".").length>2)return null;const d=o.pathname.split("/").filter(Boolean);return d.length<2?null:d[d.length-1].replace(/\/$/,"")}catch{return null}}function me(){const{toast:h}=I(),[o,d]=i.useState(!1),[v,F]=i.useState([]),[f,g]=i.useState({}),[N,A]=i.useState(0),[D,z]=i.useState(null),[m,b]=i.useState({}),[S,_]=i.useState(null),[R,U]=i.useState(28),[k,$]=i.useState(5e3),[L,q]=i.useState(1),[T,W]=i.useState("web"),E=async()=>{d(!0);try{const{data:s,error:t}=await C.functions.invoke("gsc-top-pages",{body:{days:R,minImpressions:k,maxCtr:L/100,searchType:T,rowLimit:300}});if(t)throw t;const l=s.pages||[];F(l),A(s.avgCtr||0);const r=Array.from(new Set(l.map(n=>B(n.url)).filter(n=>!!n)));if(r.length>0){const{data:n}=await C.from("posts").select("id,title,slug,seo_title,seo_description").in("slug",r),a={};(n||[]).forEach(c=>{a[c.slug]=c}),g(a)}else g({})}catch(s){h({title:"Failed to load",description:String(s.message||s),variant:"destructive"})}finally{d(!1)}};i.useEffect(()=>{E()},[]);const G=s=>{b(t=>({...t,[s.id]:{seo_title:s.seo_title??s.title??"",seo_description:s.seo_description??""}}))},H=async s=>{var l;const t=m[s];if(t){_(s);try{const{error:r}=await C.from("posts").update({seo_title:t.seo_title.trim()||null,seo_description:t.seo_description.trim()||null}).eq("id",s);if(r)throw r;g(a=>{var c;return{...a,[((c=a[s])==null?void 0:c.slug)||""]:{...a[s],...t}}});const n=(l=Object.values(f).find(a=>a.id===s))==null?void 0:l.slug;n&&g(a=>({...a,[n]:{...a[n],...t}})),h({title:"Saved",description:"SEO title and description updated."})}catch(r){h({title:"Save failed",description:String(r.message||r),variant:"destructive"})}finally{_(null)}}},M=i.useMemo(()=>v.map(s=>{const t=B(s.url),l=t?f[t]:null;return{...s,slug:t,post:l}}),[v,f]);return e.jsxs("div",{className:"font-sans",children:[e.jsx(V,{}),e.jsxs("main",{className:"ml-52 p-6 max-w-[1400px]",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-semibold mb-1",children:"CTR Rescue"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"High-impression pages with low CTR. Rewriting titles and descriptions here is the fastest way to recover search traffic."})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 items-end mb-4 p-4 border rounded-md bg-muted/30",children:[e.jsxs("div",{children:[e.jsx(x,{className:"text-xs",children:"Period (days)"}),e.jsx(j,{type:"number",className:"w-24 h-9",value:R,min:7,max:90,onChange:s=>U(Math.min(90,Math.max(7,Number(s.target.value)||28)))})]}),e.jsxs("div",{children:[e.jsx(x,{className:"text-xs",children:"Min impressions"}),e.jsx(j,{type:"number",className:"w-32 h-9",value:k,min:100,onChange:s=>$(Math.max(100,Number(s.target.value)||5e3))})]}),e.jsxs("div",{children:[e.jsx(x,{className:"text-xs",children:"Max CTR (%)"}),e.jsx(j,{type:"number",step:"0.1",className:"w-24 h-9",value:L,min:.1,max:50,onChange:s=>q(Math.min(50,Math.max(.1,Number(s.target.value)||1)))})]}),e.jsxs("div",{children:[e.jsx(x,{className:"text-xs",children:"Surface"}),e.jsxs("select",{className:"h-9 border rounded-md px-2 text-sm bg-background",value:T,onChange:s=>W(s.target.value),children:[e.jsx("option",{value:"web",children:"Web Search"}),e.jsx("option",{value:"discover",children:"Discover"}),e.jsx("option",{value:"news",children:"News"})]})]}),e.jsxs(w,{onClick:E,disabled:o,size:"sm",children:[o?e.jsx(y,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(J,{className:"h-4 w-4 mr-2"}),"Reload"]}),N>0&&e.jsxs("div",{className:"ml-auto text-xs text-muted-foreground",children:["Average CTR across returned pages: ",e.jsxs("span",{className:"font-medium text-foreground",children:[(N*100).toFixed(2),"%"]})]})]}),e.jsxs("div",{className:"border rounded-md overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-[2fr_80px_100px_80px_70px_100px_40px] gap-2 px-4 py-2 text-xs font-medium bg-muted/50 border-b",children:[e.jsx("div",{children:"Page"}),e.jsx("div",{className:"text-right",children:"Clicks"}),e.jsx("div",{className:"text-right",children:"Impr."}),e.jsx("div",{className:"text-right",children:"CTR"}),e.jsx("div",{className:"text-right",children:"Pos"}),e.jsx("div",{className:"text-right",children:"Opp. clicks"}),e.jsx("div",{})]}),o&&v.length===0&&e.jsxs("div",{className:"p-8 text-center text-sm text-muted-foreground",children:[e.jsx(y,{className:"h-5 w-5 animate-spin mx-auto mb-2"}),"Loading from Search Console…"]}),!o&&M.length===0&&e.jsx("div",{className:"p-8 text-center text-sm text-muted-foreground",children:'No pages match the filters. Try lowering "Min impressions" or raising "Max CTR".'}),M.map(s=>{var n,a,c,P;const t=D===s.url,l=(s.ctr*100).toFixed(2),r=s.ctr<N*.5;return e.jsxs("div",{className:"border-b last:border-b-0",children:[e.jsxs("div",{className:"grid grid-cols-[2fr_80px_100px_80px_70px_100px_40px] gap-2 px-4 py-2.5 text-sm hover:bg-muted/30 cursor-pointer items-center",onClick:()=>{z(t?null:s.url),!t&&s.post&&!m[s.post.id]&&G(s.post)},children:[e.jsx("div",{className:"truncate",children:e.jsxs("div",{className:"flex items-center gap-2",children:[t?e.jsx(Y,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(K,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"truncate",title:s.url,children:s.url.replace("https://analyticsindiamag.com","")}),!s.post&&s.slug&&e.jsx(O,{variant:"outline",className:"text-[10px]",children:"no post match"}),!s.slug&&e.jsx(O,{variant:"outline",className:"text-[10px]",children:"non-article"})]})}),e.jsx("div",{className:"text-right tabular-nums",children:s.clicks.toLocaleStr
1ing()}),e.jsx("div",{className:"text-right tabular-nums",children:s.impressions.toLocaleString()}),e.jsxs("div",{className:`text-right tabular-nums ${r?"text-destructive font-medium":""}`,children:[l,"%"]}),e.jsx("div",{className:"text-right tabular-nums",children:s.position?s.position.toFixed(1):"—"}),e.jsxs("div",{className:"text-right tabular-nums font-medium text-admin-accent",children:["+",s.opportunity.toLocaleString()]}),e.jsx("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",onClick:u=>u.stopPropagation(),children:e.jsx(Q,{className:"h-3.5 w-3.5 text-muted-foreground hover:text-foreground"})})]}),t&&e.jsx("div",{className:"px-6 py-4 bg-muted/20 border-t",children:s.post?e.jsxs("div",{className:"space-y-3 max-w-3xl",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Post: ",e.jsx("span",{className:"font-medium text-foreground",children:s.post.title})]}),e.jsxs("div",{children:[e.jsxs(x,{className:"text-xs",children:["SEO Title ",e.jsx("span",{className:"text-muted-foreground",children:"(target ≤60 chars, lead with the entity Google ranks you for)"})]}),e.jsx(j,{value:((n=m[s.post.id])==null?void 0:n.seo_title)??"",onChange:u=>b(p=>({...p,[s.post.id]:{...p[s.post.id],seo_title:u.target.value}})),placeholder:s.post.title,maxLength:120}),e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-0.5",children:[(((a=m[s.post.id])==null?void 0:a.seo_title)||"").length," chars"]})]}),e.jsxs("div",{children:[e.jsxs(x,{className:"text-xs",children:["SEO Description ",e.jsx("span",{className:"text-muted-foreground",children:"(target ~150 chars, answer the search intent with a promise)"})]}),e.jsx(X,{rows:2,value:((c=m[s.post.id])==null?void 0:c.seo_description)??"",onChange:u=>b(p=>({...p,[s.post.id]:{...p[s.post.id],seo_description:u.target.value}})),maxLength:300}),e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-0.5",children:[(((P=m[s.post.id])==null?void 0:P.seo_description)||"").length," chars"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(w,{size:"sm",onClick:()=>H(s.post.id),disabled:S===s.post.id,children:[S===s.post.id?e.jsx(y,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Z,{className:"h-4 w-4 mr-2"}),"Save"]}),e.jsx(w,{size:"sm",variant:"ghost",asChild:!0,children:e.jsx("a",{href:`/admin/posts/${s.post.id}/edit`,target:"_blank",rel:"noopener noreferrer",children:"Open in editor"})})]})]}):e.jsx("div",{className:"text-sm text-muted-foreground",children:s.slug?e.jsxs(e.Fragment,{children:["No post in DB matches slug ",e.jsx("code",{className:"px-1 rounded bg-muted",children:s.slug}),". May be a deleted/redirected URL."]}):e.jsx(e.Fragment,{children:"This URL isn't a main-domain article — not editable here."})})})]},s.url)})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-3",children:"Opportunity = impressions × (avg CTR − page CTR). It estimates how many extra clicks you'd get if the page hit the cohort average."})]})]})}export{me 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.