Skip to content

Installation Guide

Toni Suárez Rios edited this page Mar 18, 2024 · 2 revisions

Prerequisites

Before installing the package, ensure that you have the following prerequisites:

  • Laravel framework installed (version 11.x)
  • Composer globally installed on your system

Installation Steps

Follow these steps to install the Laravel UTM-Parameters package:

Step 1: Install Package

Open your terminal and navigate to your Laravel project directory. Then, use Composer to install the package:

$ composer require suarez/laravel-utm-parameter

Step 2: Middleware Configuration

Once the package is installed, you need to add the UtmParameters middleware to your Laravel application. Open the bootstrap/app.php file and append the UtmParameters::class inside the web-group.

return Application::configure(basePath: dirname(__DIR__))
  ...
  ->withMiddleware(function (Middleware $middleware) {
    $middleware->web(append: [
      Suarez\UtmParameter\Middleware\UtmParameters::class,
      /* ... keep the existing middleware here */
    ]);
  })
  ...

Step 3: Alias Configuration (Optional)

To enable UTM-Parameters only for certain requests or routes in your application, you can add an alias for the UtmParameters middleware. Open the bootstrap/app.php file and append the UtmParameters::class inside the web-group.

use Suarez\UtmParameter\Middleware\UtmParameters;

->withMiddleware(function (Middleware $middleware) {
    $middleware
        ->alias([
          /* ... keep the existing mappings here */
          'utm-parameters' => UtmParameters::class,
          ])
        ->web(append: [
          /* ... keep the existing mappings here */
          UtmParameters::class
        ]);
})

To apply UTM-Parameters to specific routes, use the following middleware: utm-parameters

Route::middleware('utm-parameters')->get('landing-page/{slug}', 'LandingPageController@show');

Step 4: Usage

You can now start using the UTM-Parameters package in your Laravel application. Refer to the package documentation for information on how to retrieve and utilize UTM parameters in your controllers, views, or other parts of your application.

Conclusion

Congratulations! You have successfully installed the Laravel UTM-Parameters package in your Laravel application. You can now start tracking and managing UTM parameters in your application to enhance user experience.