PHPackages                             devlop/utm-parameters - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. devlop/utm-parameters

ActiveLibrary[HTTP &amp; Networking](/categories/http)

devlop/utm-parameters
=====================

Framework agnostic UTM parameters helper

1.5.2(3y ago)02441MITPHPPHP ^7.4|^8.0

Since Feb 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/devlop/utm-parameters)[ Packagist](https://packagist.org/packages/devlop/utm-parameters)[ RSS](/packages/devlop-utm-parameters/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (11)Used By (0)

 [![Latest Stable Version](https://camo.githubusercontent.com/72720ad193248cdb216b15a9eb30ccd002e6f3ef1c9dc2d078be9bbcc46d83a6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465766c6f702f75746d2d706172616d6574657273)](https://packagist.org/packages/devlop/utm-parameters) [![License](https://camo.githubusercontent.com/336e281a039e6b20206367d313b5935fb2e019b64bb29bcd544b0feedc6a1ccc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465766c6f702f75746d2d706172616d6574657273)](https://github.com/devlop/utm-parameters/blob/master/LICENSE.md)

UTM Parameters
==============

[](#utm-parameters)

Framework agnostic (PSR-7 compatible) [UTM parameters](https://en.wikipedia.org/wiki/UTM_parameters) helper, this tool will simplify working with UTM parameters.

Installation
============

[](#installation)

```
composer require devlop/utm-parameters

```

Usage
=====

[](#usage)

Capturing incoming UTM parameters
---------------------------------

[](#capturing-incoming-utm-parameters)

The basic idea is to capture incoming UTM parameters from the query and store them in cookies for later use until needed.

Create a middleware (or similar) following this logic:

```
use Devlop\UtmParameters\UtmParameters;

// Capture incoming UTM parameters from the query
$utmParameters = UtmParameters::capture($request);

if ($utmParameters !== null) {
    // Remember the UTM parameters in cookies for 30 days
    $utmParameters->remember($response, 30);
}
```

Retrieving stored UTM parameters
--------------------------------

[](#retrieving-stored-utm-parameters)

Later when you need the stored UTM parameters (example, after a registration or a placed order) you can easiliy retrieve them.

```
use Devlop\UtmParameters\UtmParameters;

// Retrieve stored UTM parameters from cookies
$utmParameters = UtmParameters::retrieve($request);

if ($utmParameters !== null) {
    // do something with the UTM parameters
    // optionally forget the cookies
    $utmParameters->forget($response);
}
```

Available methods
-----------------

[](#available-methods)

The `Devlop\UtmParameters\UtmParameters` have the following methods available:

`public function getSource() : string`

Get the *utm\_source* parameter.

`public function getMedium() : ?string`

Get the *utm\_medium* parameter.

`public function getCampaign() : ?string`

Get the *utm\_campaign* parameter.

`public function getTerm() : ?string`

Get the *utm\_term* parameter.

`public function getContent() : ?string`

Get the *utm\_content* parameter.

`public function toArray() : array`

Get all parameters as an array:

```
[
    "utm_source" => "github",
    "utm_medium" => "email",
    "utm_campaign" => "hackathon_2021",
    "utm_term" => null,
    "utm_content" => null,
]
```

Iterating
---------

[](#iterating)

`UtmParameters` is iterable:

```
foreach ($utmParameters as $parameter => $value) {
    // ...
}
```

Constants
---------

[](#constants)

All parameter keys are available as constants on UtmParameters to avoid the need to hardcode any parameter keys in your code.

```
$parameters = $utmParameters->toArray();

$parameters[UtmParameters::SOURCE];
$parameters[UtmParameters::MEDIUM];
$parameters[UtmParameters::CAMPAIGN];
$parameters[UtmParameters::TERM];
$parameters[UtmParameters::CONTENT];
```

Supported requests / responses
==============================

[](#supported-requests--responses)

When `capturing` / `retrieving` UTM parameters these requests are supported.

- [\\Psr\\Http\\Message\\ServerRequestInterface](https://github.com/php-fig/http-message/blob/master/src/ServerRequestInterface.php)
- [\\Symfony\\Component\\HttpFoundation\\Request](https://github.com/symfony/http-foundation/blob/5.x/Request.php)
- [\\Laravel\\Http\\Request](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/Request.php)

When `remembering` / `forgetting` UTM parameters these responses are supported.

- [\\Psr\\Http\\Message\\MessageInterface](https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php)
- [\\Symfony\\Component\\HttpFoundation\\Response](https://github.com/symfony/http-foundation/blob/5.x/Response.php)
- [\\Laravel\\Http\\Response](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/Response.php)
- [\\Illuminate\\Contracts\\Cookie\\QueueingFactory](https://github.com/laravel/framework/blob/master/src/Illuminate/Contracts/Cookie/QueueingFactory.php)

Laravel
=======

[](#laravel)

Cookies Facade
--------------

[](#cookies-facade)

The easiest way to `remember` or `forget` stored UTM parameters in Laravel is to use the global `cookie()` helper method to get an instance of QueueingFactory to [attach the cookies](https://laravel.com/docs/master/responses#attaching-cookies-to-responses) to the response.

Middleware
----------

[](#middleware)

`utm-parameters` ships with a middleware for Laravel for you to use.

Add the middleware in `app/Http/Kernel.php`, the middleware will automatically capture any incoming UTM parameters and store them in cookies for 30 days.

```
namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            // other configured middleware
            \Devlop\UtmParameters\Laravel\StoreUtmParametersInCookies::class,
        ],
    ];
}
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

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

Recently: every ~174 days

Total

10

Last Release

1228d ago

Major Versions

0.1.0 → 1.0.02021-02-09

PHP version history (2 changes)0.1.0PHP ^7.4|^8.0

1.0.0PHP ^7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10432296?v=4)[Johan Rosenson](/maintainers/johanrosenson)[@johanrosenson](https://github.com/johanrosenson)

---

Top Contributors

[![johanrosenson](https://avatars.githubusercontent.com/u/10432296?v=4)](https://github.com/johanrosenson "johanrosenson (17 commits)")

---

Tags

phppsr-7utm-parameterspsr-7utm parameters

### Embed Badge

![Health badge](/badges/devlop-utm-parameters/health.svg)

```
[![Health](https://phpackages.com/badges/devlop-utm-parameters/health.svg)](https://phpackages.com/packages/devlop-utm-parameters)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k296.6M807](/packages/symfony-psr-http-message-bridge)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[league/uri

URI manipulation library

1.1k206.4M277](/packages/league-uri)

PHPackages © 2026

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