All your data are belong to us. -- Track pageviews, referrers and devices on your Kirby 3 website.
Track page views, referrers and devices on your Kirby 3 website.
This plugin provides a simple solution for self-hosted, minimal and non-intrusive visitor analytics.
search
, social
or website
.Stats
class also exposes most collected data.sha1( base64_encode( mix( anonimize(IP, 0.0.0.x) + trunc(UserAgent) + Salt)) )
.weekly
or even provide your own custom timeframe utility.Consider this plugin beta. Any feedback or bug reports are welcome. It’s been successfully running on multiple production websites for about a year. The tracking part is almost done, when the panel interface will be more polished, I’ll consider a first release.
Please note that the database structure might evolve over time, until a more stable release is available (for which you’ll be able upgrade your old databases; the upgrade meccanism already works).
I guess a lot of options could be added to suit the plugin for a wider variety of website setups. The panel interface could also be improved and translated.
Any contributions (discussions, reports, feedback and pull requests) are welcome, as long as the collected stats stay minimal and reasonably non-intrusive.
You may also have a look at the open issues.
Information
tab of the plugin’s panel view.Option 1 : Download
Download and copy this repository to /site/plugins/simplestats
.
Option 2 : Git submodule
git submodule add https://github.com/daandelange/kirby3-simplestats.git site/plugins/simplestats
Eventually add --depth 1
to discard the repo commit history. (saves disk space)
Option 3 : Composer (update the command to match the latest version)composer require daandelange/simplestats:~0.6.2-beta
(update with composer update
)
Note: While SimpleStats
is still alpha, there is no stable channel for composer, so you need to specify the unstable version.
Note: I don’t make a release for every small change. If you want to use the latest version with composer, you can manually enter a commit :composer require daandelange/simplestats:dev-master#dbdb4a2 --with-dependencies
.
If you wish to display page stats in a section, you may add a pagestats
panel section to your page’s blueprint.
sections:
pagestats:
type: pagestats
label: TestHeadline
size: small
showTotals: true
showTimeline: true
showLanguages: true
showFullInfo: false
Multi-language websites are supported. For each page, there’s a global counter, with an optional counter for each language.
Warning: Do not add or remove languages to your Kirby installation without resetting your database file !
Also, the panel view has not (yet?) been translated.
Note: During the alpha phase, I’m working with a multi-language context. While I try to test single language setups from time to time, SimpleStats might break occasionally in these setups.
The database file is a simple .sqlite
file that holds all tracking data. You can view it from the dedicated panel area, or by including smaller widget sections in the panel page editor. The popular Sqlite format allows you to easily grab the data and visualise it your way, or import it in other software.
It’s recommended to occasionally backup your stats database file.
Tracking Resolution and Kirby Languages (Important !)
Please note that the database is tightly bound to the tracking resolution option (
daandelange.simplestats.tracking.timeFrameUtility
) and can not be changed afterwards. Changing the resolution while keeping the same database file results in unefined behaviour.
The same goes for Kirby’s Language setup: if you change your multilanguage settings, you need to create a new database file (however, manually editing the previous database file, you might be able to preserve your data).
This could be automated with update scripts.Generating Stats
If you’d like to populate the database with some fake stats (useful for testing or developing SimpleStats), you can use the panel interface to generate some in the “Information” tab.
Depending on your local laws, you might need to sit down and define how personal visitor data is handled.
You might want to inspect the source code to know what’s going on in details.
As the license states, there’s no guarantee whatsoever.
If you want to use the default onLoad
tracking method, no further action is required, the plugin automatically hooks to Kirby route events. If you choose any other tracking method, you’ll need to integrate the method in your code.
Possible Tracking Methods: (Config value:
tracking.method
)
SimpleStatsTrackingMode::OnLoad
: Uses kirby’s route hooks to track content when it’s served.
Pros: Ensures that every request is tracked.
Cons: Slows down the page serve time.
Setup steps: None.SimpleStatsTrackingMode::OnImage
: Generate a simple image tag within your HTML.
Pros: Doesn’t slow down page serve time.
Cons: You trust the user to load the image.
Setup steps: You need to call$page->simpleStatsImage()
in your template code. You probably want to do this once insite/snippets/footer.php
for example.SimpleStatsTrackingMode::Disabled
: Disables tracking, no further action is needed. (now much tested yet)
Setup steps: None.SimpleStatsTrackingMode::Manual
: Manually call the tracking function.
Pros: Very flexible, might solve edge-case-usage.
Setup steps: You have to callSimpleStats::track()
manually. Additionally, you need to populate the http headers argument accrdingly to track referers and device information.
Like any Kirby plugin, options can be set in your site/config/config.php
.
All available options are listed and explained in src/config/options.php
.
Example :
// site/config/config.php
// The custom variable types (SimpleStatsTimeFrameUtility, SimplestatsTrackingMode) are namespaced, you can shorten their invocations with the line below:
// use daandelange\SimpleStats\SimpleStatsTrackingMode;
require_once(__DIR__ . '/../plugins/simplestats/src/models/SimpleStatsTimeFrameUtility.php');
return [
// [...] your options ...
// Simplestats
'daandelange.simplestats.panel.enable' => false, // Disable the panel view completely
'daandelange.simplestats.tracking.enableReferers' => false, // Disable referer tracking
'daandelange.simplestats.tracking.timeFrameUtility' => new \daandelange\SimpleStats\SimpleStatsTimeFrameUtilityWeekly(), // Here you can put your custom inherited class from SimpleStatsTimeFrameUtility
'daandelange.simplestats.tracking.timeFrameUtility' => 'weekly', // Alternative
'daandelange.simplestats.tracking.method' => \daandelange\SimpleStats\SimpleStatsTrackingMode::OnImage,
];
Here’s a list with options that have been tested. (the daandelange.simplestats
part has been stripped)
You might also find some more detailed information in the comments of options.php
.
Option | Type | Default | Description | Comment | |
---|---|---|---|---|---|
TRACKING | |||||
tracking.timeFrameUtility |
String \ | SimpleStatsTimeFrameUtility | 'monthly' |
Set the class that handles time conversions to periods. (read note below!*) | Possible string values: monthly , weekly . |
tracking.enableReferers |
Bool | true | Enables tracking referrers. Gives an insight of who links to your website. | ||
tracking.enableDevices |
Bool | true | Enables tracking of minimal hardware configurations (device information) | ||
tracking.enableVisits |
Bool | true | Enables tracking page visits (frequentation) | ||
tracking.enableVisitLanguages |
Bool | true | Enables a counter per language per page. | Only effective in multi-language Kirby installations and enableVisits enabled. |
|
tracking.ignore.roles |
Array | ['admin'] |
Ignore any tracking for connected users with these roles. | ||
tracking.ignore.pages |
Array | [] |
Ignore tracking for these page ids. | Make sure to use the full id, not the slug. | |
tracking.ignore.templates |
Array | ['error'] |
Ignore tracking for pages with these templates. | Checked against template() and intendedTemplate() |
|
tracking.ignore.bots |
Bool | false | Ignore tracking any bots. | ||
tracking.ignore.botVisits |
Bool | true | Ignore counting bot page views. | ||
tracking.ignore.botReferers |
Bool | true | Ignore tracking referrers sent by bots. | ||
tracking.salt |
String | 'CHANGEME' |
A unique hash, used to generate a unique user id from visitor data. | Recommended to change, ensures that user identifying information is hard to retrieve if your database leaks. | |
tracking.anonimizeIpBits |
Number | 1 |
Anonymise the IP address of X bits. | Use 0 for no anonymisation, 4 for full anonymisation. |
|
tracking.method |
SimplestatsTrackingMode | onLoad |
Tracking mode. See SimplestatsTrackingMode for more information. |
onLoad is the only fully automatic mode, others need manual attention. |
|
PANEL | |||||
panel.dismissDisclaimer |
Bool | false | Dismisses the panel disclaimer message. | ||
panel.enable |
Bool | true | Enable/Disable viewing stats in the panel. | ||
panel.authorizedRoles |
Array | ['admin'] |
User roles that are allowed to view statistics from the panel. | ||
panel.breadcrumbLabel |
String | 'SimpleStats' |
Breadcrumb shown in the panel. | ||
panel.hideBots |
Bool | false | To hide bot information from the devices tab. |
timeFrameUtility
setting before the initialisation. If you’d like to change it afterwards, you’ll not be able to import the previously collected data. Changing timeFrameUtility
, you need to replace the database file with a new one (or manage to convert it).Before updating, make sure to backup your database file. If something goes wrong, you’ll be able to retrieve your stats by replacing the database file later.
Depending on the installation method you used, proceed to the logical steps to update.
After updating:
Information
tab and follow instructions in the upgrade section.SimpleStats::safeTrack($id)
track()
. $id
is a $page->id()
to be tracked.SimpleStats::track($id)
$id
is a $page->id()
to be tracked.$page->simpleStatsImage()
$page->getPageStats()
$user->hasSimpleStatsPanelAccess($forSpecialAdminAccess=false)
Charts are interactive, you can hover them to have details, and click labels to toggle filtering. You can even download timelines as PNGs.
Tables are interactive and paginated. You can search data within and sort them by clicking on the column headers.
Development was started from a standard Kirby PluginKit, see their plugin guide for more details on using it.
These steps are optional, for building development versions.
npm install -g parcel-bundler
cd /path/to/website/site/plugins/simplestats && npm install
npm run dev
npm run build
npm update
MIT - Free to use, free to improve.
Copyright 2020-2021 Daan de Lange