PHPackages                             suarez/laravel-utm-parameter - 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. suarez/laravel-utm-parameter

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

suarez/laravel-utm-parameter
============================

A little helper to store and handle utm-parameter

12.0.0(1y ago)1513.8k↓15.7%3MITPHPPHP ^8.2CI passing

Since Jan 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/toni-suarez/laravel-utm-parameter)[ Packagist](https://packagist.org/packages/suarez/laravel-utm-parameter)[ Docs](https://github.com/toni-suarez/laravel-utm-parameter)[ GitHub Sponsors](https://github.com/toni-suarez)[ RSS](/packages/suarez-laravel-utm-parameter/feed)WikiDiscussions 12.x Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (29)Used By (0)

Laravel UTM-Parameters
======================

[](#laravel-utm-parameters)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5d5170e691e10d85588e4b8de5ec96c95b5659e9a98e415cdb2677a8038f4433/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73756172657a2f6c61726176656c2d75746d2d706172616d657465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/suarez/laravel-utm-parameter)[![StyleCI](https://camo.githubusercontent.com/c194278576882629631059395104cc44f523765e9ccdf7269b71dbbd909a3b32/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3434383334373137382f736869656c643f6272616e63683d6d61696e)](https://github.styleci.io/repos/448347178?branch=main)[![Test PHP 8.x](https://github.com/toni-suarez/laravel-utm-parameter/actions/workflows/tests-php8.yml/badge.svg?branch=main)](https://github.com/toni-suarez/laravel-utm-parameter/actions/workflows/tests-php8.yml)[![Packagist Downloads](https://camo.githubusercontent.com/74da1c88744674782e40af2626594cf0913b223d5500baf2b2dae9853967f475/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73756172657a2f6c61726176656c2d75746d2d706172616d65746572)](https://packagist.org/packages/suarez/laravel-utm-parameter)[![GitHub](https://camo.githubusercontent.com/34263a7a2f75f2f9992d62d53de330d0e2830bf806a5d549b334a78ab2321e5a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746f6e692d73756172657a2f6c61726176656c2d75746d2d706172616d65746572)](https://camo.githubusercontent.com/34263a7a2f75f2f9992d62d53de330d0e2830bf806a5d549b334a78ab2321e5a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f746f6e692d73756172657a2f6c61726176656c2d75746d2d706172616d65746572)[![Statamic Addon](https://camo.githubusercontent.com/fd3c994644541d8d3927f412e74a2972abacf09b38bab4c5710bb80d31923ea7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f687474707325334125324625324673746174616d69632e636f6d2532466164646f6e73253246746f6e692d73756172657a25324675746d2d706172616d657465723f7374796c653d666c61742d737175617265266c6f676f3d73746174616d6963266c6f676f436f6c6f723d72676228323535253243253230333825324325323031353829266c6162656c3d53746174616d6963266c696e6b3d687474707325334125324625324673746174616d69632e636f6d2532466164646f6e73253246746f6e692d73756172657a25324675746d2d706172616d65746572)](https://statamic.com/addons/toni-suarez/utm-parameter)

A lightweight way to handle UTM parameters session-based in your Laravel Application.

```
@hasUtm('source', 'newsletter')
  Special Content for Newsletter-Subscriber.
@endhasUtm
```

---

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

[](#installation)

Follow these steps to install the Laravel UTM-Parameters package. [Guide for Laravel 10 and below.](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Installation-Guide-(Laravel-8.x-to-10.x))

Open your terminal and navigate to your Laravel project directory. Then, use Composer to install the package:

```
$ composer require suarez/laravel-utm-parameter
```

Optionally, you can publish the config file of this package with this command:

```
php artisan vendor:publish --tag="utm-parameter"
```

### Middleware Configuration

[](#middleware-configuration)

Once the package is installed, you can add the UtmParameters middleware to your Laravel application. Open the `bootstrap/app.php` file and append the `UtmParameters::class` inside the web-group.

```
# Laravel 11+
return Application::configure(basePath: dirname(__DIR__))
  ...
  ->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
      Suarez\UtmParameter\Middleware\UtmParameters::class,
      /* ... keep the existing middleware here */
    ]);
  })
  ...
```

Also, take a look at how to set an [alias for the middleware](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Installation-Guide#step-3-alias-configuration-optional).

### Use as Facade

[](#use-as-facade)

If you prefer not to use it as middleware, you can utilize the UtmParameter Facade directly in your controllers or other parts of your application. Once the `boot($request)`-method is called, you have access to it at any place. For example:

```
use Suarez\UtmParameter\Facades\UtmParameter;

// Inside a controller method
class IndexController {
  public function index(Request $request)
  {
      UtmParameter::boot($request);
  }
}

class SomeDifferentController {
  public function index(Request $request)
  {
      $source = UtmParameter::get('source');
  }
}
```

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

[](#configuration)

The configuration file `config/utm-parameter.php` allows you to control the behavior of the UTM parameters handling.

```
