Skip to content

Instantly share code, notes, and snippets.

@tattali
Last active May 24, 2020 08:06
Show Gist options
  • Save tattali/ff33d5d404167083f81d14f437b9efc2 to your computer and use it in GitHub Desktop.
Save tattali/ff33d5d404167083f81d14f437b9efc2 to your computer and use it in GitHub Desktop.
Create or Get UTM Cookies with Symfony

Create or Get UTM Cookies with Symfony

The UtmCookieBundle allow you to save utm parameters from url into a cookie. It's also provide a bunch of tools to easily retrive all or each utm.

  • Work with any flex Symfony projects 3.4+ to 5.0+
  • PHP v7.1+

Installation

Download tattali/utm-cookie-bundle using composer

$ composer require tattali/utm-cookie-bundle

Usage

<?php

use UtmCookieBundle\UtmCookie\UtmCookie;

class ExampleHandler
{
    private $utmCookie;

    public function __construct(UtmCookie $utmCookie) {
        $this->utmCookie = $utmCookie;
    }

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

To go further check the official documentation of the bundle, at UtmCookieBundle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment