Search by

tattali / utm-cookie-bundle

tattali

This bundle allow you to save utm parameters from url into a cookie when they exists. It's also provide a bunch of tools to easily retrive all or each utm.

Package info

github.com/tattali/UtmCookieBundle

Type:symfony-bundle

pkg:composer/tattali/utm-cookie-bundle

Statistics

Installs: 16 477

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v8.1.0 2026-10-18 22:21 UTC

README

CI Quality Gate Coverage Latest Version Downloads PHP Symfony License

This bundle allow you to save utm parameters from url into a cookie when they exists. It's also provide a bunch of tools to easily retrive all or each utm.

Each major version of the bundle supports one Symfony major version. Require the version that matches your Symfony version:

Bundle Symfony PHP Install Branch Maintenance
8.x 8.x 8.4+ composer require tattali/utm-cookie-bundle main new features
7.x 7.x 8.2+ composer require tattali/utm-cookie-bundle:^7.1 7.x bug fixes
6.x 6.4 8.1+ composer require tattali/utm-cookie-bundle:^6.1 6.x bug fixes
5.x 5.4 7.2.5+ composer require tattali/utm-cookie-bundle:^5.0 5.x security fixes only

The version constraint matters: 7.0.0 and 8.0.0 also allow Symfony 6.4 and 7, and 6.0.0 allows Symfony 5, so without it Composer can install a version that is not made for your Symfony version.

For Symfony 3.4 to 5.3, use tattali/utm-cookie-bundle:^1.1. See the changelog when upgrading.

Documentation

Installation

On Symfony 8:

$ composer require tattali/utm-cookie-bundle

For an older Symfony version, use the command from the table above.

Usage

<?php

use UtmCookieBundle\UtmCookie\UtmCookie;

class ExampleHandler
{
    public function __construct(
        private readonly UtmCookie $utmCookie,
    ) {
    }

    public function example()
    {
        $this->utmCookie->get(); // get all utm cookies as array
    }
}

Get all values as array

$this->utmCookie->get();

Get each values

$this->utmCookie->get('utm_campaign'); // or whithout 'utm_' prefix
$this->utmCookie->get('utm_content');
$this->utmCookie->get('utm_medium');
$this->utmCookie->get('utm_source');
$this->utmCookie->get('utm_term');

Initialize

Only if auto_init parameter is FALSE else it will be automatically initialized

$this->utmCookie->init(); // Init and read utm params and cookie and save new values.

The cookie is added to the response of the current request.

Parameters (optional):

utm_cookie:
    auto_init: true   # Automaticaly run init when get method is called
    domain: ''        # The (sub)domain that the cookie is available to, or '' to use current domain
    httponly: false   # When TRUE the cookie will be made accessible only through the HTTP protocol
    lifetime: 604800  # The lifetime of the cookie in seconds (default 604800 => 7 days)
    name: 'utm'       # The name of the cookie (default value "utm")
    overwrite: true   # If overwrite all utm values when even one is set in get
    path: '/'         # The path on the server in which the cookie will be available on
    samesite: 'lax'   # The SameSite attribute: 'lax', 'strict', 'none', or null to leave it out
    secure: null      # null: secure when the request is made over HTTPS; true or false to force it

Cookie flags

  • samesite defaults to lax, so the cookie is sent when a visitor follows a link to your site but not on cross-site subrequests. Browsers ignore samesite: 'none' unless the cookie is also secure.
  • secure defaults to null: the cookie gets the Secure flag when the current request is made over HTTPS. Behind a reverse proxy that terminates TLS, configure Symfony's trusted proxies so the request is seen as HTTPS. Set true or false to force the flag.
  • httponly defaults to false so that front-end JavaScript can read the utm values. Set it to true if only the server reads them.

License

This bundle is under the MIT license.