PHPackages                             abhij89/utm-referer - 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. abhij89/utm-referer

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

abhij89/utm-referer
===================

A simple package to get the referer and utm parameters for a new user

1.0.0(5y ago)011MITPHP

Since Dec 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/abhij89/utm-referer)[ Packagist](https://packagist.org/packages/abhij89/utm-referer)[ RSS](/packages/abhij89-utm-referer/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Remember a visitor's original referer &amp; utm tags
====================================================

[](#remember-a-visitors-original-referer--utm-tags)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Code Style Status](https://camo.githubusercontent.com/9169704d029c4c473a8a854bb31b50497ff7f358e038ae18e475a215c45995cf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d726566657265722f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://camo.githubusercontent.com/9169704d029c4c473a8a854bb31b50497ff7f358e038ae18e475a215c45995cf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d726566657265722f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)

Remember a visitor's original referer, utm tags in cookies.

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

[](#installation)

You can install the package via composer:

```
composer require abhij89/utm-referer
```

The package will automatically register itself in Laravel 5.5. In Laravel 5.4. you'll manually need to register the `Abhij89\UTMReferer\UTMRefererServiceProvider` service provider in `config/app.php`.

You can publish the config file with:

```
php artisan vendor:publish --provider="Abhij89\UTMReferer\UTMRefererServiceProvider"

```

Publishing the config file is necessary if you want to change the keys in which the referer/utms are stored in the cookie or if you want to disable a referer/utm source.

```
return [

    /*
     * The key that will be used to remember the referer in the cookie.
     */
    'referer_cookie_key' => 'user-referer',

    /*
     * The key that will be used to remember the utm tags in the cookie.
     */
    'utm_cookie_key' => 'user-utms',

    /*
     * The sources used to determine the referer/utms.
     */
    'sources' => [
        Abhij89\UTMReferer\Sources\UTMSource::class,
        Abhij89\UTMReferer\Sources\RequestHeader::class,
    ],
];
```

Usage
-----

[](#usage)

To capture the referer, all you need to do is add the `Abhij89\UTMReferer\CaptureReferer` middleware to your middleware stack. In most configuration's, you'll only want to capture the referer in "web" requests, so it makes sense to register it in the `web` stack. Make sure it comes **after** Laravel's `StartSession` middleware!

```
// app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        // ...
        \Illuminate\Session\Middleware\StartSession::class,
        // ...
        \Abhij89\UTMReferer\CaptureReferer::class,
        // ...
    ],
    // ...
];
```

The easiest way to retrieve the referer is by just resolving it out of the container:

```
use Abhij89\UTMReferer\UTMReferer;

$referer = app(UTMReferer::class)->get(); // 'google.com'
```

Or you could opt to use Laravel's automatic facades:

```
use Facades\Abhij89\UTMReferer\UTMReferer;

$referer = UTMReferer::get(); // 'google.com'
```

An empty referer will never overwrite an exisiting referer. So if a visitor comes from google.com and visits a few pages on your site, those pages won't affect the referer since local hosts are ignored.

### Forgetting or manually setting the referer

[](#forgetting-or-manually-setting-the-referer)

The `Referer` class provides dedicated methods to forget, or manually set the referer.

```
use Referer;

Referer::put('google.com');
Referer::get(); // 'google.com'
Referer::forget();
Referer::get(); // ''
```

### Changing the way the referer is determined

[](#changing-the-way-the-referer-is-determined)

The referer is determined by doing checks on various sources, which are defined in the configuration.

```
return [
    // ...
    'sources' => [
        Abhij89\Referer\Sources\UtmSource::class,
        Abhij89\Referer\Sources\RequestHeader::class,
    ],
];
```

A source implements the `Source` interface, and requires one method, `getReferer`. If a source is able to determine a referer, other sources will be ignored. In other words, the `sources` array is ordered by priority.

In the next example, we'll add a source that can use a `?ref` query parameter to determine the referer. Additionally, we'll ignore `?utm_source` parameters.

First, create the source implementations:

```
namespace App\Referer;

use Illuminate\Http\Request;
use Abhij89\Referer\Source;

class RefParameter implements Source
{
    public function getReferer(Request $request): string
    {
        return $request->get('ref', '');
    }
}
```

Then register your source in the `sources` array. We'll also disable the `utm_source` while we're at it.

```
return [
    // ...
    'sources' => [
        App\Referer\RefParameter::class,
        Abhij89\Referer\Sources\RequestHeader::class,
    ],
];
```

That's it! Source implementations can be this simple, or more advanced if necessary.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

2017d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15982920?v=4)[Abhishek jain](/maintainers/abhij89)[@abhij89](https://github.com/abhij89)

---

Top Contributors

[![abhij89](https://avatars.githubusercontent.com/u/15982920?v=4)](https://github.com/abhij89 "abhij89 (3 commits)")

### Embed Badge

![Health badge](/badges/abhij89-utm-referer/health.svg)

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

###  Alternatives

[daixianceng/yii2-smser

Yii2 SMS extension

882.9k1](/packages/daixianceng-yii2-smser)[t3kit/theme-t3kit

Base Theme fot t3kit project

2410.2k](/packages/t3kit-theme-t3kit)[monsieurbiz/sylius-no-commerce-plugin

Disable the e-commerce on your Sylius.

1421.0k](/packages/monsieurbiz-sylius-no-commerce-plugin)

PHPackages © 2026

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