Download the PHP package suarez/laravel-utm-parameter without Composer
On this page you can find all versions of the php package suarez/laravel-utm-parameter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download suarez/laravel-utm-parameter
More information about suarez/laravel-utm-parameter
Files in suarez/laravel-utm-parameter
Package laravel-utm-parameter
Short Description A little helper to store and handle utm-parameter
License MIT
Homepage https://github.com/toni-suarez/laravel-utm-parameter
Informations about the package laravel-utm-parameter
Laravel UTM-Parameters
A lightweight way to handle UTM parameters session-based in your Laravel Application.
Installation
Follow these steps to install the Laravel UTM-Parameters package. Guide for Laravel 10 and below.
Open your terminal and navigate to your Laravel project directory. Then, use Composer to install the package:
Optionally, you can publish the config file of this package with this command:
Middleware Configuration
Once the package is installed, you can add the UtmParameters middleware to your Laravel application. Open the bootstrap/app.php
file and append the UtmParameters::class
inside the web-group.
Also, take a look at how to set an alias for the middleware.
Use as Facade
If you prefer not to use it as middleware, you can utilize the UtmParameter Facade directly in your controllers or other parts of your application. Once the boot($request)
-method is called, you have access to it at any place. For example:
Configuration
The configuration file config/utm-parameter.php
allows you to control the behavior of the UTM parameters handling.
Usage
get_all_utm()
To get an array of all UTM parameters, use this helper: get_all_utm()
.
get_utm()
If you need to retrieve certain UTM parameters, use get_utm('source|medium|campaign|term|content')
.
has_utm()
Sometimes you want to show or do something, if user might have some or specific utm-parameters.
Simply use:
has_utm('source|medium|campaign|term|content', 'optional-value')
has_not_utm('source|medium|campaign|term|content', 'optional-value')
contains_utm()
You can conditionally show or perform actions based on the presence or absence of a portion of an UTM parameters using contains.
Simply use:
contains_utm('source|medium|campaign|term|content', 'value')
contains_not_utm('source|medium|campaign|term|content', 'value')
Extending the Middleware
You can extend the middleware to customize the behavior of accepting UTM parameters. For example, you can override the shouldAcceptUtmParameter
method.
First, create a new middleware using Artisan:
Then, update the new middleware to extend UtmParameters and override the shouldAcceptUtmParameter
method:
Finally, update your bootstrap/app.php
to use the CustomMiddleware:
Resources
Explore additional use cases and resources on the wiki pages
- Installation Guide
- Installation Guide (Laravel 8.x to 10.x)
- How it works
- Limitations
- Advanced Usage
- Blade Usage
- Usage via Facade or Helper Class
Inspirations
- Use Case: A/B Testing
- Use Case: Different Styles for Social Media
- Use Case: Lead Attribution
- Use Case: Social Media Tracking
- Use‐Case: Newsletter Redirect on Product Detail Page
- Use‐Case: Offline Marketing Integration
License
The Laravel UTM-Parameters package is open-sourced software licensed under the MIT license.