PHPackages                             tasmir/activity-tracker - 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. tasmir/activity-tracker

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

tasmir/activity-tracker
=======================

User Activity Tracker for Laravel

v1.0.0(4mo ago)00MITPHPPHP ^8.2

Since Feb 16Pushed 2mo agoCompare

[ Source](https://github.com/tasmir/activity-tracker)[ Packagist](https://packagist.org/packages/tasmir/activity-tracker)[ RSS](/packages/tasmir-activity-tracker/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

Activity Tracker for Laravel
============================

[](#activity-tracker-for-laravel)

A powerful, standalone Laravel package to automatically track and log user activities, model changes, and authentication events. This package simplifies audit logging and activity tracking with minimal configuration.

Features
--------

[](#features)

- **Model Tracking**: Automatically log `created`, `updated`, `deleted`, `restored`, and `forceDeleted` events for any Eloquent model.
- **Authentication Logging**: Automated logging for user `login` and `logout` events.
- **Artisan Generator**: A robust `php artisan track:model ` command with automatic model inference and naming logic.
- **Tracker Discovery**: A `php artisan track:list` command to view all tracked models and their events.
- **Bulk Tracking**: A `php artisan track:all` command to automatically generate trackers for all untracked models.
- **Track Removal**: A `php artisan track:remove ` command to easily delete trackers and clean up models.
- **Auto-Tracking**: Automatically generates trackers when new models are created via `php artisan make:model`.
- **URL Visit Tracking**: Middleware to automatically log URLs visited by authenticated users.
- **Service Layer**: A ready-to-use `UserActivityService` for manual logging or custom implementations.
- **Activity Links**: Built-in support for model relationships and easy activity retrieval.
- **Developer Friendly**: Highly customizable stubs and easy registration via service providers.

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

[](#installation)

You can install the package via composer:

```
composer require tasmir/activity-tracker
```

The package will automatically register itself. To create the necessary database table, run the migrations:

```
php artisan migrate
```

### Configuration (Optional)

[](#configuration-optional)

You can publish the configuration file to customize the package behavior (e.g., disabling auto-tracking):

```
php artisan vendor:publish --tag="activity-tracker-config"
```

Basic Usage
-----------

[](#basic-usage)

### 1. Generating a Tracker

[](#1-generating-a-tracker)

The easiest way to track a model (e.g., `User`) is to use the generator command:

```
php artisan track:model User
```

This command will:

- Create `app/ModelTracker/UserTracker.php`.
- Automatically add the `#[ObservedBy([UserTracker::class])]` attribute to your `User` model.
- Update your `User` model with necessary `use` statements and relationships.

### 2. Manual Logging

[](#2-manual-logging)

You can inject the `UserActivityService` into your controllers or jobs for manual logging:

```
use Tasmir\ActivityTracker\Services\UserActivityService;

public function update(Request $request, Profile $profile, UserActivityService $service)
{
    $profile->update($request->all());

    $service->store(
        $profile,         // The model instance
        Profile::class,   // Model class name
        'profile_update', // Action name
        'User updated their profile information' // Description
    );
}
```

### 3. Authentication Events

[](#3-authentication-events)

The package automatically listens for Laravel's built-in authentication events. No extra setup is required to log:

- **Login**: `Illuminate\Auth\Events\Login`
- **Logout**: `Illuminate\Auth\Events\Logout`

Management Commands
-------------------

[](#management-commands)

### List Tracked Models

[](#list-tracked-models)

To see all models currently being tracked and the events they handle:

```
php artisan track:list
```

### Bulk Track All Models

[](#bulk-track-all-models)

To automatically generate tracker classes for every model in your `app/Models` directory that isn't already tracked:

```
php artisan track:all
```

### Remove Tracking

[](#remove-tracking)

To delete a tracker from a model:

```
php artisan track:remove User
```

Auto-Tracking
-------------

[](#auto-tracking)

By default, the package listens for the `make:model` command. When you create a new model, it will automatically trigger the generation of a corresponding tracker:

```
php artisan make:model Product
# Automatically triggers: php artisan track:model Product
```

You can disable this in the `config/activity-tracker.php` file by setting `auto_track_models` to `false`.

### 2. Authentication Events

[](#2-authentication-events)

User Login and Logout events are tracked by default. You can also toggle the tracking of login and logout events in the configuration:

```
'track_login' => true,
'track_logout' => true,
```

### 3. URL Visit Tracking

[](#3-url-visit-tracking)

To track pages visited by authenticated users, you can enable URL tracking and register the middleware in your application.

#### Configuration

[](#configuration)

In `config/activity-tracker.php`:

```
'track_url_visits' => true,
```

#### Middleware Registration (Laravel 12+)

[](#middleware-registration-laravel-12)

In `bootstrap/app.php`, register the middleware:

```
use Tasmir\ActivityTracker\Http\Middleware\TrackUrlVisit;

->withMiddleware(function (Middleware $middleware) {
    $middleware->append(TrackUrlVisit::class);
})
```

### 4. Detailed URL Visit Tracking

[](#4-detailed-url-visit-tracking)

For deep analytics, you can enable detailed tracking which captures location data (City, Country), IP, User Agent, Referer, Query Params, and request duration.

#### Configuration

[](#configuration-1)

In `config/activity-tracker.php`:

```
'detailed_url_tracking' => [
    'enabled' => true,
],
```

#### Middleware Registration (Laravel 12+)

[](#middleware-registration-laravel-12-1)

In `bootstrap/app.php`:

```
use Tasmir\ActivityTracker\Http\Middleware\TrackDetailedUrlVisit;

->withMiddleware(function (Middleware $middleware) {
    $middleware->append(TrackDetailedUrlVisit::class);
})
```

#### Database Table

[](#database-table)

This feature uses the `url_visits` table. Make sure to run the migrations:

```
php artisan migrate
```

Activity Log Cleanup
--------------------

[](#activity-log-cleanup)

The package includes an automated scheduler to clean up old activity logs.

### Configuration

[](#configuration-2)

In `config/activity-tracker.php`:

```
'log_cleanup' => [
    'enabled' => true,
    'retention_days' => 30,
    'schedule' => 'daily', // Options: daily, weekly, monthly
],
```

### Manual Cleanup

[](#manual-cleanup)

You can also manually cleanup logs using the command:

```
php artisan track:cleanup --days=15
```

Activity Log Data
-----------------

[](#activity-log-data)

The `user_activities` table stores the following information:

KeyTypeDescription`user_id``bigint`The ID of the user performing the action.`model_id``bigint`The ID of the model being affected.`model_type``string`The class name of the model being affected.`action``string`The action performed (e.g., `created`, `login`).`description``text`A human-readable description of the activity.`previous_data``json`(Optional) Model state before the change.`new_data``json`(Optional) Model state after the change.Relationships
-------------

[](#relationships)

If you want to access a user's activity logs, the `track:model` command automatically adds a relationship to the `User` model. You can access it like this:

```
$user = User::find(1);
$logs = $user->activities; // Returns a collection of UserActivity models
```

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

[](#contributing)

Contributions are welcome! If you have any ideas, bug fixes, or improvements, feel free to open an issue or submit a pull request on [GitHub](https://github.com/tasmir/activity-tracker).

---

Developed by [Tasmir](https://github.com/tasmir)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance80

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

138d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/67b661104aac762e04093995cba4c76ef5749be1d336d7150d8c4a8e526174bb?d=identicon)[tasmir](/maintainers/tasmir)

---

Top Contributors

[![tasmir](https://avatars.githubusercontent.com/u/25658870?v=4)](https://github.com/tasmir "tasmir (2 commits)")

### Embed Badge

![Health badge](/badges/tasmir-activity-tracker/health.svg)

```
[![Health](https://phpackages.com/badges/tasmir-activity-tracker/health.svg)](https://phpackages.com/packages/tasmir-activity-tracker)
```

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

592.7k1](/packages/crumbls-layup)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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