miniframe / statistics
Website statistics addon for the Miniframe PHP Framework.
Requires
- php: >=7.3
- ext-curl: *
- ext-sqlite3: *
- miniframe/core: ^1.0
Requires (Dev)
- geoip2/geoip2: ^2.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.4
- squizlabs/php_codesniffer: ^3.5
Suggests
- geoip2/geoip2: For converting IP to country codes
This package is auto-updated.
Last update: 2024-10-25 06:38:30 UTC
README
This package adds website statistics to the Miniframe PHP Framework.
How to use
- In your existing project, type:
composer require miniframe/statistics
- Add the directive below to your config.ini
- Run the task
php public/index.php _STATISTICS update
to update geoip and browscap databases - Visit
yourwebsite/_STATISTICS
for output
Example config.ini directives
[framework]
middleware[] = Miniframe\Statistics\Middleware\Statistics
[statistics]
browscap_database_path = cache/browscap
storage_path = cache/
It's recommended to run the update task on a regular base.
How to enable GeoIP (country lookup)
For GeoIP, I use a local database so the IP address is not shared with any 3rd party. To get this database, a few steps are required;
- Add in your configuration ini:
[statistics] geoip_database_path = cache/geoip
- Type
composer require geoip2/geoip2:~2.0
- Create an account at https://dev.maxmind.com/geoip/geolite2-free-geolocation-data
- When you have an account, create a new license key at https://www.maxmind.com/en/accounts/613599/license-key and check no for the update tool.
- Copy the
License Key
and put them in asecrets.ini
:[statistics] geoip_licensekey = ****************
It's also recommended to put the
secrets.ini
in your.gitignore
file so it won't end up in a git repository. - Run the task
php public/index.php _STATISTICS update
to update the geoip database.
You can also install a tool to automatically download the databases.
How to password protect your statistics
For password protection, you can use the Basic HTTP Authentication middleware. For more about that, see the middlewares documentation.
How to change the URL for statistics
You can modify the URL for the statistics page by altering the slug:
[statistics]
slug = stats
GDPR compliance
First, let me state this is not covered by a lawyer, no garantees here.
I wrote this library to try to be fully complaint with the GDPR.
As far as my knowledge goes, no personal data is stored.
I only store some global data like a country code, operating system and browser version, and don't even link between those data sets since there is no real need for that.
All data actually used can be seen in src/Model/PageHit.php
For Windows Developers
In the bin
folder, a few batch files exist, to make development easier.
If you install Docker Desktop for Windows, you can use bin\composer.bat, bin\phpcs.bat, bin\phpunit.bat, bin\phpstan.bat and bin\security-checker.bat as shortcuts for Composer, CodeSniffer, PHPUnit, PHPStan and the Security Checker, without the need of installing PHP and other dependencies on your machine.
The same Docker container and tools are used in Bitbucket Pipelines to automatically test this project.