PHPackages                             code16/metrics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. code16/metrics

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

code16/metrics
==============

Metrics Package for Laravel

v1.5.4(2y ago)65.7k[1 issues](https://github.com/code16/metrics/issues)[1 PRs](https://github.com/code16/metrics/pulls)MITPHPPHP ^8.2|^8.3

Since Mar 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/code16/metrics)[ Packagist](https://packagist.org/packages/code16/metrics)[ Docs](https://code16.fr)[ RSS](/packages/code16-metrics/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (5)Dependencies (9)Versions (44)Used By (0)

Metrics
=======

[](#metrics)

[![Latest Stable Version](https://camo.githubusercontent.com/01b8a886279541e382ebcaebb036b6bb011d848c42353074dfe9e170ca517280/68747470733a2f2f706f7365722e707567782e6f72672f636f646531362f6d6574726963732f762f737461626c65)](https://packagist.org/packages/code16/metrics)[![Total Downloads](https://camo.githubusercontent.com/da1456dc500e9fee86fea4918646c3c093b6a1257382b2b1befc94608d0f22bd/68747470733a2f2f706f7365722e707567782e6f72672f636f646531362f6d6574726963732f646f776e6c6f616473)](https://packagist.org/packages/code16/metrics)[![License](https://camo.githubusercontent.com/666242eeca19f0e3d5eeeab08a9779252d8b46baeebc38d29a9accdfe1024b4d/68747470733a2f2f706f7365722e707567782e6f72672f636f646531362f6d6574726963732f6c6963656e7365)](https://packagist.org/packages/code16/metrics)[![Build](https://camo.githubusercontent.com/dadead2a9c74bdbc4d1b7012f6b83d2fa8b2bd3cea6717f53b05494231d9c16f/68747470733a2f2f7472617669732d63692e6f72672f636f646531362f6d6574726963732e7376673f6272616e63683d6d6173746572)](https://packagist.org/packages/code16/metrics)

Metrics is a Laravel 5 package aimed at logging visitor's usage of your web application and provides an ensemble of classes and functionnality to help you generate statistics out of it.

It is compliant with `EU` regulations regarding privacy, and `GDPR-Ready`.

Installation
------------

[](#installation)

You can install the metrics package by typing the following command :

```
    composer require dvlpp/metrics:dev-master

```

Configuration
-------------

[](#configuration)

THe package ships with a set of ready-to-user `Analyzers` that are included in default's config file. If you want to customize it, just publish using the appropriate artisan command :

```
php artisan vendor:publish --provider="Code16\Metrics\MetricServiceProvider" --tag="config"

```

Tracking
--------

[](#tracking)

`Metrics`works by placing a tracking cookie on the user's device, which will be linked to a specific user\_id when a user is logged in, so there will be a unique identifier for a single user, whichever device he's using, and the cookie will stay on after a user has logged out, meaning that you can reconstruct a user's sequence before, or after he was logged into the application.

By default, `Metrics` will log any route accessed within the application, with the exception of when the user has a `Do Not Track` header set to true. If you do not wish a specific route or group of route to be logged, you can use the included `NoTrackingMiddleware`, or add a filter in config.

Actions
-------

[](#actions)

`Actions` are an important concept in `Metrics`. They give you the opportunity to highlight and gather data for further statistic analyzis on some important part of your application. They are very similar to events in how they work, and they are serialized in the `metrics_visits`table.

For example, you can create an action class for everytime a user add a product to his cart :

```
    use App\Product;
    use Code16\Metrics\Action;

    class AddToCart extends Action {

        public $productId;

        public function __construct(Product $product)
        {
            $this->productId = $product;
        }

    }

```

Then, you can attach the action to the current Visit object, by calling the following method on the manager class :

```
    app(Dvlpp\Metrics\Manager::class)->addAction(new AddToCart($product));

```

Alternatively, you can use the helper function :

```
    metrics_action(new AddTOCart($product))

```

Analyzers &amp; Consoliders
---------------------------

[](#analyzers--consoliders)

On top of logging your user's visits into a table, `Metrics` comes with a little "framework" which aims to help you extract statistics from these raw informations. It come out of the box with some basic statistics functions that will for example count the number of unique visitors or analysis the repartition of your users by browser or user agent.

There are two distinct operations that `Metrics` handles :

`Analyze` : This operation will produce a statistic array from raw `Visit` records. Basically metrics passes all rows from the `metrics_visit` table and listen and store statistics data that is calculated from these raw visit log.

`Consolidate` : This operation takes several results from several smaller time periods into a larger one.

Raw data are analyzed and consolidated into four incremental time periods :

- Hour
- Day
- Month
- Year

For some example on how to write custom analyzers/consoliders for your application, you can look into the classes which are included in the package (Code16\\Metrics\\Analyzers).

Updating statistics
-------------------

[](#updating-statistics)

To calculate and update the statistics, simply run `artisan metrics:update` at any time. Doing so will calculate statistics for all complete period (last hour, last day, last month..), that haven't been calculated yet. TIP : If you implement new `Analyzers` during the application lifetime, and you want to calculate statistics on previous period, simply truncate `metric_metrics` table and run another update.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~92 days

Total

36

Last Release

752d ago

PHP version history (6 changes)v1.0.10PHP &gt;=7.1.3

v1.2.0PHP &gt;=7.2.5

v1.4.0PHP ^7.2.5|^8.0

v1.5.0PHP ^7.2.5|^8.0|^8.1|^8.2

v1.5.2PHP ^7.2.5|^8.0|^8.1|^8.2|^8.3

v1.5.4PHP ^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/f97dcdc942d25d5b5720b790d5f28e6accc6f05370cf5a6b52b78abc60c29e57?d=identicon)[code16](/maintainers/code16)

---

Top Contributors

[![smknstd](https://avatars.githubusercontent.com/u/2412608?v=4)](https://github.com/smknstd "smknstd (30 commits)")[![RemiCollin](https://avatars.githubusercontent.com/u/9589616?v=4)](https://github.com/RemiCollin "RemiCollin (25 commits)")[![dvlpp](https://avatars.githubusercontent.com/u/973325?v=4)](https://github.com/dvlpp "dvlpp (18 commits)")

---

Tags

laravelMetricsanalytics

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/code16-metrics/health.svg)

```
[![Health](https://phpackages.com/badges/code16-metrics/health.svg)](https://phpackages.com/packages/code16-metrics)
```

###  Alternatives

[bezhansalleh/filament-google-analytics

Google Analytics integration for FilamentPHP

205144.8k5](/packages/bezhansalleh-filament-google-analytics)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[ohseesoftware/laravel-server-analytics

Server side analytics for your Laravel application or website.

1421.2k1](/packages/ohseesoftware-laravel-server-analytics)[cornford/googlitics

An easy way to integrate Google Analytics with Laravel.

3310.2k](/packages/cornford-googlitics)[panakour/analytics

Get whatever data you want from google analytics.

267.6k](/packages/panakour-analytics)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
