promatur / sc-analytics
A combination of clientside and serverside analytics for PHP-based websites.
Fund package maintenance!
Paypal
Requires
- php: ^7.3|^8.0
- ext-curl: *
- ext-json: *
- frontpack/composer-assets-plugin: ^0.11.0
- moneyphp/money: ^3.3
Requires (Dev)
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9
- roave/security-advisories: dev-master
- sentry/sdk: ^3.1
Suggests
- sentry/sdk: Error handling
README
Code Status
Description
A combination of clientside and serverside analytics for PHP-based websites. This repository builds upon existing
analytics solutions and offers integrations for Matomo
and Google Analytics.
Tested using PHP 7.3
, 7.4
and 8.1
.
⠀
⠀
⠀
Usage
It is recommended to use SC-Analytics with composer, which is the easiest way to use it. Just add promatur/sc-analytics
to your projects requirements.
composer require promatur/sc-analytics
Use some code like this one:
require_once 'vendor/autoload.php'; // - Configure your preferred analytics endpoint \ScAnalytics\Core\AnalyticsConfig::$matomoID = "1"; \ScAnalytics\Core\AnalyticsConfig::$matomoEndpoint = "https://analytics.example.com/"; // - Initialize the analytics system \ScAnalytics\Analytics::init(); // - Get your Analytics Handler $analytics = Analytics::get(); // - Load the Client-Side JavaScript code and initialize the page view $pageData = new \ScAnalytics\Core\PageData("Help Page", ["Support", "Help Page Overview"]) // Put this anywhere you want to load the JavaScript code echo $analytics->loadJS($pageData);
Learn more in the Wiki.
Assets
SC-Analytics also provides JavaScript assets. If you want the combination of server-side and client-side analytics,
configure the location of the assets in your composer.json
:
{ "extra": { "assets-dir": "assets", "assets-strategy": "copy" } }
If you want to use another folder for the assets, configure it in the config:
\ScAnalytics\Core\AnalyticsConfig::$assets = "my-directory";
Learn more about the Composer Assets Plugin.
Error handling
This package has an integration of Sentry, which is optional to use. Errors are automatically handled by Sentry and additional information is added.
Contributing
Using the library
This is a free/libre library under license LGPL v3 or later.
Your pull requests and/or feedback is very welcome!
Contributors
Created by Jan-Nicklas Adler.
I am looking forward to your contributions and pull requests!