PageSourceSearch

https://www.ecomdroptv.com/assets/MetricsBar-BxvUvVOU.js

js ecomdroptv.com collected 2026-10-02 01:28:08 UTC 10,679 bytes, 1 lines download raw bytes

1import{b as Be,j as e,r as ys,o as xs,h as vs,d as gs,a as bs,x as js,y as Cs,z as Fs,f as Rs}from"./index-D_T1XJ3U.js";import{r as n}from"./vendor-react-Bxgxa9T6.js";import{u as _s}from"./useLumyPorPauta-BfTI2A9g.js";import{u as Ss}from"./useSelectedCampaigns-oW27iJwj.js";import{c as Ms,t as Ce}from"./campanas-marcadas-BEzFJUYK.js";import{s as Ps}from"./planAccounts-jrtXKEQ1.js";import{K as y,a as x,b as v,c as f}from"./KpiCard-De-xnTId.js";import{R as ks}from"./ReorderableKpiStrip-CZjJsEjr.js";import{e as X,a as T,b as Fe,d as Re,r as _e,f as Es}from"./semaforo-1n3dRRyu.js";import{c as Y,a as ee,d as Se,f as Me,g as Bs,h as As,i as Ls,j as ws,k as Ns}from"./meta-DVwYyRHl.js";import{c as $s,a as Pe}from"./calculations-uMoY6F2o.js";import"./pedidos-por-pauta-BwD_YLFQ.js";import"./vendor-dnd-DkGDz49K.js";import"./useCloseOnRouteChange-CKTMe1zu.js";const qs=[{key:"today",label:"Hoy"},{key:"yesterday",label:"Ayer"},{key:"last_3d",label:"3 días"},{key:"last_7d",label:"7 días"},{key:"last_15d",label:"15 días"},{key:"last_30d",label:"30 días"}];function Ds({accentColor:o="#1877F2"}){const{datePreset:m,customRange:i,setDatePreset:b}=Be(),j=i!==null;return e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",marginRight:4},children:"Periodo:"}),e.jsx("div",{className:"date-filter-pill",children:qs.map(c=>{const C=!j&&m===c.key;return e.jsx("button",{onClick:()=>b(c.key),className:`date-pill-btn${C?" active":""}`,children:c.label},c.key)})}),j&&i&&e.jsxs("span",{style:{padding:"5px 12px",borderRadius:20,fontSize:12,fontWeight:600,border:`1px solid ${o}`,background:`${o}18`,color:o},children:[i.since," → ",i.until]})]})}function ke(o){const m=parseFloat(o.spend)||0,i=ee(o);return i<=0||m<=0?0:m/i}function Ee(o){const m=Bs(o);if(m<=0)return 0;const i=As(o),b=Ls(o),j=ws(o),c=Ns(o),C=i+b+j+c;return C<=0?0:C/(4*m)*100}function sa(){var ge;const{accounts:o,selectedAccounts:m}=ys(),{limits:i,selected:b,loading:j}=xs(),[c,C]=n.useState(()=>{try{return localStorage.getItem("meta_campanas_marcadas")||""}catch{return""}});n.useEffect(()=>{const s=a=>C(String(a.detail??""));return window.addEventListener("lumy:campanas-marcadas",s),()=>window.removeEventListener("lumy:campanas-marcadas",s)},[]);const se=s=>{try{const a=JSON.parse(String(s||"{}"));return a&&typeof a=="object"?a:{}}catch{return{}}},[ae,Ae]=n.useState(()=>{try{return se(localStorage.getItem("meta_campanas_marcadas_nombres"))}catch{return{}}});n.useEffect(()=>{const s=a=>Ae(se(a.detail));return window.addEventListener("lumy:campanas-marcadas-nombres",s),()=>window.removeEventListener("lumy:campanas-marcadas-nombres",s)},[]);const z=n.useMemo(()=>c.split(",").map(s=>s.trim()).filter(Boolean),[c]),Le=Ss("meta"),{user:F}=vs(),te=(F==null?void 0:F.role)==="admin"||!!(F!=null&&F.landing_access)||!j&&!!((ge=i.landing)!=null&&ge.enabled),re=_s(te,"meta",{periodo:"meta"}),{getQueryParams:ne,compareMode:K,datePreset:O,customRange:L}=Be(),{refreshKey:we}=gs(),[R,Ne]=n.useState(null),[$e,qe]=n.useState(!1),[_,De]=n.useState(!1),[Ie,oe]=n.useState(!1),[ce,le]=n.useState(null),{isHidden:Te}=bs(),w=Te?"sensitive-blur":"",{configs:ie}=js(),de=n.useMemo(()=>{const s=Object.values(ie).map(a=>a==null?void 0:a.deliveryRate).filter(a=>typeof a=="number"&&a>0&&a<=1);return s.length===0?Cs.deliveryRate:s.reduce((a,l)=>a+l,0)/s.length},[ie]),P=n.useMemo(()=>{const{covered:s}=Ps(o,i.meta.limit,l=>l.id,b.meta),a=new Set(s.map(l=>l.id));return m.filter(l=>a.has(l.id))},[o,m,i.meta.limit,b.meta]),ze=n.useMemo(()=>{const s=new Set(P.map(a=>(a.currency||"").toUpperCase().trim()).filter(Boolean));return s.size===1?Array.from(s)[0]:null},[P]),N=n.useRef(0),ue=n.useRef(null),pe=n.useCallback(async()=>{var l;if(P.length===0)return;const s=++N.current;(l=ue.current)==null||l.abort();const a=new AbortController;ue.current=a,oe(!0),le(null);try{const d=ne(),g=await Promise.all(P.map(async t=>{try{const M=await fetch(`/api/accounts/${t.id}/insights/comparison?${d}&compare_mode=${K}${c?`&campaigns=${encodeURIComponent(c)}`:""}`,{signal:a.signal}),u=await M.json();return!M.ok||u!=null&&u.error?{account:t,current:null,previous:null,failed:!0,previousFailed:!0}:{account:t,current:(u==null?void 0:u.current)||null,previous:(u==null?void 0:u.previous)||null,failed:!1,previousFailed:!!(u!=null&&u.previousFailed)}}
1catch(M){if(a.signal.aborted)throw M;return{account:t,current:null,previous:null,failed:!0,previousFailed:!0}}}));if(await Promise.all(g.map(async t=>{const M=!t.current||!((parseFloat(t.current.spend)||0)>0);if(Ms({fallo:t.failed,gastoEnCero:M,hayMarcadas:!!c}))try{const h=await(await fetch(`/api/accounts/${t.account.id}/campaigns?${d}`,{signal:a.signal})).json().catch(()=>null),be=Array.isArray(h)?h:(h==null?void 0:h.data)||(h==null?void 0:h.insights)||[],je=new Set(c.split(",").map(I=>I.trim()).filter(Boolean)),J=je.size>0?be.filter(I=>je.has(String(I.campaign_id||I.id||""))):be;if(!Array.isArray(J)||J.length===0)return;const Z=Y(J);Z&&(t.failed||(parseFloat(Z.spend)||0)>0)&&(t.current=Z)}catch{}})),s!==N.current)return;const Q=g.map(t=>t.current).filter(t=>!!t),D=g.map(t=>t.previous).filter(t=>!!t),fs=g.some(t=>t.current&&!t.previous&&(t.failed||t.previousFailed));qe(fs);const hs=new Set(g.filter(t=>t.current&&(parseFloat(t.current.spend)||0)>0).map(t=>(t.account.currency||"").toUpperCase().trim()).filter(Boolean));De(hs.size>1),Ne({current:Y(Q),previous:D.length>0?Y(D):null})}catch(d){if(a.signal.aborted||s!==N.current)return;le(d instanceof Error?d.message:String(d))}finally{s===N.current&&oe(!1)}},[P.map(s=>s.id).join(","),ne,K,we,c]);if(n.useEffect(()=>{pe()},[pe]),Ie)return e.jsx("div",{className:"kpi-section",children:e.jsx(Fs,{})});if(ce)return e.jsx("div",{className:"kpi-section",children:e.jsxs("div",{className:"error-banner",children:["Error cargando métricas: ",ce]})});const Ke={spend:"0",impressions:"0",ctr:"0",cpm:"0",frequency:"0",actions:[]},p=(R==null?void 0:R.current)||Ke,r=R==null?void 0:R.previous,G=parseFloat(p.spend)||0,V=parseFloat(p.impressions)||0;parseFloat(p.ctr);const Oe=parseFloat(p.inline_link_clicks||"0")||0,$=V>0?Oe/V*100:0,S=parseFloat(p.cpm)||0,k=parseFloat(p.frequency)||0,W=ee(p),Ge=Se(p),E=ke(p),B=Pe(Ge,de);Me(p);const U=Ee(p),Ve=r?parseFloat(r.spend)||0:null;r&&parseFloat(r.impressions),r&&parseFloat(r.ctr);const me=r&&parseFloat(r.impressions)||0,We=r?me>0?(parseFloat(r.inline_link_clicks||"0")||0)/me*100:0:null,Ue=r?parseFloat(r.cpm)||0:null,He=r?parseFloat(r.frequency)||0:null,fe=r?ee(r):null,he=r?Se(r):null,Qe=r?ke(r):null,Je=he!==null?Pe(he,de):null;r&&Me(r);const Ze=r?Ee(r):null,ye=O!=="today"||!!L,xe=L?`${L.since} → ${L.until}`:{today:"hoy",yesterday:"ayer",last_3d:"últ. 3 días",last_7d:"últ. 7 días",last_14d:"últ. 14 días",last_15d:"últ. 15 días",last_28d:"últ. 28 días",last_30d:"últ. 30 días",this_month:"este mes",last_month:"mes pasado"}[O]||O,Xe=ye?`vs ${xe.replace("últ. ","")} previos`:{yesterday:"vs ayer",last_3d:"vs 3d",last_7d:"vs 7d",last_15d:"vs 15d",last_30d:"vs 1 mes"}[K]??"vs anterior",Ye=k>=3.5?"#EF4444":k>=2.2?"#F59E0B":void 0,es=S>=7500?"#EF4444":S>=5500?"#F59E0B":void 0,ss=_e(B),as=Re(E),ts=es||Fe(S),rs=Ye||"#8B5CF6",H=s=>Rs(s,ze),ve=s=>s.toLocaleString("es-CO");function A(s,a,l=!1){if(ye)return e.jsx("span",{style:{color:"var(--text-muted)"},children:xe});if($e)return e.jsx("span",{style:{color:"var(--text-muted)"},title:"A una de tus cuentas no le cargó el período anterior. Comparar ahora daría un porcentaje inflado, así que no se muestra. Recarga en un momento.",children:"sin comparativo (falta una cuenta)"});if(a===null||a===0)return e.jsx("span",{children:"sin comparativo"});const d=(s-a)/a*100,g=l?d<0:d>0,Q=Math.abs(d)<.1?"var(--text-muted)":g?"#10B981":"#EF4444",D=d>0?"↑":d<0?"↓":"·";return e.jsxs("span",{style:{color:Q},children:[D," ",Math.abs(d).toFixed(1),"% ",Xe]})}const ns=T(_e(B),"ROAS"),os=X("pedidos",W,{promedio7d:fe||0}),cs=X("gasto",G),ls=T(Re(E),"CPA");X("impresiones",V);const is=T(Fe(S),"CPM"),ds=T(Es(k),"Frecuencia"),us=e.jsx("span",{style:{color:"var(--text-muted)"},children:"monedas distintas"}),q=(s,a,l=!1)=>_?us:A(s,a,l),ps={roasReal:{node:e.jsxs(y,{borderColor:ss,evaluacion:ns,children:[e.jsx(x,{children:"ROAS Real"}),e.jsx(v,{children:_?"—":B>0?`${B.toFixed(2)}x`:"—"}),e.jsx(f,{children:q(B,Je)})]})},purchases:{node:e.jsxs(y,{borderColor:"#06B6D4",evaluacion:os,children:[e.jsx(x,{children:"Compras"}),e.jsx(v,{children:ve(W)}),te?e.jsx(f,{children:re.loading?"Lumy: …":`Lumy: ${ve(re.totalOrders)} reales`}):e.jsx(f,{children:A(W,fe)})]})},spend:{node:e.jsxs(y,{borderColor:"#6366F1",evaluacion:cs,children:[e.jsx(x,{children:"Gasto Total"}),e.jsx(v,{className:w,children:_?"—":H(G)}),e.jsx(f,{children:q(G,Ve,!0)})]})},cpa:{node:e.jsxs(y,{borderColor:as,evaluacion:ls,children:[e.jsx(x,{children:"CPA"}),e.jsx(v,{className:w,children:_?"—":E>0?H(E):"—"}),e.jsx(f,{children:q(E,Qe,!0)})]})},ctrEnlace:{node:e.jsxs(y,{borderColor:$s($),children:[e.jsx(x,{children:"CTR del enlace"}),e.jsx(v,{children:$>0?`${$.toFixed(2)}%`:"—"}),e.jsx(f,{children:A($,We)})]})},cpm:{node:e.jsxs(y,{borderColor:ts,evaluacion:is,children:[e.jsx(x,{children:"CPM"}),e.jsx(v,{className:w,children:_?"—":H(S)}),e.jsx(f,{children:q(S,Ue,!0)})]})}
1,frequency:{node:e.jsxs(y,{borderColor:rs,evaluacion:ds,children:[e.jsx(x,{children:"Frecuencia"}),e.jsx(v,{children:k.toFixed(2)}),e.jsx(f,{children:A(k,He,!0)})]})},retention:{node:e.jsxs(y,{borderColor:"#EC4899",children:[e.jsx(x,{children:"% Retención"}),e.jsx(v,{children:U>0?`${U.toFixed(1)}%`:"—"}),e.jsx(f,{children:A(U,Ze)})]})}},ms=["roasReal","purchases","spend","cpa","ctrEnlace","cpm","frequency","retention"].map(s=>({id:s,node:ps[s].node}));return e.jsxs("div",{className:"kpi-section",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:12,flexWrap:"wrap"},children:[e.jsx(Ds,{}),z.length>0&&e.jsxs("span",{className:"kpi-filtro-marcadas","data-guia":"meta.tarjetas_filtradas",children:[e.jsx("span",{className:`kpi-filtro-marcadas__texto ${w}`,title:Ce(z,ae),children:Ce(z,ae)}),e.jsx("button",{type:"button",className:"kpi-filtro-marcadas__btn",onClick:()=>Le.clear(),children:"Ver todas las campañas"})]}),_&&e.jsx("span",{style:{fontSize:12,color:"var(--text-muted)",lineHeight:1.4},children:"Estás viendo cuentas en monedas distintas y eso no se puede sumar: Gasto, CPA, CPM y ROAS salen vacíos. Deja marcadas las cuentas de una sola moneda para verlos."})]}),e.jsx(ks,{items:ms,storageKey:"kpi_order_meta",brandColor:"#1877F2",customCreatorTab:"meta"})]})}export{sa as MetricsBar};

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.