Skip to content
Available for new work
Pages in Blog

GuidePremium

Analytics, reading time and related posts in CoullWorks Blog for Laravel

What the analytics module counts and what it does not, how views reach the database through the queue, how reading time and related posts are worked out, and where the numbers appear.

Updated 16 November 2026Back to the package pageBuy

The analytics module is small and private on purpose. It counts how many times each post is opened, ranks popular posts, picks related posts and works out reading time. It stores no personal data and sets no cookie. This page explains what it does; the four settings that tune it are in Settings, Analytics, and the two dashboard widgets are in Dashboard.

Turn it on#

  1. Set coullworks-blog.analytics.enabled to true in config/coullworks-blog.php. It is off by default, and while it is off nothing of the module is registered: no route, listener, command, schedule, extra or widget.
  2. Run its migrations: php artisan vendor:publish --tag=cwb-analytics-migrations, then php artisan migrate.
  3. Run a queue worker and the scheduler (see install). Views, reading time and related posts are written by queued jobs and two scheduled commands.
  4. Open a published post in a private window. After the worker runs, the post's count is 1.

What is counted#

A view is one reader opening one published post. Here is the whole path:

  1. A published post page includes a small hidden marker and a script. When the page loads, the script sends one POST to {blog}/views with the post id and the language, using navigator.sendBeacon. A reader whose browser cannot send a beacon is not counted.
  2. The server answers 204 No Content every time, counted or not, so a client learns nothing about the rules below.
  3. A request is not counted when its user agent contains a bot word (bot, crawl, spider, curl, wget, lighthouse, headless, preview, monitor, uptime and the others in analytics.bots, matched without regard to case), or when the same reader has already been counted for the same post in the last analytics.dedup_minutes (30 by default).
  4. A counted view becomes one queued job, RecordPostView. The job re-checks that the post is still published and then adds 1 to two numbers in one step: the post's running total and the row for today (UTC). Nothing is read and then written back, so two views at the same moment are never lost.

What is not stored. The "same reader" check is a keyed hash of the address, the user agent and the post, made with a salt that changes every day, and kept only in the cache for the dedup window. No address, no user agent, no cookie and no user id is written to any table. The PostViewed event carries a post id, a blog id and a language, and nothing about the reader.

What is kept. The running total of each post is kept for ever. The per-day rows are deleted after analytics.retention_days (default 90, a blog setting) by the scheduled command cwb:analytics-prune, which runs daily. Deleting old days never changes a total.

The queue and the schedule#

WhatNameNotes
Count a viewRecordPostView jobOne per accepted view. Needs a queue worker
Recompute reading time and related postsRefreshPostData jobQueued when a post is saved, published, unpublished or deleted
Rebuild every related listcwb:analytics-refresh-relatedScheduled daily at 03:00. Catches tag and category changes
Prune old day rowscwb:analytics-pruneScheduled daily

Set analytics.queue to put the jobs on a named queue (the default null is the default queue). analytics.throttle (120 a minute) limits the view endpoint per client, and analytics.middleware adds middleware to it. That middleware must not start a session, because the page may come from a full-page cache. analytics.popular_cache_seconds and analytics.related_cache_seconds (300 each; 0 turns the cache off) keep the lists. The page that shows a post never waits for any of this: it reads finished numbers.

Where the numbers appear#

The dashboard: Top posts ranked by views and the Views over time chart

The Dashboard of the Field Notes blog. At the bottom, Top posts lists seven posts with their view counts (Layering for wet, cold days 117, Every block type 109, down to How to choose a three-season tent 91) under a "7 days" selector, and Views over time draws a line over the last 30 days that rises sharply from 10 November.

  • Top posts widget (ability blog.analytics.view): the ten most viewed posts for 7 days, 30 days or all time.
  • Views over time widget: one point per UTC day, for 7, 30 (default) or 90 days.
  • Popular posts on the public post page: the most viewed posts of the last 7 days in the reader's language, as many as the setting Popular posts shown (1 to 20, default 5).

Both counts follow the blog chosen in the blog switcher, so each blog has its own numbers.

Reading time#

The foot of an article with a "3 min read" line under the comment form

The French article of the Atelier blog. At the very bottom, under the comment form, the line "3 min read" is the analytics block's reading time. The same page also shows "3 min read" in its byline at the top.

Reading time is the number of words in the post, divided by a reading speed, rounded up, and never less than 1 minute. The word count is the one the post already stores per language; the module never counts words itself.

  • Reading speed is the setting Reading speed (words per minute) (analytics.words_per_minute, 50 to 1000, default 200). Change it on the Settings screen, Analytics tab.
  • Each language has its own time, because each translation has its own word count.
  • The value is stored and rewritten only when it changes. It is recomputed when the post is saved.
  • On the page, the line reads "N min read" in an element with the class cw-reading-time, inside the analytics block at the foot of the article, so you can style it.

The byline's "N min read" and this line use the same setting. Core registers analytics.words_per_minute (default 200) and one calculation makes every "N min read" figure, in the Blade, Livewire and Inertia front ends and in the analytics module, so the two cannot disagree. A blog without the analytics module still has the setting.

The Analytics tab of the post editor: a Related posts list with an Add related post button

The Analytics tab of the post editor, where editors pin related posts by hand. The Related posts list is empty here, with one Add related post button under it.

The Related posts block: a heading and three cards titled Every block type, Lightbox and background video and Dividers in a guide, each with an arrow

The Related posts block under an article, three cards across.

The Related posts block on a phone-width window: the three cards stacked one under another

The same block at 390 px: the cards stack.

A post's related list is made of two parts, in this order:

  1. Pinned posts. The posts an editor chose by hand on the post's Analytics tab, in the order set there. Press Add related post, choose a post of the same blog, and drag the rows to reorder them. A row can be removed. A post cannot be related to itself, and every pinned post must belong to the same blog. Only pinned posts that are currently published are shown.
  2. Computed posts. The rest of the list is filled by score. A candidate is a published post of the same blog with a published version in the same language. Each tag it shares with the post scores 3 and each category it shares scores 2. Higher scores come first, then the newer post. A post that shares nothing is never chosen, and a post with no tags and no categories gets no computed list.

The list is cut to the setting Related posts shown (analytics.related_count, 1 to 20, default 4). It is rebuilt when the post is saved, published, unpublished or deleted, for the post and for the posts that share its tags and categories, and every night at 03:00 by cwb:analytics-refresh-related. You can run that command by hand after a bulk change. An unpublished or deleted post leaves every list at once.

On the page the list is the "Related posts" block of the analytics section at the foot of the article, and it also feeds the related grid and the rail when the analytics module is on. Without the module the rail shows the latest posts of the post's primary category instead.

Available for new work

UK based · PHP · Python · JS · TS. Every first call is free.