PHPackages                             samer-alshaer/laravel-utm-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. samer-alshaer/laravel-utm-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

samer-alshaer/laravel-utm-builder
=================================

A Laravel package for generating URLs with UTM parameters. Features fluent API, presets, helpers, and full Laravel integration.

v1.0.4(6mo ago)241MITPHPPHP ^8.1

Since Dec 1Pushed 6mo agoCompare

[ Source](https://github.com/samer-alshaer/laravel-utm-builder)[ Packagist](https://packagist.org/packages/samer-alshaer/laravel-utm-builder)[ Docs](https://github.com/samer-alshaer/laravel-utm-builder)[ RSS](/packages/samer-alshaer-laravel-utm-builder/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (6)Used By (0)

Laravel UTM Builder
===================

[](#laravel-utm-builder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d73acb04f3555f39d1386151f30d630b6b1cfb16c458609f70b486bb3c19bef9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d65722d616c73686165722f6c61726176656c2d75746d2d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samer-alshaer/laravel-utm-builder)[![Total Downloads](https://camo.githubusercontent.com/d125c24a9c3dde03b4b2eb52536cc4730333bb2d3a582a5b4e1a36f18a3907df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616d65722d616c73686165722f6c61726176656c2d75746d2d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samer-alshaer/laravel-utm-builder)[![License](https://camo.githubusercontent.com/38f0fa6da9d55e6a2b99f21dbfc1b37947e530d6ebbd3b8e7cebf9017eff406a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73616d65722d616c73686165722f6c61726176656c2d75746d2d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samer-alshaer/laravel-utm-builder)

A Laravel package for generating URLs with UTM parameters. Features a fluent API, presets, helpers, Blade directives, and full Laravel integration.

Features
--------

[](#features)

- 🔗 **Fluent API** - Chainable methods for building URLs
- 📦 **Presets** - Pre-defined UTM configurations for common use cases
- 🛠 **Helper Functions** - Quick URL generation anywhere in your code
- 🎨 **Blade Directives** - Easy use in your views
- 🏷 **Model Trait** - Add UTM link generation to your Eloquent models
- ⚙️ **Configurable** - Customize everything via config file
- ✅ **Fully Tested** - Comprehensive test coverage
- 📱 **Laravel 10, 11 &amp; 12** - Support for latest Laravel versions

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require samer-alshaer/laravel-utm-builder
```

Publish the configuration file:

```
php artisan vendor:publish --tag="utm-builder-config"
```

Configuration
-------------

[](#configuration)

Add these optional environment variables to your `.env` file:

```
UTM_BASE_URL=https://your-app.com
UTM_CLIENT_URL=https://your-client-site.com
```

Usage
-----

[](#usage)

### Using the Fluent Builder

[](#using-the-fluent-builder)

```
use Samer\UtmBuilder\UtmBuilder;

// Basic usage
$url = UtmBuilder::make()
    ->path('landing-page')
    ->source('google')
    ->medium('cpc')
    ->campaign('summer_sale')
    ->build();
// https://your-app.com/landing-page?utm_source=google&utm_medium=cpc&utm_campaign=summer_sale

// Using presets
$url = UtmBuilder::make()
    ->path('signup')
    ->preset('newsletter')
    ->content('header_button')
    ->build();

// With additional parameters
$url = UtmBuilder::make()
    ->path('product/123')
    ->preset('email')
    ->ref('user', 456)
    ->param('discount', '20OFF')
    ->build();
```

### Using the Facade

[](#using-the-facade)

```
use Samer\UtmBuilder\Facades\Utm;

$url = Utm::make()
    ->path('checkout')
    ->preset('email')
    ->campaign('abandoned_cart')
    ->build();
```

### Using Helper Functions

[](#using-helper-functions)

```
// Quick link with preset
$url = utm_link('page/path', 'email');

// Link with custom parameters
$url = utm_link('signup', 'newsletter', ['ref_id' => 123]);

// Client website URL
$url = utm_client('landing-page', 'facebook');

// Custom UTM parameters
$url = utm_url('https://example.com/page', [
    'utm_source' => 'partner',
    'utm_medium' => 'referral',
]);
```

### In Blade Templates

[](#in-blade-templates)

```
{{-- Using directive --}}
Sign Up

{{-- Using client directive --}}
Visit Site

{{-- Using helper --}}
Click Here
```

### In Eloquent Models

[](#in-eloquent-models)

```
use Samer\UtmBuilder\Traits\HasUtmLinks;

class Product extends Model
{
    use HasUtmLinks;

    public function getShareLink(): string
    {
        return $this->utmBuilder()
            ->path("product/{$this->slug}")
            ->preset('whatsapp')
            ->ref('product', $this->id)
            ->build();
    }

    // Or use the built-in method
    public function getLink(): string
    {
        return $this->toUtmLink('email', ['discount' => '10OFF']);
    }

    // Customize the path
    protected function getUtmPath(): string
    {
        return "products/{$this->slug}";
    }
}
```

### Available Methods

[](#available-methods)

MethodDescription`make($baseUrl)`Create new builder instance`client()`Create instance with client URL`path($path)`Set URL path`preset($name)`Apply preset configuration`source($source)`Set utm\_source`medium($medium)`Set utm\_medium`campaign($campaign)`Set utm\_campaign`term($term)`Set utm\_term`content($content)`Set utm\_content`id($id)`Set utm\_id`utm($array)`Set multiple UTM params`params($array)`Add query parameters`param($key, $value)`Add single parameter`ref($key, $value)`Add reference tracking`build()`Generate the URL`toArray()`Get URL and params as array`getUtmParams()`Get UTM parameters onlyPresets
-------

[](#presets)

The package comes with several built-in presets:

```
// Email
'email', 'newsletter', 'transactional'

// SMS
'sms', 'sms_notification', 'sms_promotion'

// Social Media
'facebook', 'twitter', 'linkedin', 'instagram', 'whatsapp'

// Advertising
'google_ads', 'facebook_ads'

// Other
'referral', 'affiliate', 'internal', 'admin_panel'
```

### Custom Presets

[](#custom-presets)

Add your own presets in `config/utm-builder.php`:

```
'presets' => [
    'booking_payment' => [
        'utm_source' => 'system',
        'utm_medium' => 'email',
        'utm_campaign' => 'booking_payment',
    ],

    'agent_registration' => [
        'utm_source' => 'admin_panel',
        'utm_medium' => 'referral',
        'utm_campaign' => 'agent_signup',
    ],
],
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Samer](https://github.com/samer-alshaer)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance69

Regular maintenance activity

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Total

5

Last Release

183d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f9708ec86e2987b1e1c2abed3ce58a0081f0cb1ea697105c8f1d4e49c2af756a?d=identicon)[samer-alshaer](/maintainers/samer-alshaer)

---

Top Contributors

[![samer-alshaer](https://avatars.githubusercontent.com/u/80044830?v=4)](https://github.com/samer-alshaer "samer-alshaer (7 commits)")

---

Tags

laraveltrackingmarketinganalyticsurl buildergoogle-analyticsUTMutm-buildercampaign-tracking

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/samer-alshaer-laravel-utm-builder/health.svg)

```
[![Health](https://phpackages.com/badges/samer-alshaer-laravel-utm-builder/health.svg)](https://phpackages.com/packages/samer-alshaer-laravel-utm-builder)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[nativephp/mobile

NativePHP for Mobile

1.1k75.1k91](/packages/nativephp-mobile)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
