PHP code example of victord11 / laravel-utm

1. Go to this page and download the library: Download victord11/laravel-utm 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/ */

    

victord11 / laravel-utm example snippets


// app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        // ...
        \Illuminate\Session\Middleware\StartSession::class,
        // ...
        \VictoRD11\LaravelUTM\Middleware\ParameterTrackerMiddleware::class,
    ],
];

use VictoRD11\LaravelUTM\Sources;

return [

    /**
     * How the data will be stored
     */
    'store' => StoreType::Cookie,

    /*
     * 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 `\VictoRD11\LaravelUTM\Sources` namespace.
     */
    'tracked_parameters' => [
        [
            'key' => 'utm_source',
            'source' => Sources\RequestParameter::class,
        ],
        [
            'key' => 'utm_medium',
            'source' => Sources\RequestParameter::class,
        ],
        [
            'key' => 'utm_campaign',
            'source' => Sources\RequestParameter::class,
        ],
        [
            'key' => 'utm_term',
            'source' => Sources\RequestParameter::class,
        ],
        [
            'key' => 'utm_content',
            'source' => Sources\RequestParameter::class,
        ],
        [
            'key' => 'referer',
            'source' => Sources\CrossOriginRequestHeader::class,
        ],
    ],

    /**
     * The name of the cooke that will be set
     */
    'cookie_name' => 'utm_params',

    /**
     * Cookie secure flag
     */
    'cookie_secure' => null,

    /**
     * Cookie http flag
     */
    'cookie_http_only' => true,

    /**
     * We'll put the first touch tracked parameters in the session using this key.
     */
    'first_touch_store_key' => 'laravel_utm_parameters_first',

    /**
     * We'll put the last touch tracked parameters in the session using this key.
     */
    'last_touch_store_key' => 'laravel_utm_parameters_last',

    /**
     * If we should keep track of the first touch utm params
     */
    'first_touch' => true,

    /**
     * If we should keep track of the last touch utm params
     */
    'last_touch' => true,

    /*
     * 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',
    ],
];

use VictoRD11\LaravelUTM\ParameterTracker;

// returns an array of the first touch tracked parameters
$parameterTracker = app(ParameterTracker::class)

$parameterTracker->getFirstTouch();
$parameterTracker->getLastTouch();
$parameterTracker->getCurrent();
bash
php artisan vendor:publish --provider="VictoRD11\LaravelUTM\ServiceProvider"
blade

use VictoRD11\LaravelUTM\DecorateURL;