HifiPlanet-Website/hifi/assets/Traffic-DdMyhQDp.js
max.olchov d31b72c01f
Admin: eigene Seite "Besucher" mit Trends aus Google Analytics
Neue Seite /admin/traffic (Seitenleiste unter Übersicht, Recht system.admin) mit
Zeitraum 7/28/90 Tage bzw. 12 Monate: Echtzeit-Besucher, sechs Kennzahlen mit
Vergleich zum Vorzeitraum, Verlaufsdiagramm (aktuell gegen davor), Kanäle,
Quellen, Seiten, Einstiegsseiten, eigene Events, Geräte und Orte.

API GET /analytics/traffic (batchRunReports + runRealtimeReport), Ergebnis
5 Minuten im Temp-Ordner zwischengespeichert (?refresh=1 umgeht das).
Dashboard-Widget verlinkt auf die neue Seite. Build neu.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TFDXmUdWg4Ai8x5ehhJvva
2026-10-22 09:31:25 +00:00

1 line
13 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{r as x,j as e,P as D,C as u,q as W,B as L,s as C,c as V}from"./index-BwTeajq7.js";const F=[{value:7,label:"7 Tage"},{value:28,label:"28 Tage"},{value:90,label:"90 Tage"},{value:365,label:"12 Monate"}],Z=[{value:"users",label:"Besucher"},{value:"sessions",label:"Sitzungen"},{value:"pageviews",label:"Seitenaufrufe"}],P={Direct:"Direkt (Adresse/Lesezeichen)","Organic Search":"Google & Co. (unbezahlt)","Paid Search":"Suchanzeigen",Referral:"Verweise von anderen Seiten","Organic Social":"Social Media","Paid Social":"Social-Media-Anzeigen",Email:"E-Mail","Organic Maps":"Google Maps","Organic Video":"Video (YouTube & Co.)",Display:"Bannerwerbung",Unassigned:"Nicht zugeordnet"},I={desktop:"Computer",mobile:"Handy",tablet:"Tablet","smart tv":"Smart-TV"},$={generate_lead:"Anfrage gesendet",select_package:"Paket angeklickt",contact_call:"Telefonnummer angetippt",contact_whatsapp:"WhatsApp geöffnet",scroll:"Bis zum Seitenende gescrollt",click:"Link zu anderer Website",file_download:"Datei heruntergeladen",form_start:"Formular angefangen"},H=new Intl.NumberFormat("de-DE"),b=s=>H.format(Math.round(s)),U=s=>`${new Intl.NumberFormat("de-DE",{maximumFractionDigits:1}).format(s*100)} %`,X=s=>{const r=Math.round(s);return`${Math.floor(r/60)}:${String(r%60).padStart(2,"0")} min`},A=(s,r=!1)=>`${s.slice(6,8)}.${s.slice(4,6)}.${r?s.slice(0,4):""}`;function K(s,r){if(!r)return s>0?{label:"neu",tone:"up"}:null;const l=(s-r)/r*100;return Math.abs(l)<.5?{label:"±0 %",tone:"flat"}:{label:`${l>0?"+":"−"}${new Intl.NumberFormat("de-DE",{maximumFractionDigits:Math.abs(l)<10?1:0}).format(Math.abs(l))} %`,tone:l>0?"up":"down"}}const q={up:"bg-brand-100 text-brand-800 dark:bg-brand-900/50 dark:text-brand-300",down:"bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300",flat:"bg-neutral-100 text-neutral-600 dark:bg-neutral-800 dark:text-neutral-300"};function R({current:s,previous:r,className:l=""}){const c=K(s,r);return c?e.jsxs("span",{className:`inline-flex items-center rounded-full px-1.5 py-0.5 text-[11px] font-semibold tabular-nums ${q[c.tone]} ${l}`,children:[c.tone==="up"?"▲ ":c.tone==="down"?"▼ ":"",c.label]}):null}function y({label:s,hint:r,value:l,previous:c,format:t}){return e.jsxs("div",{className:"rounded-xl border border-neutral-200/80 bg-white p-4 shadow-sm shadow-neutral-900/[0.03] dark:border-neutral-800 dark:bg-neutral-900 dark:shadow-none",children:[e.jsx("p",{className:"text-xs font-medium text-neutral-500 dark:text-neutral-400",title:r,children:s}),e.jsx("p",{className:"mt-1 text-2xl font-bold tabular-nums tracking-tight text-neutral-900 dark:text-white",children:t(l)}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[e.jsx(R,{current:l,previous:c}),e.jsxs("span",{className:"text-[11px] text-neutral-400",children:["vorher ",t(c)]})]})]})}function J({current:s,previous:r,metric:l,days:c}){const[t,m]=x.useState(null),g=x.useRef(null),[a,N]=x.useState(720);x.useEffect(()=>{const n=g.current;if(!n)return;const d=new ResizeObserver(([S])=>N(Math.max(260,Math.round(S.contentRect.width))));return d.observe(n),()=>d.disconnect()},[]);const j=a<500?200:240,o={top:12,right:8,bottom:26,left:36},M=a-o.left-o.right,k=j-o.top-o.bottom,i=Math.max(1,...s.map(n=>n[l]),...r.map(n=>n[l])),w=(()=>{const n=10**Math.floor(Math.log10(i));return Math.ceil(i/n)*n})(),h=s.length,p=n=>o.left+(h<=1?M/2:n/(h-1)*M),z=n=>o.top+k-n/w*k,B=n=>n.map((d,S)=>`${S?"L":"M"}${p(S).toFixed(1)},${z(d[l]).toFixed(1)}`).join(""),G=`${B(s)}L${p(h-1).toFixed(1)},${o.top+k}L${p(0).toFixed(1)},${o.top+k}Z`,_=[0,.5,1].map(n=>Math.round(w*n)),E=Math.max(1,Math.ceil(h/Math.max(3,Math.floor(a/100)))),T=n=>{const d=n.currentTarget.getBoundingClientRect(),S=(n.clientX-d.left)/d.width*a,O=Math.round((S-o.left)/M*(h-1));m(Math.min(h-1,Math.max(0,O)))},f=t!==null?{cur:s[t],prev:r[t]}:null;return e.jsxs("div",{ref:g,className:"relative",children:[e.jsxs("svg",{width:a,height:j,viewBox:`0 0 ${a} ${j}`,className:"block max-w-full touch-none select-none",onMouseMove:T,onTouchMove:n=>T(n.touches[0]?{...n,clientX:n.touches[0].clientX,currentTarget:n.currentTarget}:n),onMouseLeave:()=>m(null),role:"img","aria-label":"Verlauf im gewählten Zeitraum im Vergleich zum vorherigen",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"traffic-area",x1:"0",x2:"0",y1:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#6ba626",stopOpacity:"0.28"}),e.jsx("stop",{offset:"100%",stopColor:"#6ba626",stopOpacity:"0"})]})}),_.map(n=>e.jsxs("g",{children:[e.jsx("line",{x1:o.left,x2:a-o.right,y1:z(n),y2:z(n),className:"stroke-neutral-200 dark:stroke-neutral-800",strokeWidth:"1"}),e.jsx("text",{x:o.left-6,y:z(n)+4,textAnchor:"end",className:"fill-neutral-400 text-[11px]",children:b(n)})]},n)),s.map((n,d)=>d%E===0&&h-1-d>=E/2||d===h-1?e.jsx("text",{x:p(d),y:j-6,textAnchor:d===0?"start":d===h-1?"end":"middle",className:"fill-neutral-400 text-[11px]",children:A(n.date)},n.date):null),e.jsx("path",{d:B(r),fill:"none",className:"stroke-neutral-400 dark:stroke-neutral-500",strokeWidth:"1.5",strokeDasharray:"4 4"}),e.jsx("path",{d:G,fill:"url(#traffic-area)"}),e.jsx("path",{d:B(s),fill:"none",stroke:"#6ba626",strokeWidth:"2.25",strokeLinejoin:"round",strokeLinecap:"round"}),f&&e.jsxs("g",{children:[e.jsx("line",{x1:p(t),x2:p(t),y1:o.top,y2:o.top+k,className:"stroke-neutral-300 dark:stroke-neutral-700"}),e.jsx("circle",{cx:p(t),cy:z(f.cur[l]),r:"4",fill:"#6ba626",className:"stroke-white dark:stroke-neutral-900",strokeWidth:"2"})]})]}),f&&e.jsxs("div",{className:"pointer-events-none absolute top-0 z-10 rounded-lg border border-neutral-200 bg-white px-3 py-2 text-xs shadow-lg dark:border-neutral-700 dark:bg-neutral-900",style:{left:`${p(t)/a*100}%`,transform:`translateX(${t>h/2?"-105%":"5%"})`},children:[e.jsxs("p",{className:"font-semibold text-neutral-900 dark:text-white",children:[A(f.cur.date,!0),": ",b(f.cur[l])]}),f.prev&&e.jsxs("p",{className:"text-neutral-500 dark:text-neutral-400",children:[c," Tage davor (",A(f.prev.date),"): ",b(f.prev[l])]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-4 text-xs text-neutral-500 dark:text-neutral-400",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"h-0.5 w-4 rounded bg-brand-500"})," Gewählter Zeitraum"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-4 border-t-2 border-dashed border-neutral-400"})," Zeitraum davor"]})]})]})}function v({rows:s,label:r=m=>m,mono:l=!1,showTrend:c=!0,empty:t="Noch keine Daten."}){if(!(s!=null&&s.length))return e.jsx("p",{className:"text-sm text-neutral-400",children:t});const m=s.reduce((a,N)=>a+N.current,0)||1,g=Math.max(...s.map(a=>a.current),1);return e.jsx("ul",{className:"space-y-2.5",children:s.map(a=>e.jsxs("li",{children:[e.jsxs("div",{className:"mb-1 flex items-baseline justify-between gap-3 text-sm",children:[e.jsx("span",{className:`min-w-0 truncate text-neutral-700 dark:text-neutral-200 ${l?"font-mono text-xs":""}`,title:a.name,children:r(a.name)||"(nicht gesetzt)"}),e.jsxs("span",{className:"flex shrink-0 items-center gap-2",children:[c&&e.jsx(R,{current:a.current,previous:a.previous}),e.jsx("span",{className:"w-12 text-right font-semibold tabular-nums text-neutral-900 dark:text-white",children:b(a.current)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-1.5 flex-1 overflow-hidden rounded-full bg-neutral-100 dark:bg-neutral-800",children:e.jsx("div",{className:"h-full rounded-full bg-brand-500/80",style:{width:`${a.current/g*100}%`}})}),e.jsxs("span",{className:"w-10 text-right text-[11px] tabular-nums text-neutral-400",children:[Math.round(a.current/m*100)," %"]})]})]},a.name))})}function Q({data:s}){return s?e.jsx(u,{className:"mb-6",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-x-6 gap-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"relative flex h-3 w-3",children:[s.users>0&&e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-brand-400 opacity-75"}),e.jsx("span",{className:`relative inline-flex h-3 w-3 rounded-full ${s.users>0?"bg-brand-500":"bg-neutral-300 dark:bg-neutral-600"}`})]}),e.jsxs("p",{className:"text-sm text-neutral-600 dark:text-neutral-300",children:[e.jsx("span",{className:"text-2xl font-bold tabular-nums text-neutral-900 dark:text-white",children:s.users})," ","Besucher in den letzten 30 Minuten"]})]}),s.pages.length>0&&e.jsxs("p",{className:"min-w-0 text-xs text-neutral-500 dark:text-neutral-400",children:["Gerade auf: ",s.pages.map(r=>`${r.name} (${r.users})`).join(" · ")]})]})}):null}function ee(){const[s,r]=x.useState(28),[l,c]=x.useState("users"),[t,m]=x.useState(null),[g,a]=x.useState(""),[N,j]=x.useState(!1),o=(i=!1)=>{j(!0),a(""),V.get(`/analytics/traffic?days=${s}${i?"&refresh=1":""}`).then(m).catch(w=>a(w.message)).finally(()=>j(!1))};x.useEffect(()=>{o()},[s]);const M=x.useMemo(()=>((t==null?void 0:t.events)||[]).filter(i=>$[i.name]).sort((i,w)=>Object.keys($).indexOf(i.name)-Object.keys($).indexOf(w.name)),[t]),k=e.jsx(D,{title:"Besucher",description:"Zahlen aus Google Analytics. Jede Zahl zeigt den Vergleich zum gleich langen Zeitraum davor.",actions:e.jsxs(e.Fragment,{children:[e.jsx(C,{value:s,onChange:r,options:F,size:"sm"}),e.jsx(L,{variant:"secondary",size:"sm",icon:"refresh",onClick:()=>o(!0),disabled:N,children:"Aktualisieren"})]})});return t&&!t.configured?e.jsxs("div",{children:[e.jsx(D,{title:"Besucher"}),e.jsx(u,{children:e.jsx(W,{icon:"gauge",title:"Google Analytics ist noch nicht verbunden",description:"Trage unter System › Google-Dienste die Property-ID und den Service-Account ein, dann erscheinen hier die Besucherzahlen.",actions:e.jsx(L,{to:"/admin/settings/google",children:"Zu den Google-Diensten"})})})]}):e.jsxs("div",{children:[k,g&&e.jsx(u,{className:"mb-6",children:e.jsx("p",{className:"text-sm text-red-600",children:g})}),!t&&!g&&e.jsx("p",{className:"text-sm text-neutral-400",children:"Lädt…"}),t&&e.jsxs("div",{className:N?"opacity-60 transition-opacity":"transition-opacity",children:[e.jsx(Q,{data:t.realtime}),e.jsxs("div",{className:"mb-6 grid grid-cols-2 gap-3 sm:gap-4 lg:grid-cols-3 xl:grid-cols-6",children:[e.jsx(y,{label:"Besucher",hint:"Aktive Nutzer im Zeitraum",value:t.kpis.activeUsers.current,previous:t.kpis.activeUsers.previous,format:b}),e.jsx(y,{label:"Neue Besucher",hint:"Zum ersten Mal auf der Seite",value:t.kpis.newUsers.current,previous:t.kpis.newUsers.previous,format:b}),e.jsx(y,{label:"Sitzungen",hint:"Besuche (ein Besucher kann mehrmals kommen)",value:t.kpis.sessions.current,previous:t.kpis.sessions.previous,format:b}),e.jsx(y,{label:"Seitenaufrufe",value:t.kpis.screenPageViews.current,previous:t.kpis.screenPageViews.previous,format:b}),e.jsx(y,{label:"Ø Besuchsdauer",value:t.kpis.averageSessionDuration.current,previous:t.kpis.averageSessionDuration.previous,format:X}),e.jsx(y,{label:"Interessierte Besuche",hint:"Anteil der Sitzungen über 10 Sekunden, mit 2+ Seiten oder einer Aktion (GA: Engagement-Rate)",value:t.kpis.engagementRate.current,previous:t.kpis.engagementRate.previous,format:U})]}),e.jsx(u,{title:"Verlauf",actions:e.jsx(C,{value:l,onChange:c,options:Z,size:"sm"}),className:"mb-6",children:e.jsx(J,{current:t.daily.current,previous:t.daily.previous,metric:l,days:t.days})}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(u,{title:"Woher die Besucher kommen",description:"Sitzungen nach Kanal",children:e.jsx(v,{rows:t.channels,label:i=>P[i]||i})}),e.jsx(u,{title:"Quellen",description:"Sitzungen nach Website bzw. Suchmaschine",children:e.jsx(v,{rows:t.sources,label:i=>i==="(direct)"?"direkt":i})}),e.jsx(u,{title:"Meistbesuchte Seiten",description:"Seitenaufrufe",children:e.jsx(v,{rows:t.pages,mono:!0})}),e.jsx(u,{title:"Einstiegsseiten",description:"Auf welcher Seite ein Besuch beginnt (Sitzungen)",children:e.jsx(v,{rows:t.landing_pages,mono:!0,showTrend:!1})}),e.jsx(u,{title:"Was Besucher tun",description:"Anzahl im Zeitraum – die wichtigsten Aktionen auf der Website",children:e.jsx(v,{rows:M,label:i=>$[i],empty:"Noch keine Aktionen erfasst."})}),e.jsxs("div",{className:"grid gap-6",children:[e.jsx(u,{title:"Geräte",description:"Besucher",children:e.jsx(v,{rows:t.devices,label:i=>I[i]||i})}),e.jsx(u,{title:"Orte",description:"Besucher nach Stadt (ungefähr, aus der IP-Adresse)",children:e.jsx(v,{rows:t.cities,showTrend:!1,label:i=>i==="(not set)"?"unbekannt":i})})]})]}),e.jsxs("p",{className:"mt-6 text-xs text-neutral-400",children:["Gezählt werden nur Besucher, die im Cookie-Banner der Statistik zugestimmt haben. Stand"," ",new Date(t.generated_at).toLocaleTimeString("de-DE",{hour:"2-digit",minute:"2-digit"})," Uhr, wird bis zu 5 Minuten zwischengespeichert. Noch mehr Auswertungen gibt es direkt in"," ",e.jsx("a",{href:"https://analytics.google.com/",target:"_blank",rel:"noreferrer",className:"text-brand-600 hover:underline dark:text-brand-400",children:"Google Analytics"}),"."]})]})]})}export{ee as default};