{"id":26322960,"url":"https://github.com/devlop/utm-parameters","last_synced_at":"2025-03-15T17:16:02.759Z","repository":{"id":56966969,"uuid":"337368001","full_name":"devlop/utm-parameters","owner":"devlop","description":"Framework agnostic (PSR-7 compatible) UTM parameters helper","archived":false,"fork":false,"pushed_at":"2023-01-07T06:49:03.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T03:11:19.230Z","etag":null,"topics":["php","psr-7","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/devlop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-09T10:28:50.000Z","updated_at":"2023-01-07T06:48:52.000Z","dependencies_parsed_at":"2023-02-06T14:31:51.092Z","dependency_job_id":null,"html_url":"https://github.com/devlop/utm-parameters","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlop%2Futm-parameters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlop%2Futm-parameters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlop%2Futm-parameters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlop%2Futm-parameters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devlop","download_url":"https://codeload.github.com/devlop/utm-parameters/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243762253,"owners_count":20343979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["php","psr-7","utm-parameters"],"created_at":"2025-03-15T17:16:02.140Z","updated_at":"2025-03-15T17:16:02.752Z","avatar_url":"https://github.com/devlop.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/devlop/utm-parameters\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/devlop/utm-parameters\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/devlop/utm-parameters/blob/master/LICENSE.md\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/devlop/utm-parameters\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# UTM Parameters\n\nFramework agnostic (PSR-7 compatible) [UTM parameters](https://en.wikipedia.org/wiki/UTM_parameters) helper, this tool will simplify working with UTM parameters.\n\n# Installation\n\n```\ncomposer require devlop/utm-parameters\n```\n\n# Usage\n\n## Capturing incoming UTM parameters\n\nThe basic idea is to capture incoming UTM parameters from the query and store them in cookies for later use until needed.\n\nCreate a middleware (or similar) following this logic:\n\n```php\nuse Devlop\\UtmParameters\\UtmParameters;\n\n// Capture incoming UTM parameters from the query\n$utmParameters = UtmParameters::capture($request);\n\nif ($utmParameters !== null) {\n    // Remember the UTM parameters in cookies for 30 days\n    $utmParameters-\u003eremember($response, 30);\n}\n```\n\n## Retrieving stored UTM parameters\n\nLater when you need the stored UTM parameters (example, after a registration or a placed order) you can easiliy retrieve them.\n\n```php\nuse Devlop\\UtmParameters\\UtmParameters;\n\n// Retrieve stored UTM parameters from cookies\n$utmParameters = UtmParameters::retrieve($request);\n\nif ($utmParameters !== null) {\n    // do something with the UTM parameters\n    // optionally forget the cookies\n    $utmParameters-\u003eforget($response);\n}\n```\n\n## Available methods\n\nThe `Devlop\\UtmParameters\\UtmParameters` have the following methods available:\n\n`public function getSource() : string`\n\nGet the *utm_source* parameter.\n\n`public function getMedium() : ?string`\n\nGet the *utm_medium* parameter.\n\n`public function getCampaign() : ?string`\n\nGet the *utm_campaign* parameter.\n\n`public function getTerm() : ?string`\n\nGet the *utm_term* parameter.\n\n`public function getContent() : ?string`\n\nGet the *utm_content* parameter.\n\n`public function toArray() : array`\n\nGet all parameters as an array:\n\n```php\n[\n    \"utm_source\" =\u003e \"github\",\n    \"utm_medium\" =\u003e \"email\",\n    \"utm_campaign\" =\u003e \"hackathon_2021\",\n    \"utm_term\" =\u003e null,\n    \"utm_content\" =\u003e null,\n]\n```\n\n## Iterating\n\n`UtmParameters` is iterable:\n\n```php\nforeach ($utmParameters as $parameter =\u003e $value) {\n    // ...\n}\n```\n\n## Constants\n\nAll parameter keys are available as constants on UtmParameters to avoid the need to hardcode any parameter keys in your code.\n\n```php\n$parameters = $utmParameters-\u003etoArray();\n\n$parameters[UtmParameters::SOURCE];\n$parameters[UtmParameters::MEDIUM];\n$parameters[UtmParameters::CAMPAIGN];\n$parameters[UtmParameters::TERM];\n$parameters[UtmParameters::CONTENT];\n```\n\n# Supported requests / responses\n\nWhen `capturing` / `retrieving` UTM parameters these requests are supported.\n\n* [\\Psr\\Http\\Message\\ServerRequestInterface](https://github.com/php-fig/http-message/blob/master/src/ServerRequestInterface.php)\n* [\\Symfony\\Component\\HttpFoundation\\Request](https://github.com/symfony/http-foundation/blob/5.x/Request.php)\n* [\\Laravel\\Http\\Request](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/Request.php)\n\nWhen `remembering` / `forgetting` UTM parameters these responses are supported.\n\n* [\\Psr\\Http\\Message\\MessageInterface](https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php)\n* [\\Symfony\\Component\\HttpFoundation\\Response](https://github.com/symfony/http-foundation/blob/5.x/Response.php)\n* [\\Laravel\\Http\\Response](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/Response.php)\n* [\\Illuminate\\Contracts\\Cookie\\QueueingFactory](https://github.com/laravel/framework/blob/master/src/Illuminate/Contracts/Cookie/QueueingFactory.php)\n\n# Laravel\n\n## Cookies Facade\n\nThe easiest way to `remember` or `forget` stored UTM parameters in Laravel is to use the global `cookie()` helper method to get an instance of QueueingFactory\nto [attach the cookies](https://laravel.com/docs/master/responses#attaching-cookies-to-responses) to the response.\n\n## Middleware\n\n`utm-parameters` ships with a middleware for Laravel for you to use.\n\nAdd the middleware in `app/Http/Kernel.php`, the middleware will automatically capture any incoming UTM parameters and store them in cookies for 30 days.\n\n```php\nnamespace App\\Http;\n\nuse Illuminate\\Foundation\\Http\\Kernel as HttpKernel;\n\nclass Kernel extends HttpKernel\n{\n    /**\n     * The application's route middleware groups.\n     *\n     * @var array\n     */\n    protected $middlewareGroups = [\n        'web' =\u003e [\n            // other configured middleware\n            \\Devlop\\UtmParameters\\Laravel\\StoreUtmParametersInCookies::class,\n        ],\n    ];\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlop%2Futm-parameters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevlop%2Futm-parameters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlop%2Futm-parameters/lists"}