Add charts and bounce rate to admin Analytics, filter self-referrers

- Bar chart: visitors per day
- Line chart: pageviews per day (with fill)
- Bounce rate KPI with color coding (green/yellow/red)
- Filter out self-referrers (ticket.e-cosplay.fr, esyweb.local)
- Uses Chart.js via cdn.jsdelivr.net (already in CSP)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-26 12:14:33 +01:00
parent efe967389d
commit 375357ddde
2 changed files with 79 additions and 0 deletions

View File

@@ -35,6 +35,18 @@
</div>
</div>
{# Charts #}
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
<div class="admin-card">
<h2 class="text-sm font-black uppercase tracking-widest mb-4">Visiteurs par jour</h2>
<canvas id="chart-visitors" height="200"></canvas>
</div>
<div class="admin-card">
<h2 class="text-sm font-black uppercase tracking-widest mb-4">Pages vues par jour</h2>
<canvas id="chart-pageviews" height="200"></canvas>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
{# Top pages #}
<div class="admin-card">
@@ -121,4 +133,30 @@
{% endfor %}
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js"></script>
<script>
(function() {
const labels = {{ chart_labels|json_encode|raw }};
const opts = {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false } },
scales: {
x: { grid: { display: false }, ticks: { font: { weight: 'bold', size: 10 } } },
y: { beginAtZero: true, ticks: { font: { weight: 'bold', size: 10 } } }
}
};
new Chart(document.getElementById('chart-visitors'), {
type: 'bar',
data: { labels, datasets: [{ data: {{ chart_visitors|json_encode|raw }}, backgroundColor: '#fabf04', borderColor: '#111827', borderWidth: 2 }] },
options: opts
});
new Chart(document.getElementById('chart-pageviews'), {
type: 'line',
data: { labels, datasets: [{ data: {{ chart_pageviews|json_encode|raw }}, borderColor: '#111827', backgroundColor: 'rgba(250,191,4,0.2)', borderWidth: 3, fill: true, tension: 0.3, pointBackgroundColor: '#fabf04', pointBorderColor: '#111827', pointBorderWidth: 2 }] },
options: opts
});
})();
</script>
{% endblock %}