promatur/sc-analytics

A combination of clientside and serverside analytics for PHP-based websites.

Fund package maintenance!
Paypal

v1.1.5 2024-02-29 22:21 UTC

This package is auto-updated.

Last update: 2024-04-30 18:48:45 UTC


README

Latest Stable Version Latest Unstable Version Total Downloads License

Code Status

PHPUnit PHPStan Average time to resolve an issue Percentage of issues still open

Description

SC-Analytics Logo

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!