Search by

wakeworks / analytics

Zazamawakeworks

A privacy focused analytics module integrated into Silverstripe

Package info

github.com/wakeworks/Analytics

Type:silverstripe-vendormodule

pkg:composer/wakeworks/analytics

Statistics

Installs: 382

Dependents: 0

Suggesters: 0

Stars: 6

Open Issues: 4

3.1.0 2026-12-03 16:17 UTC

README

Introduction

This module enables basic analytics in Silverstripe without saving identifying data and without cookies.

Screenshot

Requirements

  • silverstripe/framework ^6
  • silverstripe/admin ^3

For Silverstripe 5, check out version/branch 2, for Silverstripe 4, check out version/branch 1.

Installation

composer require wakeworks/analytics

After a /dev/build, the module will start logging requests. You can find an overview of the data at /admin/analytics.

ATTENTION: Please read through "Garbage Collection" if you don't want your database to grow infinitely.

How does it work?

  • On every request, a user sends its User-Agent string to the server. Using a middleware and matomo/device-detector, we can parse it and check which browser/device it is or if it's a bot.
  • This information is stored in the database together with other collected analytics.
  • No cookie or session is used. A request counts as the entry of a visit if it has no referrer or a referrer from another site (see Visits and referrers).
  • In order to filter out as many bots as possible, we don't save any request with an unknown User-Agent. To optimize bot detection, use image verification.
    Also, some routes are automatically skipped, e.g. UserDefinedFormController/ping, /admin/* or /dev/*, see "When is no information stored?".

Admin panel

At /admin/analytics you find:

  • Overview: page views, visits and pages per visit, compared to the period of the same length before
  • Daily page views and visits
  • Most viewed pages / URLs
  • Referrers (domain of the referring site or direct/unknown)
  • Devices, browser families, browser versions and operating systems

The selected range (7 days, 1 month, 3 months, 1 year, all) applies to all charts.

Statistics tab on pages

Users with access to the analytics section see a "Statistics" tab on every page in the CMS: page views and entries (visits that started on the page) of the last 30 days, compared to the 30 days before, with a daily chart.

SilverStripe\CMS\Model\SiteTree:
  # Number of days shown (default 30)
  analytics_days: 30
  # Hide the tab
  analytics_tab_enabled: false

Visits and referrers

The module doesn't set a cookie to recognise visitors. Instead, a request is the entry of a visit if it

  • has no Referer header (e.g. typed in, bookmark, app), or
  • comes from another site. Only the host of that site is stored (e.g. google.com), never the full referring URL.

Requests from this site (navigation between pages) are counted as page views but not as visits. The host of the request and of the base URL are always treated as internal. If the site runs on several domains, add the others:

WakeWorks\Analytics\Middlewares\AnalyticsProcessorMiddleware:
  internal_hosts:
    - other-domain.example

Visits are therefore an approximation: e.g. a reload without referrer counts as a new visit.

Improve bot detection by using image verification

While removing unknown User-Agents already takes away a fair share of bots, there are still many crawlers that just call your website without loading its content.

In order to remove them from the statistics, you can insert an image tracking code by activating it with the following configuration.

WakeWorks\Analytics\Middlewares\AnalyticsProcessorMiddleware:
  image_verification: true

This method works by inserting a hidden <img> tag before </body> on every valid tracking request. If a user loads the image, the request will create an entry in the database, otherwise it won't.

Garbage Collection

After some time, your database will fill up with too many requests that you might not care about anymore (e.g. very old ones).

Use the task /dev/tasks/AnalyticsGarbageCollectionTask in order to delete them.

You should do this automatically, by using a cron job or, if that's not possible, by activating the Garbage Collection every xth request via the middleware.

WakeWorks\Analytics\Middlewares\AnalyticsProcessorMiddleware:
  # Run AnalyticsGarbageCollectionTask with probability of 1/100
  # => ~ every 100 requests. (Default: 0, off)
  gc_divisor: 100
  # Delete requests older than (default) 365 days.
  preserve_for_days: 365

Only do this if the amount of requests you collect is reasonably small, otherwise the DELETE query might take uncomfortably long for the visitor.

Extension for Subsites

If you have silverstripe/subsites installed and want to track by Subsite, you can simply enable the SubsiteExtension and everything will work out of the box.

WakeWorks\Analytics\Models\AnalyticsLog:
  extensions:
    - WakeWorks\Analytics\Extensions\SubsitesExtension

Which information is stored?

  • Current date
  • Requested url
  • Operating System with version
  • Browser with version
  • Device type (desktop, smartphone etc.)
  • Whether the request is the entry of a visit
  • Domain of the referring site for entries from other sites
  • SiteTreeID (PageID) if possible

When is no information stored?

  • Unidentifiable/Bot User-Agents
  • Status codes that are not between 200-204 due to bots spamming /wp-* etc.
  • Admin backend urls
  • Security urls / Controller
  • DevelopmentAdmin Controller (/dev urls)
  • UserDefinedFormController/ping