Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
New admin dashboard at /admin/user-insights providing: - Problem detection tab (problem scoring, locked accounts, failed logins) - Engagement ranking tab (engagement scoring, WoW comparison, sparklines) - Page map tab (section heatmap, top 50 pages, unused pages) - Paths tab (entry/exit pages, transitions, drop-off analysis) - Overview tab (Chart.js charts, hourly heatmap, device breakdown) - Individual user drill-down profiles with timelines and gauges Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
364 lines
18 KiB
HTML
364 lines
18 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}{{ user.name or user.email }} - User Insights{% endblock %}
|
|
|
|
{% block extra_css %}
|
|
<style>
|
|
.profile-container { max-width: 1400px; margin: 0 auto; padding: var(--spacing-lg); }
|
|
|
|
/* Back link */
|
|
.back-link { display: inline-flex; align-items: center; gap: var(--spacing-xs); color: var(--text-secondary); text-decoration: none; font-size: var(--font-size-sm); margin-bottom: var(--spacing-lg); }
|
|
.back-link:hover { color: var(--primary); }
|
|
|
|
/* Profile header */
|
|
.profile-header { background: white; padding: var(--spacing-xl); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); margin-bottom: var(--spacing-xl); display: flex; gap: var(--spacing-xl); align-items: flex-start; flex-wrap: wrap; }
|
|
.profile-info { flex: 1; min-width: 250px; }
|
|
.profile-name { font-size: var(--font-size-2xl); font-weight: 700; margin-bottom: var(--spacing-xs); }
|
|
.profile-email { color: var(--text-secondary); font-size: var(--font-size-sm); margin-bottom: var(--spacing-md); }
|
|
.profile-meta { display: flex; gap: var(--spacing-lg); flex-wrap: wrap; font-size: var(--font-size-sm); color: var(--text-secondary); }
|
|
.profile-meta-item { display: flex; flex-direction: column; gap: 2px; }
|
|
.profile-meta-label { font-size: var(--font-size-xs); text-transform: uppercase; letter-spacing: 0.5px; }
|
|
.profile-meta-value { font-weight: 600; color: var(--text-primary); }
|
|
|
|
/* Gauges row */
|
|
.gauges-row { display: flex; gap: var(--spacing-xl); }
|
|
.gauge-wrapper { text-align: center; }
|
|
.gauge { position: relative; width: 120px; height: 60px; overflow: hidden; }
|
|
.gauge-bg { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 10px solid var(--border); border-bottom-color: transparent; border-left-color: transparent; transform: rotate(225deg); }
|
|
.gauge-fill { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 10px solid; border-bottom-color: transparent; border-left-color: transparent; transition: transform 0.8s ease-out; }
|
|
.gauge-fill.low { border-top-color: #22c55e; border-right-color: #22c55e; }
|
|
.gauge-fill.medium { border-top-color: #f59e0b; border-right-color: #f59e0b; }
|
|
.gauge-fill.high { border-top-color: #ef4444; border-right-color: #ef4444; }
|
|
.gauge-value { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); font-size: var(--font-size-xl); font-weight: 700; }
|
|
.gauge-label { font-size: var(--font-size-xs); color: var(--text-secondary); margin-top: var(--spacing-xs); }
|
|
|
|
/* Section cards */
|
|
.section-card { background: white; padding: var(--spacing-lg); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); margin-bottom: var(--spacing-xl); }
|
|
.section-card h2 { font-size: var(--font-size-lg); font-weight: 600; margin-bottom: var(--spacing-lg); }
|
|
|
|
/* Two columns */
|
|
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: var(--spacing-xl); }
|
|
@media (max-width: 1024px) { .two-columns { grid-template-columns: 1fr; } }
|
|
|
|
/* Three columns */
|
|
.three-columns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--spacing-xl); }
|
|
@media (max-width: 1024px) { .three-columns { grid-template-columns: 1fr; } }
|
|
|
|
/* Timeline */
|
|
.timeline { position: relative; padding-left: var(--spacing-xl); }
|
|
.timeline::before { content: ''; position: absolute; left: 12px; top: 0; bottom: 0; width: 2px; background: var(--border); }
|
|
.timeline-item { position: relative; padding-bottom: var(--spacing-md); display: flex; gap: var(--spacing-md); align-items: flex-start; }
|
|
.timeline-dot { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-left: -30px; z-index: 1; font-size: 10px; }
|
|
.timeline-dot.login { background: #dbeafe; color: #2563eb; }
|
|
.timeline-dot.pageview { background: #dcfce7; color: #16a34a; }
|
|
.timeline-dot.search { background: #fef3c7; color: #d97706; }
|
|
.timeline-dot.conversion { background: #ede9fe; color: #7c3aed; }
|
|
.timeline-dot.problem { background: #fee2e2; color: #dc2626; }
|
|
.timeline-body { flex: 1; }
|
|
.timeline-desc { font-size: var(--font-size-sm); }
|
|
.timeline-time { font-size: var(--font-size-xs); color: var(--text-muted); }
|
|
|
|
/* Bars */
|
|
.bar-row { display: flex; align-items: center; gap: var(--spacing-sm); margin-bottom: var(--spacing-sm); }
|
|
.bar-label { width: 200px; min-width: 200px; font-size: var(--font-size-xs); font-family: monospace; word-break: break-all; color: var(--text-secondary); }
|
|
.bar-track { flex: 1; height: 20px; background: var(--background); border-radius: var(--radius-sm); overflow: hidden; }
|
|
.bar-fill { height: 100%; border-radius: var(--radius-sm); background: var(--primary); }
|
|
.bar-value { font-size: var(--font-size-xs); font-weight: 600; min-width: 30px; text-align: right; }
|
|
|
|
/* Hourly bars */
|
|
.hourly-bars { display: flex; align-items: flex-end; gap: 2px; height: 60px; }
|
|
.hourly-bar { flex: 1; background: var(--primary); border-radius: 2px 2px 0 0; min-width: 8px; opacity: 0.7; position: relative; }
|
|
.hourly-bar:hover { opacity: 1; }
|
|
.hourly-labels { display: flex; gap: 2px; }
|
|
.hourly-label { flex: 1; text-align: center; font-size: 9px; color: var(--text-muted); min-width: 8px; }
|
|
|
|
/* Data table */
|
|
.data-table { width: 100%; border-collapse: collapse; }
|
|
.data-table th { text-align: left; padding: var(--spacing-sm) var(--spacing-md); background: var(--background); font-weight: 600; font-size: var(--font-size-xs); color: var(--text-secondary); border-bottom: 1px solid var(--border); }
|
|
.data-table td { padding: var(--spacing-sm) var(--spacing-md); border-bottom: 1px solid var(--border); font-size: var(--font-size-sm); }
|
|
.data-table tr:last-child td { border-bottom: none; }
|
|
|
|
/* Stats grid */
|
|
.stats-mini { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--spacing-md); margin-bottom: var(--spacing-lg); }
|
|
.stat-mini { text-align: center; padding: var(--spacing-md); background: var(--background); border-radius: var(--radius); }
|
|
.stat-mini-value { font-size: var(--font-size-xl); font-weight: 700; }
|
|
.stat-mini-label { font-size: var(--font-size-xs); color: var(--text-secondary); margin-top: 2px; }
|
|
|
|
/* Chart */
|
|
.chart-container { position: relative; height: 250px; }
|
|
|
|
@media (max-width: 768px) {
|
|
.profile-header { flex-direction: column; }
|
|
.gauges-row { flex-direction: row; gap: var(--spacing-md); }
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="profile-container">
|
|
|
|
<a href="{{ url_for('admin.user_insights', tab='engagement') }}" class="back-link">
|
|
<svg width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
|
|
Powrót do User Insights
|
|
</a>
|
|
|
|
<!-- Profile Header -->
|
|
<div class="profile-header">
|
|
<div class="profile-info">
|
|
<div class="profile-name">{{ user.name or 'Bez nazwy' }}</div>
|
|
<div class="profile-email">{{ user.email }}</div>
|
|
<div class="profile-meta">
|
|
{% if user.company %}
|
|
<div class="profile-meta-item">
|
|
<span class="profile-meta-label">Firma</span>
|
|
<span class="profile-meta-value">{{ user.company.name }}</span>
|
|
</div>
|
|
{% endif %}
|
|
<div class="profile-meta-item">
|
|
<span class="profile-meta-label">Rola</span>
|
|
<span class="profile-meta-value">{{ user.role }}</span>
|
|
</div>
|
|
<div class="profile-meta-item">
|
|
<span class="profile-meta-label">Rejestracja</span>
|
|
<span class="profile-meta-value">{{ user.created_at.strftime('%d.%m.%Y') if user.created_at else 'N/A' }}</span>
|
|
</div>
|
|
<div class="profile-meta-item">
|
|
<span class="profile-meta-label">Ostatni login</span>
|
|
<span class="profile-meta-value">{{ user.last_login.strftime('%d.%m.%Y %H:%M') if user.last_login else 'Nigdy' }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="gauges-row">
|
|
<!-- Engagement gauge -->
|
|
<div class="gauge-wrapper">
|
|
<div class="gauge">
|
|
<div class="gauge-bg"></div>
|
|
{% set eng_class = 'low' if engagement_score >= 50 else ('medium' if engagement_score >= 20 else 'high') %}
|
|
<div class="gauge-fill {{ eng_class }}" style="transform: rotate({{ 225 + (engagement_score / 100 * 180) }}deg);"></div>
|
|
<div class="gauge-value">{{ engagement_score }}</div>
|
|
</div>
|
|
<div class="gauge-label">Zaangażowanie</div>
|
|
</div>
|
|
|
|
<!-- Problem gauge -->
|
|
<div class="gauge-wrapper">
|
|
<div class="gauge">
|
|
<div class="gauge-bg"></div>
|
|
{% set prob_class = 'high' if problem_score >= 51 else ('medium' if problem_score >= 21 else 'low') %}
|
|
<div class="gauge-fill {{ prob_class }}" style="transform: rotate({{ 225 + (problem_score / 100 * 180) }}deg);"></div>
|
|
<div class="gauge-value">{{ problem_score }}</div>
|
|
</div>
|
|
<div class="gauge-label">Problemy</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Quick stats -->
|
|
<div class="stats-mini">
|
|
<div class="stat-mini">
|
|
<div class="stat-mini-value">{{ avg_sessions_week }}</div>
|
|
<div class="stat-mini-label">Śr. sesji/tydzień</div>
|
|
</div>
|
|
<div class="stat-mini">
|
|
<div class="stat-mini-value">{{ (avg_session_duration / 60)|round(1) }}m</div>
|
|
<div class="stat-mini-label">Śr. czas sesji</div>
|
|
</div>
|
|
<div class="stat-mini">
|
|
<div class="stat-mini-value">{{ password_resets }}</div>
|
|
<div class="stat-mini-label">Resety hasła (30d)</div>
|
|
</div>
|
|
<div class="stat-mini">
|
|
<div class="stat-mini-value">{{ security_alerts_count }}</div>
|
|
<div class="stat-mini-label">Alerty (7d)</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="two-columns">
|
|
<!-- Timeline -->
|
|
<div class="section-card">
|
|
<h2>Oś czasu aktywności</h2>
|
|
{% if timeline %}
|
|
<div class="timeline" style="max-height: 600px; overflow-y: auto;">
|
|
{% for event in timeline %}
|
|
<div class="timeline-item">
|
|
<div class="timeline-dot {{ event.type }}">
|
|
{% if event.icon == 'key' %}🔑{% elif event.icon == 'eye' %}👁{% elif event.icon == 'search' %}🔍{% elif event.icon == 'check' %}✓{% elif event.icon == 'alert' %}⚠{% elif event.icon == 'shield' %}🛡{% else %}•{% endif %}
|
|
</div>
|
|
<div class="timeline-body">
|
|
<div class="timeline-desc">{{ event.desc }}</div>
|
|
<div class="timeline-time">{{ event.time.strftime('%d.%m.%Y %H:%M') }}</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
{% else %}
|
|
<p style="color: var(--text-muted); text-align: center;">Brak zdarzeń.</p>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<!-- Behavioral stats -->
|
|
<div>
|
|
<!-- Favorite pages -->
|
|
<div class="section-card">
|
|
<h2>Ulubione strony (30d)</h2>
|
|
{% for p in fav_pages %}
|
|
<div class="bar-row">
|
|
<div class="bar-label">{{ p.path }}</div>
|
|
<div class="bar-track">
|
|
<div class="bar-fill" style="width: {{ p.bar_pct }}%;"></div>
|
|
</div>
|
|
<div class="bar-value">{{ p.count }}</div>
|
|
</div>
|
|
{% endfor %}
|
|
{% if not fav_pages %}
|
|
<p style="color: var(--text-muted); text-align: center;">Brak danych.</p>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<!-- Hourly pattern -->
|
|
<div class="section-card">
|
|
<h2>Wzorzec godzinowy (30d)</h2>
|
|
<div class="hourly-bars">
|
|
{% set max_h = hourly_bars|map(attribute='count')|max if hourly_bars|map(attribute='count')|max > 0 else 1 %}
|
|
{% for h in hourly_bars %}
|
|
<div class="hourly-bar" style="height: {{ (h.count / max_h * 55 + 5)|int }}px;" title="{{ h.hour }}:00 — {{ h.count }}"></div>
|
|
{% endfor %}
|
|
</div>
|
|
<div class="hourly-labels">
|
|
{% for h in hourly_bars %}
|
|
<div class="hourly-label">{% if h.hour % 3 == 0 %}{{ h.hour }}{% endif %}</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Devices & Browsers -->
|
|
<div class="section-card">
|
|
<h2>Urządzenia i przeglądarki</h2>
|
|
<div style="display: flex; gap: var(--spacing-xl); flex-wrap: wrap;">
|
|
<div style="flex: 1; min-width: 120px;">
|
|
<strong style="font-size: var(--font-size-xs); color: var(--text-secondary);">URZĄDZENIA</strong>
|
|
{% for d in devices %}
|
|
<div style="margin-top: var(--spacing-sm); font-size: var(--font-size-sm);">
|
|
{{ d.type|capitalize }}: <strong>{{ d.count }}</strong>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
<div style="flex: 1; min-width: 120px;">
|
|
<strong style="font-size: var(--font-size-xs); color: var(--text-secondary);">PRZEGLĄDARKI</strong>
|
|
{% for b in browsers %}
|
|
<div style="margin-top: var(--spacing-sm); font-size: var(--font-size-sm);">
|
|
{{ b.name }}: <strong>{{ b.count }}</strong>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Problem history -->
|
|
<div class="section-card">
|
|
<h2>Historia problemów</h2>
|
|
<div class="two-columns">
|
|
<div>
|
|
<h3 style="font-size: var(--font-size-sm); font-weight: 600; margin-bottom: var(--spacing-md);">Błędy JS</h3>
|
|
{% if js_errors %}
|
|
<table class="data-table">
|
|
<thead>
|
|
<tr><th>Wiadomość</th><th>Strona</th><th>Data</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for e in js_errors %}
|
|
<tr>
|
|
<td style="max-width: 300px; word-break: break-all; font-size: var(--font-size-xs);">{{ e.message[:100] }}</td>
|
|
<td style="font-size: var(--font-size-xs);">{{ e.url[:50] if e.url else 'N/A' }}</td>
|
|
<td style="white-space: nowrap;">{{ e.occurred_at.strftime('%d.%m %H:%M') }}</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
{% else %}
|
|
<p style="color: var(--text-muted);">Brak błędów JS.</p>
|
|
{% endif %}
|
|
</div>
|
|
<div>
|
|
<h3 style="font-size: var(--font-size-sm); font-weight: 600; margin-bottom: var(--spacing-md);">Wolne strony (> 3s)</h3>
|
|
{% if slow_pages %}
|
|
<table class="data-table">
|
|
<thead>
|
|
<tr><th>Strona</th><th>Czas</th><th>Data</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for p in slow_pages %}
|
|
<tr>
|
|
<td style="font-family: monospace; font-size: var(--font-size-xs);">{{ p.path }}</td>
|
|
<td style="color: var(--error); font-weight: 600;">{{ p.load_time_ms }}ms</td>
|
|
<td style="white-space: nowrap;">{{ p.viewed_at.strftime('%d.%m %H:%M') }}</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
{% else %}
|
|
<p style="color: var(--text-muted);">Brak wolnych stron.</p>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Engagement trend chart -->
|
|
<div class="section-card">
|
|
<h2>Trend zaangażowania (30 dni)</h2>
|
|
<div class="chart-container">
|
|
<canvas id="trendChart"></canvas>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Search queries -->
|
|
{% if search_queries %}
|
|
<div class="section-card">
|
|
<h2>Ostatnie wyszukiwania</h2>
|
|
<div style="display: flex; flex-wrap: wrap; gap: var(--spacing-sm);">
|
|
{% for s in search_queries %}
|
|
<span style="padding: 4px 12px; background: var(--background); border-radius: var(--radius); font-size: var(--font-size-sm);">
|
|
"{{ s.query }}" <span style="color: var(--text-muted); font-size: var(--font-size-xs);">{{ s.searched_at.strftime('%d.%m') }}</span>
|
|
</span>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
const trendData = {{ trend_data|tojson|safe }};
|
|
const trendCtx = document.getElementById('trendChart').getContext('2d');
|
|
new Chart(trendCtx, {
|
|
type: 'line',
|
|
data: {
|
|
labels: trendData.labels,
|
|
datasets: [{
|
|
label: 'Dzienny score',
|
|
data: trendData.scores,
|
|
borderColor: '#6366f1',
|
|
backgroundColor: 'rgba(99, 102, 241, 0.1)',
|
|
fill: true,
|
|
tension: 0.4,
|
|
pointRadius: 2
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
plugins: { legend: { display: false } },
|
|
scales: {
|
|
x: { grid: { display: false } },
|
|
y: { beginAtZero: true, max: 30 }
|
|
}
|
|
}
|
|
});
|
|
{% endblock %}
|