Files
simpleblog/templates/admin/visitors.html
T
2026-11-14 17:05:01 +00:00

87 lines
3.3 KiB
HTML

{% extends "admin/base.html" %}
{% block admin_content %}
<div class="admin-panel">
<h1>Visitors</h1>
<p class="muted">Every tracked visitor. Click a row to see the pages they visited.</p>
<form method="get" action="{{ url_for('admin.visitors') }}" class="filter-form">
<label>
<span>Country</span>
<select name="country" id="country-filter">
<option value="">All countries</option>
{% for c in countries %}
<option value="{{ c.country_code }}" {% if c.country_code == selected_country %}selected{% endif %}>
{{ c.country_code|country_flag }} {{ c.country }} ({{ c.c }})
</option>
{% endfor %}
</select>
</label>
<label>
<span>City</span>
<select name="city" id="city-filter">
<option value="">All cities</option>
{% for city in cities %}
<option value="{{ city }}" {% if city == selected_city %}selected{% endif %}>{{ city }}</option>
{% endfor %}
</select>
</label>
<noscript><button type="submit" class="btn">Filter</button></noscript>
{% if selected_country or selected_city %}
<a class="btn" href="{{ url_for('admin.visitors') }}">Clear filters</a>
{% endif %}
<span class="muted">{{ rows|length }} shown</span>
</form>
<table class="admin-table">
<thead>
<tr>
<th>Visitor ID</th>
<th>Browser</th>
<th>OS</th>
<th>Device</th>
<th>Location</th>
<th>Source</th>
<th>Referrer domain</th>
<th>First seen</th>
<th>Last seen</th>
<th>Visits</th>
</tr>
</thead>
<tbody>
{% for r in rows %}
<tr>
<td><a href="{{ url_for('admin.visit_history', vid=r.visitor_id) }}"><code>{{ r.visitor_id }}</code></a></td>
<td>{{ r.browser or "&mdash;" }}</td>
<td>{{ r.os or "&mdash;" }}</td>
<td>{{ r.device }}</td>
<td>{% if r.city or r.country %}{% if r.country_code %}<span class="location-flag">{{ r.country_code|country_flag }}</span> {% endif %}{{ r.city or "—" }}{% if r.country %}<span class="muted">, {{ r.country }}</span>{% endif %}{% else %}&mdash;{% endif %}</td>
<td><span class="term">{{ r.source }}</span></td>
<td>{{ r.referrer_domain or "&mdash;" }}</td>
<td>{{ parse_date(r.first_seen) }}</td>
<td>{{ parse_date(r.last_seen) }}</td>
<td>{{ r.visits }}</td>
</tr>
{% else %}
<tr><td colspan="10" class="empty-state">No visitors match these filters.</td></tr>
{% endfor %}
</tbody>
</table>
</div>
<script>
(function () {
var country = document.getElementById("country-filter");
var city = document.getElementById("city-filter");
if (!country || !city) return;
// Changing country resets the city, otherwise a city that no longer
// belongs to the selection would keep filtering the table to zero rows.
country.addEventListener("change", function () {
city.value = "";
country.form.submit();
});
city.addEventListener("change", function () {
city.form.submit();
});
})();
</script>
{% endblock %}