PHP code example of devlop / utm-parameters

1. Go to this page and download the library: Download devlop/utm-parameters library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devlop / utm-parameters example snippets


use Devlop\UtmParameters\UtmParameters;

// Capture incoming UTM parameters from the query
$utmParameters = UtmParameters::capture($request);

if ($utmParameters !== null) {
    // Remember the UTM parameters in cookies for 30 days
    $utmParameters->remember($response, 30);
}

use Devlop\UtmParameters\UtmParameters;

// Retrieve stored UTM parameters from cookies
$utmParameters = UtmParameters::retrieve($request);

if ($utmParameters !== null) {
    // do something with the UTM parameters
    // optionally forget the cookies
    $utmParameters->forget($response);
}

[
    "utm_source" => "github",
    "utm_medium" => "email",
    "utm_campaign" => "hackathon_2021",
    "utm_term" => null,
    "utm_content" => null,
]

foreach ($utmParameters as $parameter => $value) {
    // ...
}

$parameters = $utmParameters->toArray();

$parameters[UtmParameters::SOURCE];
$parameters[UtmParameters::MEDIUM];
$parameters[UtmParameters::CAMPAIGN];
$parameters[UtmParameters::TERM];
$parameters[UtmParameters::CONTENT];

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            // other configured middleware
            \Devlop\UtmParameters\Laravel\StoreUtmParametersInCookies::class,
        ],
    ];
}