Changeset e3a5aed in Klonkt for src/views/pages/admin-stats.ejs


Ignore:
Timestamp:
06/30/2026 10:11:03 PM (2 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
d9c5eb8
Parents:
65a0697
Message:

feat(stats): let the admin exclude their own IP from statistics

Logged-in admins were already skipped, but an admin browsing logged out (incognito, another browser)
still inflated the numbers. Admin -> Statistics now shows your current IP with a one-click "Don't
count my visits" toggle, stored in a stats_exclude_ips app_setting and checked on every pageview
(recordPageview/recordPostView). Trust-proxy gives the real client IP; normalised for matching.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/pages/admin-stats.ejs

    r65a0697 re3a5aed  
    33  <h1><%= t('astat.title') %></h1>
    44  <p class="stats-note"><%= t('astat.intro') %></p>
     5
     6  <% if (typeof myIp !== 'undefined' && myIp) { %>
     7  <form method="post" action="/admin/stats/exclude-ip" class="stats-note" style="margin:.2rem 0 1.2rem;display:flex;align-items:center;gap:.6rem;flex-wrap:wrap;">
     8    <span><%= t('astat.your_ip') %> <code><%= myIp %></code> —
     9      <% if (ipExcluded) { %><strong><%= t('astat.ip_not_counted') %></strong><% } else { %><%= t('astat.ip_counted') %><% } %></span>
     10    <button type="submit" class="btn" style="padding:3px 10px;font-size:.85rem;"><%= ipExcluded ? t('astat.ip_count') : t('astat.ip_exclude') %></button>
     11  </form>
     12  <% } %>
    513
    614  <% var s = stats; var _max = Math.max(1, ...s.series.map(function(d){ return d.pageviews; })); %>
Note: See TracChangeset for help on using the changeset viewer.