PHPackages                             realtydev/analyticstracker - 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. realtydev/analyticstracker

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

realtydev/analyticstracker
==========================

Keeps track of the original UTM parameters

01PHP

Since Dec 28Pushed 5y agoCompare

[ Source](https://github.com/realtydev/analyticstracker)[ Packagist](https://packagist.org/packages/realtydev/analyticstracker)[ RSS](/packages/realtydev-analyticstracker/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Keeps track of the original UTM (or other analytics) parameters
===============================================================

[](#keeps-track-of-the-original-utm-or-other-analytics-parameters)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c1854aaa5e6151e87875fcb20f4de41d639c4cf2757527cb52e26699e1eab997/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7265616c74796465762f6c61726176656c2d616e616c79746963732d747261636b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/realtydev/laravel-analytics-tracker)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c5e8a3d23d1bd7242d4581dc60a4e2fe60869759741726d030dd1be3347505cc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7265616c74796465762f6c61726176656c2d616e616c79746963732d747261636b65722f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/realtydev/laravel-analytics-tracker/actions?query=workflow%3Arun-tests+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/2c1fc8f074fc3b0fb05083d6727eed9c8da6259e89eb25f8f6810c1fd4a6459a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7265616c74796465762f6c61726176656c2d616e616c79746963732d747261636b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/realtydev/laravel-analytics-tracker)

Cross domain analytics is hard. This package helps you to keep track of the visitor's original UTM parameters, referer header and other analytics parameters. You can then submit these parameters along with a form submission or add them to a link to another domain you track.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/88c325c45039df2934d447927e3a43889dc9e114bee16b868ae6e1efbad3c318/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d75746d2d666f727761726465722e6a70673f743d31)](https://realtydev.be/github-ad-click/laravel-utm-forwarder)

We invest a lot of resources into creating [best in class open source packages](https://realtydev.be/open-source). You can support us by [buying one of our paid products](https://realtydev.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://realtydev.be/about-us). We publish all received postcards on [our virtual postcard wall](https://realtydev.be/open-source/postcards).

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

[](#installation)

You can install the package via composer:

```
composer require realtydev/laravel-analytics-tracker
```

The package works via a middleware that needs to be added to the `web` stack in your `kernel.php` file. Make sure to register this middleware after the `StartSession` middleware.

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

protected $middlewareGroups = [
    'web' => [
        // ...
        \Illuminate\Session\Middleware\StartSession::class,
        // ...

        \realtydev\AnalyticsTracker\Middleware\TrackAnalyticsParametersMiddleware::class,
    ],
];
```

To configure the tracked parameters or how they're mapped on the URL parameters, you can publish the config file using:

```
php artisan vendor:publish --provider="realtydev\AnalyticsTracker\AnalyticsTrackerServiceProvider"
```

This is the contents of the published config file:

```
return [
    /*
     * These are the analytics parameters that will be tracked when a user first visits
     * the application. The configuration consists of the parameter's key and the
     * source to extract this key from.
     *
     * Available sources can be found in the `\realtydev\AnalyticsTracker\Sources` namespace.
     */
    'tracked_parameters' => [
        [
            'key' => 'utm_source',
            'source' => realtydev\AnalyticsTracker\Sources\RequestParameter::class,
        ],
        [
            'key' => 'utm_medium',
            'source' => realtydev\AnalyticsTracker\Sources\RequestParameter::class,
        ],
        [
            'key' => 'utm_campaign',
            'source' => realtydev\AnalyticsTracker\Sources\RequestParameter::class,
        ],
        [
            'key' => 'utm_term',
            'source' => realtydev\AnalyticsTracker\Sources\RequestParameter::class,
        ],
        [
            'key' => 'utm_content',
            'source' => realtydev\AnalyticsTracker\Sources\RequestParameter::class,
        ],
        [
            'key' => 'referer',
            'source' => realtydev\AnalyticsTracker\Sources\CrossOriginRequestHeader::class,
        ],
    ],

    /**
     * We'll put the tracked parameters in the session using this key.
     */
    'session_key' => 'tracked_analytics_parameters',

    /*
     * When formatting an URL to add the tracked parameters we'll use the following
     * mapping to put tracked parameters in URL parameters.
     *
     * This is useful when using an analytics solution that ignores the utm_* parameters.
     */
    'parameter_url_mapping' => [
        'utm_source' => 'utm_source',
        'utm_medium' => 'utm_medium',
        'utm_campaign' => 'utm_campaign',
        'utm_term' => 'utm_term',
        'utm_content' => 'utm_content',
        'referer' => 'referer',
    ],
];
```

Usage
-----

[](#usage)

The easiest way to retrieve the tracked parameters is by resolving the `TrackedAnalyticsParameters` class:

```
use realtydev\AnalyticsTracker\AnalyticsBag;

app(AnalyticsBag::class)->get(); // returns an array of tracked parameters
```

You can also decorate an existing URL with the tracked parameters. This is useful to forward analytics to another domain you're running analytics on.

```

    Buy this product on our webshop

Will link to https://mywebshop.com?utm_source=facebook&utm_campaign=blogpost
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Alex Vanderbist](https://github.com/AlexVanderbist)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad6519dc923802aba893ec289fff4edc09dc495fc22dcac5d4c28931d884d107?d=identicon)[realty-dev](/maintainers/realty-dev)

---

Top Contributors

[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (8 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (7 commits)")[![realtydev](https://avatars.githubusercontent.com/u/35852411?v=4)](https://github.com/realtydev "realtydev (6 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (2 commits)")

### Embed Badge

![Health badge](/badges/realtydev-analyticstracker/health.svg)

```
[![Health](https://phpackages.com/badges/realtydev-analyticstracker/health.svg)](https://phpackages.com/packages/realtydev-analyticstracker)
```

PHPackages © 2026

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