Who comes
Every page and API request the site serves is counted once, by the store that served it, as a visit that names nobody. The files a page is made of (scripts, styles, fonts, photographs, and the text and XML files at the root) are not counted, because one visit is one page and not the forty files behind it, and neither are the Admin tab's own reads. The Admin tab draws the count day by day, split three ways: people, scanners and crawlers, and the site reading itself.
In plain words
This page says how the site counts who visits it. Every page or API request is counted once as a visit that names nobody. People are counted apart from bots, and the site's own checks are counted apart from both.
What that is worth: a developer sees a visitor count that groups a day's requests without ever storing a full address, and the organization gets a count of real readers that its own tools cannot inflate.
What a visit carries
A visit is handed to the counter as a record with six fields, and a record with no field for a thing cannot carry it:
public sealed record ActivityHit(DateTimeOffset At, string Visitor, string Network, string Path, string Store, bool Bot, string? Source = null)
{
public string? Person { get; init; }
}
public sealed record ActivityHour(string Store, DateTimeOffset Hour, int Requests, int Bots, IReadOnlyDictionary<string, int> Paths);
public sealed record ActivityVisitor(
string Store,
string Day,
string Visitor,
string Network,
DateTimeOffset FirstSeen,
DateTimeOffset LastSeen,
int Requests,
int Bots,
IReadOnlyDictionary<string, int> Paths,
IReadOnlyDictionary<string, int>? Sources = null);
public sealed record ActivityAvailability(bool Available, string Reason, string? Retention = null);
public sealed record ActivityCost(double Charge, int Operations, int Failures);
public interface IActivityCost
{
ActivityCost Cost { get; }
}
public interface IActivityStore
{
Task<ActivityAvailability> AvailabilityAsync(CancellationToken cancellation);
Task RecordAsync(IReadOnlyList<ActivityHit> hits, CancellationToken cancellation);
Task<IReadOnlyList<ActivityHour>> HoursAsync(DateTimeOffset since, CancellationToken cancellation);
Task<IReadOnlyList<ActivityVisitor>> VisitorsAsync(DateTimeOffset since, CancellationToken cancellation);
}
public sealed class NullActivityStore(string reason) : IActivityStore
{
public static readonly NullActivityStore Instance = new("this store keeps no activity");
public Task<ActivityAvailability> AvailabilityAsync(CancellationToken cancellation) =>
Task.FromResult(new ActivityAvailability(false, reason));
public Task RecordAsync(IReadOnlyList<ActivityHit> hits, CancellationToken cancellation) => Task.CompletedTask;
public Task<IReadOnlyList<ActivityHour>> HoursAsync(DateTimeOffset since, CancellationToken cancellation) =>
Task.FromResult<IReadOnlyList<ActivityHour>>([]);
public Task<IReadOnlyList<ActivityVisitor>> VisitorsAsync(DateTimeOffset since, CancellationToken cancellation) =>
Task.FromResult<IReadOnlyList<ActivityVisitor>>([]);
}
Live from api/TheYard.Application/Shared/History/Activity.cs, region activity-port, read from this build at 99df7a8.
- When, to the hour.
- The visitor token, a keyed hash of the day and the address. Within a day the same address is the same token on both sites, so one person's requests group together; the next day it is a different token, so nothing joins one day to the next. The key is the signing key the one web app holds and nobody outside has, which is what stops anybody turning a token back into an address by hashing every IPv4 address there is.
- The network, the address cut to its first three octets (
203.0.113.x): enough to see a network, a country or an obvious scanner range, and not enough to name a machine. A full address is never stored, on either store.
- The path, with any at sign percent-encoded so an address pasted into a URL cannot travel. The query string is never recorded.
- The store that served the request (Azure SQL Database or Azure Cosmos DB), so the graph keeps a line for each site.
- Whether it looked like a bot, read from the request's user agent and what it asked for. The agent itself is read and forgotten.
public sealed partial class VisitorTokens(string key)
{
private readonly byte[] _key = Encoding.UTF8.GetBytes(key);
public string TokenFor(string address, DateTimeOffset at)
{
byte[] hash = HMACSHA256.HashData(_key, Encoding.UTF8.GetBytes(at.UtcDay + "|" + address));
return Convert.ToHexStringLower(hash.AsSpan(0, 16));
}
public string PersonFor(string address, string? userAgent)
{
byte[] hash = HMACSHA256.HashData(_key, Encoding.UTF8.GetBytes("person|" + address + "|" + AgentFamily(userAgent)));
return Convert.ToHexStringLower(hash.AsSpan(0, 16));
}
public static string AgentFamily(string? userAgent) =>
string.IsNullOrEmpty(userAgent) ? "" : Versions().Replace(userAgent, "");
[GeneratedRegex(@"\d+(?:[._]\d+)*")]
private static partial Regex Versions();
public string OperatorMark()
{
byte[] hash = HMACSHA256.HashData(_key, Encoding.UTF8.GetBytes("operator|mark"));
return Convert.ToHexStringLower(hash.AsSpan(0, 16));
}
public byte[] BlogSessionFor(string address, DateTimeOffset at) =>
HMACSHA256.HashData(_key, Encoding.UTF8.GetBytes("blog|" + at.UtcDay + "|" + address));
public static string NetworkOf(string? address)
{
if (string.IsNullOrWhiteSpace(address))
{
return "x";
}
string[] octets = address.Split('.');
if (octets.Length == 4 && octets.All(octet => int.TryParse(octet, out int value) && value is >= 0 and <= 255))
{
return $"{octets[0]}.{octets[1]}.{octets[2]}.x";
}
if (address.Contains(':', StringComparison.Ordinal))
{
string[] groups = address.Split(':');
return string.Join(':', groups.Take(3)) + ":x";
}
return "x";
}
public static string AddressOf(HttpContext context) =>
WithoutPort(context.Connection.RemoteIpAddress?.ToString() ?? "");
public static string WithoutPort(string address)
{
if (address.StartsWith('['))
{
int close = address.IndexOf(']', StringComparison.Ordinal);
return close > 1 ? address[1..close] : address;
}
int colon = address.IndexOf(':', StringComparison.Ordinal);
return colon > 0 && colon == address.LastIndexOf(':') && address[..colon].Count(c => c == '.') == 3
? address[..colon]
: address;
}
}
Live from api/TheYard.Api/Shared/Activity/Activity.cs, region visitor-token, read from this build at 99df7a8.
A port after an address is dropped before the token is made, so one machine is one visitor whatever port it came from.
Three kinds of visitor
Each visitor-day is exactly one of three kinds, and the three add up to the day's total:
- People. Everybody who made a request that did not look like a bot.
- Scanners and crawlers. A token whose every request looked like a bot (by its agent or by what it asked for): the probes for WordPress,
.env and .git that every public address gets, and the search engines, whose agents name themselves.
- The site's own reads. The tools that check the site on its owner's behalf, the page sweep, the release's own readers and App Service's health check among them, carry
TheYard-SelfRead in their user agent or come from the machine itself, and are counted apart so they never pass for people. A stranger could claim the mark and hide from the count; that costs a count of visitors and reaches nothing else.
The chart stacks the three day by day, people at the bottom, in three colours chosen as a set that stays apart under colour blindness (Colour and style). Visitors only is the default view; the lines by store are a click away.
Where they came from
On a page load, and only then, a visit also keeps the lowercased host of the page that linked here and nothing else of it, so neither a path nor a query that could say something about the reader reaches a row. The hosts are grouped on the card as LinkedIn, GitHub, search, another site, or typed and unknown. A link opened from a PDF, the resume among them, sends no referrer, so it reads as typed unless the link carries a tag of its own.
The path through
The card also counts, in visitor-days, how many readers took each step of the path a reader takes through a portfolio: the landing page, the inventory, the page about the author, and the resume. Each step is a set of paths, and the resume counts both addresses it is served from.