PHPackages                             tourze/symfony-utm-bundle - 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. tourze/symfony-utm-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

tourze/symfony-utm-bundle
=========================

Symfony bundle for UTM parameter tracking and conversion analytics

1.1.0(4mo ago)00MITPHPCI passing

Since Nov 5Pushed 4mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (36)Versions (4)Used By (0)

Symfony UTM Bundle
==================

[](#symfony-utm-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![PHP Version](https://camo.githubusercontent.com/cc1df0bdf6b1fa541f565daa2d9f434c010c034d15673230cd1f648c5da6cff0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f73796d666f6e792d75746d2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-utm-bundle)
[![License](https://camo.githubusercontent.com/182eacd1579c77f64dd6ae591d170709bb5ee5bd063fdd2942b3c6f1945e2125/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f73796d666f6e792d75746d2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-utm-bundle)
[![Latest Version](https://camo.githubusercontent.com/d8ec28c3b4debeaca1ac8b3b0c4e446a11121318dcec4f1be421a000ca0bb3ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f73796d666f6e792d75746d2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-utm-bundle)
[![Total Downloads](https://camo.githubusercontent.com/5123a777a37d1a2333dda317ac8c35eacc1474f4af20993f2d1fee5ee8d625ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f73796d666f6e792d75746d2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-utm-bundle)
[![Code Coverage](https://camo.githubusercontent.com/59636f3fe98483ede84701e49094579155d16e75929dbf040aec32e88c0926f2/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f73796d666f6e792d75746d2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/symfony-utm-bundle)

A comprehensive Symfony bundle for tracking UTM (Urchin Tracking Module) parameters
and conversion events. This bundle provides automatic UTM parameter detection,
session management, and conversion tracking for web applications.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Dependencies](#dependencies)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
- [Usage](#usage)
- [Advanced Usage](#advanced-usage)
- [EasyAdmin Integration](#easyadmin-integration)
- [Events](#events)
- [Storage Strategies](#storage-strategies)
- [API Reference](#api-reference)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)

Features
--------

[](#features)

- **Automatic UTM Parameter Detection**: Automatically extracts UTM parameters from incoming requests
- **Session Management**: Manages UTM sessions with configurable lifetime and expiration
- **Conversion Tracking**: Track conversion events with UTM attribution
- **Multiple Storage Strategies**: Support for database and session-based storage
- **EasyAdmin Integration**: Pre-built admin controllers for managing UTM data
- **Flexible Configuration**: Support for custom UTM parameters and validation rules
- **Event-Driven Architecture**: Dispatches events for UTM conversions and sessions
- **Parameter Validation**: Built-in validation with XSS protection and length limits
- **User Attribution**: Automatic user identification and anonymous session tracking

Dependencies
------------

[](#dependencies)

- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 3.0 or higher
- EasyAdmin Bundle 4.0 or higher

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

[](#installation)

Install the bundle via Composer:

```
composer require tourze/symfony-utm-bundle
```

Quick Start
-----------

[](#quick-start)

### 1. Enable the Bundle

[](#1-enable-the-bundle)

Add the bundle to your `config/bundles.php` file:

```
return [
    // ...
    Tourze\UtmBundle\UtmBundle::class => ['all' => true],
];
```

### 2. Configure Database

[](#2-configure-database)

Run the following commands to set up the database tables:

```
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
```

### 3. Basic Usage

[](#3-basic-usage)

The bundle automatically tracks UTM parameters from URLs like:

```
https://example.com/landing-page?utm_source=google&utm_medium=cpc&utm_campaign=summer_sale

```

Track conversions in your controllers:

```
use Tourze\UtmBundle\Service\UtmConversionTracker;

class OrderController extends AbstractController
{
    public function __construct(
        private UtmConversionTracker $conversionTracker
    ) {}

    public function complete(): Response
    {
        // Track order completion conversion
        $this->conversionTracker->track('order_complete', 99.99, [
            'order_id' => 12345,
            'items_count' => 3
        ]);

        return $this->render('order/complete.html.twig');
    }
}
```

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

[](#configuration)

Create a configuration file at `config/packages/utm.yaml`:

```
utm:
  # Storage strategy: 'database' or 'session'
  storage_strategy: 'database'

  # Session configuration
  session:
    lifetime: 3600  # Session lifetime in seconds

  # Parameter validation
  validation:
    max_length: 255     # Maximum parameter length
    sanitize: true      # Enable XSS protection

  # Additional UTM parameters to track
  additional_parameters:
    - utm_id
    - utm_custom
```

Usage
-----

[](#usage)

### Manual UTM Parameter Extraction

[](#manual-utm-parameter-extraction)

```
use Tourze\UtmBundle\Service\UtmParametersExtractor;
use Symfony\Component\HttpFoundation\Request;

class MyController extends AbstractController
{
    public function __construct(
        private UtmParametersExtractor $extractor
    ) {}

    public function landing(Request $request): Response
    {
        $utmParams = $this->extractor->extract($request);

        if ($utmParams->hasAnyParameter()) {
            $source = $utmParams->getSource();
            $medium = $utmParams->getMedium();
            $campaign = $utmParams->getCampaign();

            // Use UTM data for analytics
        }

        return $this->render('landing.html.twig');
    }
}
```

### Session Management

[](#session-management)

```
use Tourze\UtmBundle\Service\UtmSessionManager;

class AnalyticsController extends AbstractController
{
    public function __construct(
        private UtmSessionManager $sessionManager
    ) {}

    public function dashboard(): Response
    {
        $currentSession = $this->sessionManager->getCurrentSession();

        if ($currentSession) {
            $parameters = $currentSession->getParameters();
            $userIdentifier = $currentSession->getUserIdentifier();
            $metadata = $currentSession->getMetadata();
        }

        return $this->render('analytics/dashboard.html.twig');
    }
}
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Storage Strategy

[](#custom-storage-strategy)

Implement your own storage strategy:

```
use Tourze\UtmBundle\Service\Storage\UtmStorageStrategyInterface;
use Tourze\UtmBundle\Entity\UtmSession;
use Tourze\UtmBundle\Dto\UtmParametersDto;

class RedisStorageStrategy implements UtmStorageStrategyInterface
{
    public function store(UtmParametersDto $parameters, string $sessionId): UtmSession
    {
        // Custom Redis implementation
    }

    public function retrieve(string $sessionId): ?UtmSession
    {
        // Custom Redis retrieval
    }
}
```

### Event Listeners

[](#event-listeners)

Listen to UTM events:

```
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Tourze\UtmBundle\Event\UtmConversionEvent;

class UtmAnalyticsSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            UtmConversionEvent::NAME => 'onConversion',
        ];
    }

    public function onConversion(UtmConversionEvent $event): void
    {
        $conversion = $event->getConversion();
        $eventName = $conversion->getEventName();
        $value = $conversion->getValue();

        // Send data to analytics platform
    }
}
```

EasyAdmin Integration
---------------------

[](#easyadmin-integration)

The bundle provides pre-built EasyAdmin controllers for managing UTM data. Add to your dashboard:

```
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use Tourze\UtmBundle\Controller\Admin\UtmParametersCrudController;
use Tourze\UtmBundle\Controller\Admin\UtmSessionCrudController;
use Tourze\UtmBundle\Controller\Admin\UtmConversionCrudController;

class DashboardController extends AbstractDashboardController
{
    public function configureMenuItems(): iterable
    {
        yield MenuItem::section('UTM Analytics');
        yield MenuItem::linkToCrud('UTM Parameters', 'fas fa-link', UtmParameters::class)
            ->setController(UtmParametersCrudController::class);
        yield MenuItem::linkToCrud('UTM Sessions', 'fas fa-users', UtmSession::class)
            ->setController(UtmSessionCrudController::class);
        yield MenuItem::linkToCrud('UTM Conversions', 'fas fa-chart-line', UtmConversion::class)
            ->setController(UtmConversionCrudController::class);
    }
}
```

Events
------

[](#events)

The bundle dispatches the following events:

- `UtmConversionEvent::NAME`: Dispatched when a conversion is tracked

Storage Strategies
------------------

[](#storage-strategies)

### Database Strategy (Default)

[](#database-strategy-default)

Stores UTM data in database tables using Doctrine ORM.

### Session Strategy

[](#session-strategy)

Stores UTM data in PHP sessions for simpler setups without persistent storage.

API Reference
-------------

[](#api-reference)

### UtmConversionTracker

[](#utmconversiontracker)

- `track(string $eventName, float $value = 0.0, array $metadata = []): UtmConversion`

### UtmParametersExtractor

[](#utmparametersextractor)

- `extract(Request $request): UtmParametersDto`

### UtmSessionManager

[](#utmsessionmanager)

- `getCurrentSession(): ?UtmSession`
- `createSession(UtmParametersDto $parameters): UtmSession`

### UtmContextManager

[](#utmcontextmanager)

- `getCurrentParameters(): ?UtmParameters`
- `getCurrentSession(): ?UtmSession`

Testing
-------

[](#testing)

Run the test suite:

```
vendor/bin/phpunit packages/symfony-utm-bundle/tests
```

Run static analysis:

```
vendor/bin/phpstan analyse packages/symfony-utm-bundle
```

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

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass
6. Submit a pull request

Please ensure your code follows PSR-12 coding standards and includes appropriate tests.

License
-------

[](#license)

This bundle is released under the MIT License. See [LICENSE](LICENSE) file for details.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance79

Regular maintenance activity

Popularity0

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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

Total

3

Last Release

141d ago

### Community

Maintainers

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-symfony-utm-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-symfony-utm-bundle/health.svg)](https://phpackages.com/packages/tourze-symfony-utm-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)

PHPackages © 2026

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