source: Klonkt/src/views/pages/admin-stats.ejs@ 37edecd

main
Last change on this file since 37edecd was 37edecd, checked in by roboburr <roboburr@…>, 3 months ago

Link-in-bio + click stats (premium feature #6)

Linktree-style page from the existing sites.profile_links (JSON [{platform,url}])
+ PLATFORMS icons. Clicks counted per url.

  • DB: link_clicks (site_id, url, clicks), PK (site_id,url).
  • routes/linkbio.js (premium-gated): GET /links (page with profile_links as buttons), GET /links/go/:i (counts click per url + 302 redirect). Open-redirect safe: only redirects to a url in the site's own profile_links; http(s)/mailto only.
  • view pages/linkbio.ejs (photo/name/bio + brand-coloured buttons with SVG icons).
  • admin-stats: link-clicks section (top 50, per url) for the current site.
  • admin dashboard: 🔗 Link-in-bio link (premium, non-hub).

node --check passed.

Co-Authored-By: Claude <noreply@…>

  • Property mode set to 100644
File size: 6.0 KB
Line 
1<div class="container stats-page">
2 <p><a href="/admin" class="btn">&larr; Beheer</a></p>
3 <h1>Statistieken</h1>
4 <p class="stats-note">Cookievrij gemeten — geen tracking-cookies, geen toestemmingsbanner.
5 Unieke bezoekers via een dagelijks roterende, anonieme hash (IP/browser worden niet bewaard).
6 Je eigen beheerder-bezoeken tellen niet mee.</p>
7
8 <% var s = stats; var _max = Math.max(1, ...s.series.map(function(d){ return d.pageviews; })); %>
9
10 <div class="stats-cards">
11 <div class="stat-card"><div class="stat-num"><%= s.totals.visitors %></div><div class="stat-label">Bezoekers (14d)</div></div>
12 <div class="stat-card"><div class="stat-num"><%= s.totals.pageviews %></div><div class="stat-label">Weergaven (14d)</div></div>
13 <div class="stat-card"><div class="stat-num"><%= s.totals.plays %></div><div class="stat-label">Plays (totaal)</div></div>
14 <div class="stat-card"><div class="stat-num"><%= s.totals.postViews %></div><div class="stat-label">Post-weergaven (totaal)</div></div>
15 </div>
16
17 <section class="stats-chart-wrap">
18 <div class="stats-chart-head">
19 <h2>Laatste 14 dagen</h2>
20 <div class="stats-legend">
21 <span class="lg lg-vis">Bezoekers</span>
22 <span class="lg lg-pv">Weergaven</span>
23 </div>
24 </div>
25 <div class="stats-chart">
26 <% s.series.forEach(function(d){
27 var pvPct = Math.round(d.pageviews / _max * 100);
28 var visPct = Math.round(d.visitors / _max * 100);
29 %>
30 <div class="sc-col" title="<%= d.day %> — <%= d.pageviews %> weergaven, <%= d.visitors %> bezoekers">
31 <div class="sc-bar">
32 <span class="sc-pv" style="height: <%= pvPct %>%"></span>
33 <span class="sc-vis" style="height: <%= visPct %>%"></span>
34 </div>
35 <span class="sc-day"><%= d.day.slice(8) %></span>
36 </div>
37 <% }); %>
38 </div>
39 </section>
40
41 <div class="stats-tops">
42 <section class="stats-top">
43 <h2>Populairste posts</h2>
44 <% if (!s.topPosts.length || s.topPosts[0].views === 0) { %>
45 <p class="stats-empty">Nog geen weergaven.</p>
46 <% } else { %>
47 <ol>
48 <% s.topPosts.forEach(function(p){ %>
49 <li><a href="/<%= p.slug %>"><%= p.title %></a><span class="stats-count"><%= p.views %></span></li>
50 <% }); %>
51 </ol>
52 <% } %>
53 </section>
54 <section class="stats-top">
55 <h2>Meest geluisterd</h2>
56 <% if (!s.topTracks.length || s.topTracks[0].plays === 0) { %>
57 <p class="stats-empty">Nog geen plays.</p>
58 <% } else { %>
59 <ol>
60 <% s.topTracks.forEach(function(t){ %>
61 <li><span><%= t.title %></span><span class="stats-count"><%= t.plays %></span></li>
62 <% }); %>
63 </ol>
64 <% } %>
65 </section>
66 </div>
67
68 <% if (typeof linkClicks !== 'undefined' && linkClicks.length) { %>
69 <section class="stats-top" style="margin-top:1.2rem">
70 <h2>🔗 Link-in-bio klikken</h2>
71 <ol>
72 <% linkClicks.forEach(function(l){ %>
73 <li><a href="<%= l.url %>" target="_blank" rel="noopener"><%= l.url.replace(/^https?:\/\//,'').slice(0,48) %></a><span class="stats-count"><%= l.clicks %></span></li>
74 <% }); %>
75 </ol>
76 </section>
77 <% } %>
78</div>
79
80<style>
81.stats-page { max-width: 820px; margin: 2.5rem auto; padding: 0 1rem; }
82.stats-page h1 { font-family: var(--font-display, serif); font-size: 2rem; margin: .5rem 0 .25rem; }
83.stats-note { color: var(--ink-muted); font-size: .85rem; margin: 0 0 1.5rem; max-width: 60ch; }
84.stats-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 2rem; }
85.stat-card { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px; padding: 1rem 1.1rem; }
86.stat-num { font-family: var(--font-display, serif); font-size: 1.9rem; line-height: 1; color: var(--accent); }
87.stat-label { color: var(--ink-muted); font-size: .82rem; margin-top: .35rem; }
88
89.stats-chart-wrap { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 12px; padding: 1.1rem 1.2rem 1rem; margin-bottom: 2rem; }
90.stats-chart-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .5rem; }
91.stats-chart-head h2 { font-size: 1.05rem; margin: 0; }
92.stats-legend { display: flex; gap: .9rem; font-size: .78rem; color: var(--ink-muted); }
93.lg::before { content: ""; display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
94.lg-vis::before { background: var(--accent); }
95.lg-pv::before { background: color-mix(in srgb, var(--accent) 28%, transparent); }
96.stats-chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; margin-top: 1rem; }
97.sc-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
98.sc-bar { position: relative; width: 70%; max-width: 26px; height: 140px; display: flex; align-items: flex-end; }
99.sc-pv, .sc-vis { position: absolute; bottom: 0; left: 0; width: 100%; border-radius: 3px 3px 0 0; min-height: 2px; }
100.sc-pv { background: color-mix(in srgb, var(--accent) 28%, transparent); }
101.sc-vis { background: var(--accent); }
102.sc-day { font-size: .68rem; color: var(--ink-muted); margin-top: .35rem; }
103
104.stats-tops { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
105@media (max-width: 560px) { .stats-tops { grid-template-columns: 1fr; } }
106.stats-top { background: var(--paper-2); border: 1px solid var(--rule); border-radius: 12px; padding: 1rem 1.2rem; }
107.stats-top h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
108.stats-top ol { margin: 0; padding-left: 1.2rem; }
109.stats-top li { padding: .35rem 0; display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
110.stats-top a { color: var(--ink); text-decoration: none; }
111.stats-top a:hover { color: var(--accent); }
112.stats-count { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
113.stats-empty { color: var(--ink-muted); font-size: .88rem; margin: 0; }
114</style>
Note: See TracBrowser for help on using the repository browser.