Skip to content

About

Cookie-free page view analytics for Umbraco 17, stored in the site's own database. No second database, no raw IP or User-Agent kept.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

BaryoDev.Umbraco.Analytics

Page view analytics for Umbraco 17 that stays in your own site. Events go into your Umbraco database (SQLite or SQL Server) through tables the package creates. No second database, no external service, no cookie by default.

The visitor counting idea comes from Umami (MIT). The code here is written from scratch. See docs/design.md.

Install

dotnet add package BaryoDev.Umbraco.Analytics

Start the site once. The migration creates baryoAnalyticsEvent and baryoAnalyticsDaily. An Analytics dashboard appears in the Content section.

Collect page views

Script mode is the default. Add the tag to your layout:

<script defer src="/baryo-analytics/tracker.js"></script>

The script posts to /baryo-analytics/collect next to itself. Set data-endpoint="..." on the tag to use another URL.

Middleware mode records HTML page requests on the server, no script needed. Set "Mode": "Middleware".

Only one mode runs at a time, so a page is not counted twice.

Config

All keys live under BaryoDev:Analytics in appsettings.

Key Default Meaning
Enabled true Turn collection off
Mode Script Script or Middleware
SiteKey default Mixed into the visitor hash
Secret generated Server secret. If empty, one is generated on first run and kept in the Umbraco key-value store. Set it from an environment variable or a secret store, never commit it
SaltRotation Monthly Monthly, Daily or Cookie
VisitIdleMinutes 30 Idle time that ends a visit
RetentionDays 395 Raw events older than this are rolled into daily totals and deleted. Daily rows are kept
DeleteOldPageAndReferrerRows false When true, daily page and referrer rows are deleted once they are older than twice RetentionDays. Deleted rows cannot be recovered. Totals, device, browser and country rows are always kept
RespectDoNotTrack true Skip requests with DNT: 1
RespectGlobalPrivacyControl true Skip requests with Sec-GPC: 1
CountryHeader CF-IPCountry Country is stored only if this header is present
ClientIpHeader empty Header with the client IP chain. Read only when the connection comes from a TrustedProxies entry
TrustedProxies empty IPs or CIDRs of your proxies. The header chain is walked from the right and the first hop that is not a trusted proxy is the client
ExcludedPaths empty Extra path prefixes to skip
ExtraBotUserAgents empty Extra User-Agent fragments to skip. The built-in list matches fragments such as bot, so a rare real browser can be skipped
CookieName ba_vid Cookie name in Cookie mode
RateLimitPerMinute 120 Hits per client per minute. Extra hits are dropped. 0 turns it off. Tracks at most 50,000 clients per minute, then drops hits from new ones
QueueCapacity 10000 Events held in memory before new ones are dropped
AllowedOrigins empty Extra hosts whose pages may post beacons, for a site served on more than one domain. Hosts, host:port or full origins, for example www.example.org
RequirePublishedContent false Script mode only. Drop a hit whose path does not resolve to published content. Also drops 404 and non-Umbraco routes, so it is off by default

/umbraco, /App_Plugins and /baryo-analytics paths are always skipped, and so are bots.

A beacon is accepted when the browser sends Sec-Fetch-Site: same-origin, or when its Origin header (or Referer when Origin is absent) has the same host as the request, after forwarded headers. Sec-Fetch-Site is sent whatever the page's Referrer-Policy, so a no-referrer page is still counted, and it does not depend on the Host your proxy forwards. Otherwise the hit is dropped, the endpoint still answers 202, and one warning is logged per process. Behind a proxy that rewrites the Host header, keep the original Host, enable XForwardedHost in forwarded headers, or add the page host to AllowedOrigins. If the tracker is served from another domain than the pages, or the site has several domains, list the page hosts in AllowedOrigins. This stops casual cross-site junk. It does not stop a script that sets its own headers, so the rate limit still applies.

Behind a reverse proxy, configure ASP.NET Core forwarded headers or set ClientIpHeader together with TrustedProxies. A header from any other source is ignored, so it cannot be forged. Otherwise all visitors share one address and count as one. With no usable address at all (no remote IP), the rate limit is skipped and a warning is logged once. If every visitor shares one proxy address, the limit of RateLimitPerMinute applies to the whole site, so fix the forwarded headers first. The rate limit stays on when there is no forwarded header: behind a proxy that sends no client IP header, every visitor shares one bucket, so raise RateLimitPerMinute or set ClientIpHeader. A warning is logged once when the connection address is private or loopback and ClientIpHeader is not set. A warning is logged (at most once an hour) when a whole minute of hits came from one address and none carried a forwarded header.

Privacy model

  • The visitor id is SHA-256(siteKey, IP, User-Agent, salt, secret), cut to 32 hex characters. The salt changes every month (or day), so ids do not carry over.
  • The raw IP and User-Agent are not stored. The event table has no column for them.
  • No cookie is set unless SaltRotation is Cookie. That mode uses a random first-party id cookie and stores only its hash.
  • The stored path is the page path as typed, without the query string or fragment. If your URLs carry tokens or emails in the path, the raw rows keep them for RetentionDays and the daily page rows keep them until you delete them. Use ExcludedPaths for those routes, and set DeleteOldPageAndReferrerRows to true to delete daily page and referrer rows after twice RetentionDays. The referrer is kept as a host and the UTM values as sent.
  • The path loses its query string. The referrer is kept as a host. Only the three utm_ values are kept from the query.
  • Device class and browser family come from the User-Agent and are stored as short labels.
  • A generated secret lives in the same database as the events. Set Secret from an environment variable or a secret store if you want it kept apart.
  • Country comes from CountryHeader as sent. Only use it behind a proxy that sets or overwrites that header.
  • Visit stitching is per server process. With several servers, a visitor who moves between them can be counted as more than one visit.
  • This describes what the code does. Whether it meets the consent rules where you operate is your call.

Dashboard

A Last 24 hours view with 24 hourly bars (shown in your local time), visitors, visits and page views, top pages and top referrers, read from the raw events. Visitors, visits and page views for 7, 30 or 90 days, a daily bar chart, top pages, top referrers, devices and browsers. Access follows the Content section.

Build

dotnet build -c Release

Licence

MIT.

About

Cookie-free page view analytics for Umbraco 17, stored in the site's own database. No second database, no raw IP or User-Agent kept.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages