PHPackages                             andreaselia/analytics - 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. [Admin Panels](/categories/admin)
4. /
5. andreaselia/analytics

ActiveLibrary[Admin Panels](/categories/admin)

andreaselia/analytics
=====================

Analytics for the Laravel framework.

v2.4.0(1y ago)19719.5k↓16.7%27[1 issues](https://github.com/andreaselia/laravel-analytics/issues)2MITPHPPHP ^7.4|^8.0CI failing

Since Jan 9Pushed 1y ago7 watchersCompare

[ Source](https://github.com/andreaselia/laravel-analytics)[ Packagist](https://packagist.org/packages/andreaselia/analytics)[ GitHub Sponsors](https://github.com/andreaselia)[ RSS](/packages/andreaselia-analytics/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (34)Used By (2)

Laravel Analytics
=================

[](#laravel-analytics)

[![Latest Stable Version](https://camo.githubusercontent.com/e5fdda6b22905903867d317dd69db1f68c5fddb3af8c2be1e7e89d1dff08593e/68747470733a2f2f706f7365722e707567782e6f72672f616e6472656173656c69612f616e616c79746963732f76)](//packagist.org/packages/andreaselia/analytics)

Easily collect page view analytics with a beautifully simple to use dashboard.

[![Laravel Analytics Dashboard](/screenshot.png?raw=true "Laravel Analytics Dashboard")](/screenshot.png?raw=true)

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

[](#installation)

Install the package:

```
composer require andreaselia/analytics
```

Publish the config file and assets:

```
php artisan vendor:publish --provider="AndreasElia\Analytics\AnalyticsServiceProvider"
```

Don't forget to run the migrations:

```
php artisan migrate
```

You can add the page view middleware to a specific route group, e.g. `web.php` like so:

```
Route::middleware('analytics')->group(function () {
    // ...
});
```

Or add the page view to all middlewares/on an application level like so:

```
// app/Http/Kernel.php

protected $middleware = [
    // ...
    \AndreasElia\Analytics\Http\Middleware\Analytics::class,
];
```

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

[](#configuration)

### Disabling tracking

[](#disabling-tracking)

You can disable tracking by setting the environment variable `ANALYTICS_ENABLED` or the `enabled` property in the `analytics.php` config file to `false`.

### Excluding routes

[](#excluding-routes)

You can exclude certain routes from being tracked by adding them to the `exclude` array in the `analytics.php` config file.

### Ignore robots

[](#ignore-robots)

You can ignore requests from robots by setting the `ignoreRobots` property in the `analytics.php` config file.

### Ignore specific IP addresses

[](#ignore-specific-ip-addresses)

You can ignore requests from specific IP addresses by adding them to the `ignoreIps` array in the `analytics.php` config file.

### Masking routes

[](#masking-routes)

You can mask certain routes from being tracked by adding them to the `mask` array in the `analytics.php` config file. This is useful if you want to track the same route with different parameters, e.g. `/users/1` and `/users/2` will be tracked as `/users/∗︎`.

### Ignoring certain HTTP verbs/methods

[](#ignoring-certain-http-verbsmethods)

You can ignore the tracking of some methods by adding them to the `analytics.ignoreMethods` config option. For example, if you don't want to track `POST` requests, you can configure it like so:

```
'ignoreMethods' => [
    'POST',
],
```

### Changing how session\_id is determined

[](#changing-how-session_id-is-determined)

By default, `session_id` in the `page_views` table is filled with the session ID of the current request. However, in certain scenarios (for example, for API and other requests not using cookies), the session is unavailable.

In these cases, you can create a custom session ID provider: create a class that implements the `AndreasElia\Analytics\Contracts\SessionProvider` interface and set its name as the `provider` option in the `analytics.php` config file. The configured class object is resolved from the container, therefore, dependency injection can be used via the `__constructor`.

One example of a custom way to generate the session ID in cookie-less environment is to hash IP address + User Agent + some other headers from the request.

Feel free to take a look at `AndreasElia\Analytics\RequestSessionProvider` for an example of implementing the `SessionProvider` interface.

### Changing how the timezone for "today" and "yesterday" is determined

[](#changing-how-the-timezone-for-today-and-yesterday-is-determined)

Since timestamps are stored using your application's timezone, you may get mixed results depending on when you check views for "today" and "yesterday" and your actual timezone. You can change the relative time for whatever "now" is by setting a callback in a service provider.

```
use AndreasElia\Analytics\Models\PageView;

public function boot()
{
    PageView::resolveTimezoneUsing(function () {
        return request()->user()?->timezone;
    });
}
```

You can return a dynamic value like the example above, or a static value. If one isn't determined, it will just fall back to the `config('app.timezone')` value.

Laravel Nova
------------

[](#laravel-nova)

The package comes with a dashboard and metrics for Laravel Nova.

### Dashboard

[](#dashboard)

You can add the dashboard to Laravel Nova by adding `new \AndreasElia\Analytics\Nova\Dashboards\Analytics` to `dashboards` array in your `NovaServiceProvider`:

```
    protected function dashboards(): array
    {
        return [
            new \AndreasElia\Analytics\Nova\Dashboards\Analytics,
        ];
    }
```

### Metrics

[](#metrics)

Alternatively, you can add the metrics to your own Laravel Nova dashboard by adding them to the `cards` array in your dashboard file.

```
    protected function cards(): array
    {
        return [
            new \AndreasElia\Analytics\Nova\Metrics\Devices,
            new \AndreasElia\Analytics\Nova\Metrics\PageViews,
            new \AndreasElia\Analytics\Nova\Metrics\UniqueUsers,
        ];
    }
```

Contributing
------------

[](#contributing)

You're more than welcome to submit a pull request, or if you're not feeling up to it - create an issue so someone else can pick it up.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance44

Moderate activity, may be stable

Popularity45

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 65% of commits — single point of failure

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 ~47 days

Recently: every ~83 days

Total

33

Last Release

442d ago

Major Versions

v1.17.0 → v2.0.02024-04-01

PHP version history (2 changes)v1.0.0PHP ^7.4|^8.0

v2.0.0PHP ^8.0

### Community

Maintainers

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

---

Top Contributors

[![andreaselia](https://avatars.githubusercontent.com/u/5033092?v=4)](https://github.com/andreaselia "andreaselia (119 commits)")[![grantholle](https://avatars.githubusercontent.com/u/1189456?v=4)](https://github.com/grantholle "grantholle (23 commits)")[![tomirons](https://avatars.githubusercontent.com/u/5089787?v=4)](https://github.com/tomirons "tomirons (22 commits)")[![Umfi](https://avatars.githubusercontent.com/u/13978552?v=4)](https://github.com/Umfi "Umfi (5 commits)")[![sinnbeck](https://avatars.githubusercontent.com/u/13980140?v=4)](https://github.com/sinnbeck "sinnbeck (5 commits)")[![myneid](https://avatars.githubusercontent.com/u/28316?v=4)](https://github.com/myneid "myneid (2 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (2 commits)")[![imanghafoori1](https://avatars.githubusercontent.com/u/6961695?v=4)](https://github.com/imanghafoori1 "imanghafoori1 (2 commits)")[![muhammadmp97](https://avatars.githubusercontent.com/u/17279395?v=4)](https://github.com/muhammadmp97 "muhammadmp97 (1 commits)")[![GlitterCakes](https://avatars.githubusercontent.com/u/5402396?v=4)](https://github.com/GlitterCakes "GlitterCakes (1 commits)")[![justrau](https://avatars.githubusercontent.com/u/10882793?v=4)](https://github.com/justrau "justrau (1 commits)")

---

Tags

analyticsdashboardlaravellaravel-analyticsmiddlewarepackagephpself-hostedmiddlewarelaravelpackageanalytics

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andreaselia-analytics/health.svg)

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

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[masterro/laravel-mail-viewer

Easily view in browser outgoing emails.

6392.1k](/packages/masterro-laravel-mail-viewer)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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