PHPackages                             webudvikleren/laravel-utm-manager - 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. webudvikleren/laravel-utm-manager

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

webudvikleren/laravel-utm-manager
=================================

A simple Laravel package to capture and manage UTM parameters.

v0.0.11(5mo ago)0696↓33.3%MITPHPPHP ^8.0

Since May 6Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/Webudvikleren/laravel-utm-manager)[ Packagist](https://packagist.org/packages/webudvikleren/laravel-utm-manager)[ RSS](/packages/webudvikleren-laravel-utm-manager/feed)WikiDiscussions main Synced 1mo ago

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

Laravel UTM Manager
===================

[](#laravel-utm-manager)

📈 Simple UTM tracking middleware for Laravel. Capture UTM parameters from the URL and make them easily accessible via session or helper methods. Great for tracking marketing sources across forms, registrations, or orders.

---

✨ Features
----------

[](#-features)

- Middleware to automatically store UTM parameters
- Configurable list of UTM keys
- Store in session (default) or extend for other storage
- Facade for easy access: `Utm::get('utm_source')`
- Trait for auto-filling UTM data directly on Eloquent models
- Trait for attaching UTM data to a related model (`utmVisit`)
- Artisan command to generate a migration dynamically

---

🔧 Installation
--------------

[](#-installation)

```
composer require webudvikleren/laravel-utm-manager
```

### Publish the config file:

[](#publish-the-config-file)

```
php artisan vendor:publish --tag=config --provider="Webudvikleren\UtmManager\UtmManagerServiceProvider"
```

🚀 Usage
-------

[](#-usage)

### 1. Add middleware

[](#1-add-middleware)

You can register the middleware globally or per route:

```
// app/Http/Kernel.php
protected $middleware = [
    // ...
    \Webudvikleren\UtmManager\Http\Middleware\CaptureUtmParameters::class,
];
```

Or assign it to specific routes:

```
Route::middleware(['utm.capture'])->group(function () {
    Route::get('/register', [RegisterController::class, 'show']);
});
```

### 2. Access UTM data

[](#2-access-utm-data)

Use the facade to get stored UTM parameters:

```
use Utm;

Utm::get('utm_source'); // e.g., 'facebook'
Utm::all(); // returns all captured UTM data as array
```

### 3. Automatically attach UTM data to Eloquent models

[](#3-automatically-attach-utm-data-to-eloquent-models)

Add the HasUtmData trait to your model:

```
use Webudvikleren\UtmManager\Traits\HasUtmData;

class Lead extends Model
{
    use HasUtmData;

    protected $fillable = [
        'name', 'email',
        'utm_source', 'utm_medium', 'utm_campaign',
    ];
}
```

When creating the model, UTM fields will be auto-filled (if present in the session).

### 4. Store UTM data in a related model

[](#4-store-utm-data-in-a-related-model)

If you want to store UTM data in a separate model (e.g., `utm_visits`), use the `HasUtmRelation` trait:

```
use Webudvikleren\UtmManager\Traits\HasUtmRelation;

class User extends Model
{
    use HasUtmRelation;

    public function utmVisit()
    {
        return $this->hasOne(\App\Models\UtmVisit::class);
    }
}
```

Then define the related model like this:

```
class UtmVisit extends Model
{
    protected $table = 'utm_visits'; // or load from config('utm.table')

    protected $fillable = [
        'utm_source',
        'utm_medium',
        'utm_campaign',
        'utm_term',
        'utm_content',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
```

The related model class and table name are both configurable via `config/utm.php`.

### 5. Generate a migration for related UTM data

[](#5-generate-a-migration-for-related-utm-data)

The package includes an Artisan command to generate a migration based on the configured UTM keys and table name.

```
php artisan utm:make-migration
php artisan migrate
```

This will generate a migration with the correct user\_id foreign key and all defined UTM columns.

### 6. Publish the default UtmVisit model

[](#6-publish-the-default-utmvisit-model)

To create a prebuilt `UtmVisit` model in your `app/Models` folder:

```
php artisan utm:publish-model
```

You can then customize the model or change the class in `config/utm.php`.

⚙️ Configuration
----------------

[](#️-configuration)

```
// config/utm.php

return [

    // Where to store UTM data: 'session' (default)
    'storage' => 'session',

    // Which UTM keys to track
    'utm_keys' => [
        'utm_source',
        'utm_medium',
        'utm_campaign',
        'utm_term',
        'utm_content',
    ],

    // Table name for storing UTM visits (if using HasUtmRelation)
    'table' => 'utm_visits',

    // Fully qualified class name for related UTM model
    'related_model' => \App\Models\UtmVisit::class,
];
```

📦 Example URL
-------------

[](#-example-url)

Send traffic with UTM parameters to your app:

> [https://yourapp.com/register?utm\_source=facebook&amp;utm\_medium=social&amp;utm\_campaign=summer-sale](https://yourapp.com/register?utm_source=facebook&utm_medium=social&utm_campaign=summer-sale)

The package will capture and store these in the user's session.

✅ Roadmap Ideas
---------------

[](#-roadmap-ideas)

- Cookie support
- Database logging
- Integration with Laravel Nova or Horizon
- Debug toolbar for current UTM state

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance77

Regular maintenance activity

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Every ~21 days

Recently: every ~51 days

Total

11

Last Release

157d ago

### Community

Maintainers

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

---

Top Contributors

[![philipsorensen](https://avatars.githubusercontent.com/u/5397535?v=4)](https://github.com/philipsorensen "philipsorensen (15 commits)")

### Embed Badge

![Health badge](/badges/webudvikleren-laravel-utm-manager/health.svg)

```
[![Health](https://phpackages.com/badges/webudvikleren-laravel-utm-manager/health.svg)](https://phpackages.com/packages/webudvikleren-laravel-utm-manager)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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