{"id":37384242,"url":"https://github.com/toni-suarez/laravel-utm-parameter","last_synced_at":"2026-01-16T05:16:53.004Z","repository":{"id":40458749,"uuid":"448347178","full_name":"toni-suarez/laravel-utm-parameter","owner":"toni-suarez","description":"A lightweight way to handle UTM parameters session-based in your Laravel Application.","archived":false,"fork":false,"pushed_at":"2025-02-25T17:00:16.000Z","size":97,"stargazers_count":15,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"12.x","last_synced_at":"2025-12-13T03:58:48.436Z","etag":null,"topics":["laravel","php","social-media","utm-parameters"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toni-suarez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-15T17:35:44.000Z","updated_at":"2025-10-11T22:39:57.000Z","dependencies_parsed_at":"2024-06-18T18:05:54.004Z","dependency_job_id":"2aa75faa-63f5-4be6-97f9-9d384901aada","html_url":"https://github.com/toni-suarez/laravel-utm-parameter","commit_stats":{"total_commits":21,"total_committers":3,"mean_commits":7.0,"dds":0.5238095238095238,"last_synced_commit":"5b0e3272209fd340aa85492cd0e8bb761605566c"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/toni-suarez/laravel-utm-parameter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toni-suarez%2Flaravel-utm-parameter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toni-suarez%2Flaravel-utm-parameter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toni-suarez%2Flaravel-utm-parameter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toni-suarez%2Flaravel-utm-parameter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toni-suarez","download_url":"https://codeload.github.com/toni-suarez/laravel-utm-parameter/tar.gz/refs/heads/12.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toni-suarez%2Flaravel-utm-parameter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28477224,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T03:13:13.607Z","status":"ssl_error","status_checked_at":"2026-01-16T03:11:47.863Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","php","social-media","utm-parameters"],"created_at":"2026-01-16T05:16:52.449Z","updated_at":"2026-01-16T05:16:52.996Z","avatar_url":"https://github.com/toni-suarez.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel UTM-Parameters\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/suarez/laravel-utm-parameter.svg?style=flat-square)](https://packagist.org/packages/suarez/laravel-utm-parameter)\n[![StyleCI](https://github.styleci.io/repos/448347178/shield?branch=main)](https://github.styleci.io/repos/448347178?branch=main)\n[![Test PHP 8.x](https://github.com/toni-suarez/laravel-utm-parameter/actions/workflows/tests-php8.yml/badge.svg?branch=main)](https://github.com/toni-suarez/laravel-utm-parameter/actions/workflows/tests-php8.yml)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/suarez/laravel-utm-parameter)](https://packagist.org/packages/suarez/laravel-utm-parameter)\n![GitHub](https://img.shields.io/github/license/toni-suarez/laravel-utm-parameter)\n[![Statamic Addon](https://img.shields.io/badge/https%3A%2F%2Fstatamic.com%2Faddons%2Ftoni-suarez%2Futm-parameter?style=flat-square\u0026logo=statamic\u0026logoColor=rgb(255%2C%2038%2C%20158)\u0026label=Statamic\u0026link=https%3A%2F%2Fstatamic.com%2Faddons%2Ftoni-suarez%2Futm-parameter)](https://statamic.com/addons/toni-suarez/utm-parameter)\n\nA lightweight way to handle UTM parameters session-based in your Laravel Application.\n\n```blade\n@hasUtm('source', 'newsletter')\n  \u003cp\u003eSpecial Content for Newsletter-Subscriber.\u003c/p\u003e\n@endhasUtm\n```\n\n---\n\n## Installation\n\nFollow these steps to install the Laravel UTM-Parameters package. [Guide for Laravel 10 and below.](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Installation-Guide-(Laravel-8.x-to-10.x))\n\nOpen your terminal and navigate to your Laravel project directory. Then, use Composer to install the package:\n\n```bash\n$ composer require suarez/laravel-utm-parameter\n```\n\nOptionally, you can publish the config file of this package with this command:\n```bash\nphp artisan vendor:publish --tag=\"utm-parameter\"\n```\n\n### Middleware Configuration\n\nOnce 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.\n\n```php\n# Laravel 11+\nreturn Application::configure(basePath: dirname(__DIR__))\n  ...\n  -\u003ewithMiddleware(function (Middleware $middleware) {\n    $middleware-\u003eweb(append: [\n      Suarez\\UtmParameter\\Middleware\\UtmParameters::class,\n      /* ... keep the existing middleware here */\n    ]);\n  })\n  ...\n```\n\nAlso, take a look at how to set an [alias for the middleware](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Installation-Guide#step-3-alias-configuration-optional).\n\n### Use as Facade\n\nIf 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:\n\n```php\nuse Suarez\\UtmParameter\\Facades\\UtmParameter;\n\n// Inside a controller method\nclass IndexController {\n  public function index(Request $request)\n  {\n      UtmParameter::boot($request);\n  }\n}\n\nclass SomeDifferentController {\n  public function index(Request $request)\n  {\n      $source = UtmParameter::get('source');\n  }\n}\n```\n\n## Configuration\n\nThe configuration file `config/utm-parameter.php` allows you to control the behavior of the UTM parameters handling.\n\n```php\n\u003c?php\n\nreturn [\n  /*\n   * Control Overwriting UTM Parameters (default: false)\n   *\n   * This setting determines how UTM parameters are handled within a user's session.\n   *\n   * - Enabled (true): New UTM parameters will overwrite existing ones during the session.\n   * - Disabled (false): The initial UTM parameters will persist throughout the session.\n   */\n  'override_utm_parameters' =\u003e false,\n\n  /*\n   * Session Key for UTM Parameters (default: 'utm')\n   *\n   * This key specifies the name used to access and store UTM parameters within the session data.\n   *\n   * If you're already using 'utm' for another purpose in your application,\n   * you can customize this key to avoid conflicts.\n   * Simply provide your preferred key name as a string value.\n   */\n  'session_key' =\u003e 'utm',\n\n  /*\n    * Allowed UTM Parameters (default: ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'utm_campaign_id'])\n    *\n    * This setting defines the UTM parameters that are allowed within your application.\n    *\n    * In this array, you can specify a list of allowed UTM parameter names. Each parameter should be listed as a string.\n    * Only parameters from this list will be stored and processed in the session.\n    * and any parameter without the 'utm_' prefix will be ignored regardless of its inclusion in this list.\n    *\n    * Example: To only allow the basic UTM parameters (source, medium, and campaign), you could update the array like this:\n    *\n    * 'allowed_utm_parameters' =\u003e [\n    *     'utm_source',\n    *     'utm_medium',\n    *     'utm_campaign',\n    * ],\n    */\n    'allowed_utm_parameters' =\u003e [\n        'utm_source',\n        'utm_medium',\n        'utm_campaign',\n        'utm_term',\n        'utm_content',\n        'utm_campaign_id'\n    ],\n];\n```\n\n## Usage\n\n### get_all_utm()\n\nTo get an array of all UTM parameters, use this helper:  `get_all_utm()`.\n\n```php\n$parameter = get_all_utm();\n```\n\n###  get_utm()\n\nIf you need to retrieve certain UTM parameters, use `get_utm('source|medium|campaign|term|content')`.\n\n```blade\n \u003cp\u003eYou came from {{ get_utm('source') }}\u003c/p\u003e\n```\n\n```php\n// Some Task in your Class\npublic function someTask()\n{\n  return match(get_utm('source')) {\n    'bing' =\u003e Bing::class,\n    'google' =\u003e Google::class,\n    'duckduckgo' =\u003e DuckDuckGo::class,\n    'newsletter' =\u003e Newsletter::class,\n    default =\u003e Default::class\n  };\n}\n\n// Render a view based on an utm_source\nRoute::get('/', function () {\n  return match(get_utm('source')) {\n        'newsletter' =\u003e view('newsletter'),\n        default =\u003e view('welcome')\n    };\n});\n```\n\n### has_utm()\n\nSometimes you want to show or do something, if user might have some or specific utm-parameters.\n\nSimply use:\n- `has_utm('source|medium|campaign|term|content', 'optional-value')`\n- `has_not_utm('source|medium|campaign|term|content', 'optional-value')`\n\n```blade\n@hasUtm('source', 'corporate-partner')\n  \u003cdiv\u003eSome corporate partner related stuff\u003c/div\u003e\n@endhasUtm\n\n@hasNotUtm('term')\n  \u003cp\u003eYou have any term.\u003c/p\u003e\n@endhasNotUtm\n```\n\n```php\n if (has_utm('campaign', 'special-sale')) {\n   redirect('to/special-sale/page');\n }\n\n if (has_not_utm('campaign', 'newsletter')) {\n   session()-\u003eflash('Did you know, we have a newsletter?');\n }\n```\n\n### contains_utm()\n\nYou can conditionally show or perform actions based on the presence or absence of a portion of an UTM parameters using contains.\n\nSimply use:\n- `contains_utm('source|medium|campaign|term|content', 'value')`\n- `contains_not_utm('source|medium|campaign|term|content', 'value')`\n\n```blade\n@containsUtm('campaign', 'weekly')\n  \u003cdiv\u003eSome Weekly related stuff\u003c/div\u003e\n@endhasUtm\n\n@containsNotUtm('campaign', 'sales')\n  \u003cp\u003eSome not Sales stuff\u003c/p\u003e\n@endhasNotUtm\n```\n\n```php\n if (contains_utm('campaign', 'weekly')) {\n   redirect('to/special/page');\n }\n\n if (contains_not_utm('campaign', 'sale')) {\n   session()-\u003eflash('Did you know, we have a newsletter?');\n }\n```\n\n## Extending the Middleware\n\nYou can extend the middleware to customize the behavior of accepting UTM parameters. For example, you can override the `shouldAcceptUtmParameter` method.\n\nFirst, create a new middleware using Artisan:\n\n```bash\nphp artisan make:middleware CustomMiddleware\n```\n\nThen, update the new middleware to extend UtmParameters and override the `shouldAcceptUtmParameter` method:\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Middleware;\n\nuse Illuminate\\Http\\Request;\nuse Suarez\\UtmParameter\\Middleware\\UtmParameters;\n\nclass CustomMiddleware extends UtmParameters\n{\n    /**\n     * Determines whether the given request/response pair should accept UTM-Parameters.\n     *\n     * @param \\Illuminate\\Http\\Request  $request\n     *\n     * @return bool\n     */\n    protected function shouldAcceptUtmParameter(Request $request)\n    {\n        return $request-\u003eisMethod('GET') || $request-\u003eisMethod('POST');\n    }\n}\n```\n\nFinally, update your `bootstrap/app.php` to use the CustomMiddleware:\n\n```php\n# bootstrap/app.php\nuse App\\Http\\Middleware\\CustomMiddleware;\n\n-\u003ewithMiddleware(function (Middleware $middleware) {\n    $middleware-\u003eweb(append: [\n        CustomMiddleware::class,\n        // other middleware...\n    ]);\n})\n```\n\n## Resources\nExplore additional use cases and resources on the [wiki pages](https://github.com/toni-suarez/laravel-utm-parameter/wiki)\n\n- [Installation Guide](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Installation-Guide)\n- [Installation Guide (Laravel 8.x to 10.x)](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Installation-Guide-(Laravel-8.x-to-10.x))\n- [How it works](https://github.com/toni-suarez/laravel-utm-parameter/wiki/How-it-works)\n- [Limitations](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Limitations)\n- [Advanced Usage](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Advanced-Usage)\n- [Blade Usage](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Blade-Usage)\n- [Usage via Facade or Helper Class](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Usage-via-Facade-or-Helper-Class)\n\n### Inspirations\n- [Use Case: A/B Testing](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Use-Case:-A-B-Testing)\n- [Use Case: Different Styles for Social Media](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Use-Case:-Different-Styles-for-Social-Media)\n- [Use Case: Lead Attribution](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Use-Case:-Lead-Attribution)\n- [Use Case: Social Media Tracking](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Use-Case:-Social-Media-Tracking)\n- [Use‐Case: Newsletter Redirect on Product Detail Page](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Use%E2%80%90Case:-Newsletter-Redirect-on-Product-Detail-Page)\n- [Use‐Case: Offline Marketing Integration](https://github.com/toni-suarez/laravel-utm-parameter/wiki/Use%E2%80%90Case:-Offline-Marketing-Integration)\n\n---\n\n## License\n\nThe Laravel UTM-Parameters package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoni-suarez%2Flaravel-utm-parameter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoni-suarez%2Flaravel-utm-parameter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoni-suarez%2Flaravel-utm-parameter/lists"}