# Laravel analytics

> Live analytics for Laravel apps: one composer require sends page views, your events, errors, sign-ins, failed jobs, response times and crawler visits, after the response has gone.

Source: https://mettr.app/integrations/laravel

## Three lines to install

mettr was built from dashboards that ran inside three Laravel sites, so Laravel is where it is most at home.

```bash
composer require mettr/laravel
```

```dotenv
METTR_SECRET_KEY=sk_...
METTR_PUBLIC_KEY=pk_...
```

```blade
<head>
    @mettr
</head>
```

It sends from production only, so local work and tests stay out of your numbers. PHP 8.3 or later, Laravel 12 or 13.

## What you get without writing code

- **Page views, navigation, outbound clicks and who is online**, from the browser script, loaded and sent through `/_live` on your own domain, so ad blockers mostly leave it alone and each event carries the signed-in user.
- **Sign-ins and sign-ups**, from Laravel's own `Login` and `Registered` events.
- **404s and exceptions**, by class, never the message: a wave of 404s after a deploy shows up next to the deploy.
- **Failed queue jobs**, with the job, the queue and the exception's class.
- **Response times** of a sample of requests, for the slowest routes.
- **Crawler visits**: Googlebot, Bingbot, GPTBot, ClaudeBot and the rest, named, checked against their owners' networks where that can be done, kept apart from your visitors.

## Your own events, in one line

```php
use Mettr\Laravel\Facades\Mettr;

Mettr::event('upgrade', ['plan' => 'pro', 'seats' => 5]);
```

Events are batched and sent after the response has gone, so a visitor never waits on mettr. In queue workers and console commands they go when the job or command ends; or send them through a queue of your own with `METTR_QUEUE`.

## Leave your team out

Name a gate, and nothing is sent for the people it allows:

```php
Gate::define('mettr-staff', fn (User $user): bool => $user->is_admin);
```

## Bring your history

Already logging with `spatie/laravel-activitylog`? One command sends your history, a thousand rows a batch, each with its own id so a second run adds nothing twice:

```bash
php artisan mettr:import-activity-log --dry-run
```

## Revenue from your own billing

Billing with Cashier or code of your own? Send each subscription as it changes, and MRR, churn and revenue by source follow:

```php
Mettr::subscription(id: (string) $subscription->id, status: 'active', amount: 19.00, currency: 'USD', userId: (string) $user->id);
```

## Open source

`mettr/laravel` is MIT licensed, on [GitHub](https://github.com/mettrhq/mettr-laravel) and Packagist. Read exactly what it sends: messages of exceptions, request bodies and headers other than the user agent never leave your server. [The full guide](/docs/laravel).
