{"id":27145449,"url":"https://github.com/elegantengineeringtech/laravel-referrer","last_synced_at":"2026-03-05T10:33:33.769Z","repository":{"id":255436246,"uuid":"849508341","full_name":"ElegantEngineeringTech/laravel-referrer","owner":"ElegantEngineeringTech","description":"Remember the Visitor Referrer Across Requests","archived":false,"fork":false,"pushed_at":"2025-08-18T06:16:53.000Z","size":77,"stargazers_count":12,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-20T23:24:12.306Z","etag":null,"topics":["laravel","laravel-package","php","referrer","referrer-tracking"],"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/ElegantEngineeringTech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"ElegantEngineeringTech"}},"created_at":"2024-08-29T18:01:56.000Z","updated_at":"2025-07-28T06:23:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc58fcc1-ebfa-4926-83ea-c62baa82af11","html_url":"https://github.com/ElegantEngineeringTech/laravel-referrer","commit_stats":null,"previous_names":["elegantengineeringtech/laravel-referrer"],"tags_count":12,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/ElegantEngineeringTech/laravel-referrer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElegantEngineeringTech%2Flaravel-referrer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElegantEngineeringTech%2Flaravel-referrer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElegantEngineeringTech%2Flaravel-referrer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElegantEngineeringTech%2Flaravel-referrer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ElegantEngineeringTech","download_url":"https://codeload.github.com/ElegantEngineeringTech/laravel-referrer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElegantEngineeringTech%2Flaravel-referrer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30119461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T09:35:22.236Z","status":"ssl_error","status_checked_at":"2026-03-05T09:35:20.028Z","response_time":93,"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","laravel-package","php","referrer","referrer-tracking"],"created_at":"2025-04-08T09:48:22.679Z","updated_at":"2026-03-05T10:33:33.740Z","avatar_url":"https://github.com/ElegantEngineeringTech.png","language":"PHP","funding_links":["https://github.com/sponsors/ElegantEngineeringTech"],"categories":[],"sub_categories":[],"readme":"# Remember the Visitor Referrer Across Requests\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/elegantly/laravel-referrer.svg?style=flat-square)](https://packagist.org/packages/elegantly/laravel-referrer)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/ElegantEngineeringTech/laravel-referrer/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/ElegantEngineeringTech/laravel-referrer/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/ElegantEngineeringTech/laravel-referrer/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/ElegantEngineeringTech/laravel-referrer/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/elegantly/laravel-referrer.svg?style=flat-square)](https://packagist.org/packages/elegantly/laravel-referrer)\n\n![laravel-referrer](https://repository-images.githubusercontent.com/849508341/dce87156-6746-4177-8d49-f29e6be7de99)\n\nThis package allows you to detect and store visitor referrers so that you can access them later.\nA typical use case would be saving the referrer in a database when a visitor registers in your app.\n\nOut of the box, it captures:\n\n-   Google Click ID (gclid)\n-   Meta Click ID (fbclid)\n-   TikTok Click ID (ttclid)\n-   Header referrer value\n-   All URL UTM values\n-   Or add your own source\n\nThe package is designed to be highly flexible regarding:\n\n-   How you want to detect the referrer\n-   How you want to store the referrer value\n\nOut of the box, it can store referrer values in:\n\n-   Laravel Context\n-   Laravel Session\n-   A Cookie\n-   Or add your own driver\n\n## Installation\n\nYou can install the package via Composer:\n\n```bash\ncomposer require elegantly/laravel-referrer\n```\n\n## Usage\n\nFirst, publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"referrer-config\"\n```\n\n### Configuration\n\nThen configure your sources and drivers:\n\n```php\nuse Elegantly\\Referrer\\Enums\\Strategy;\n\nreturn [\n    /*\n    |--------------------------------------------------------------------------\n    | Referrer Sources\n    |--------------------------------------------------------------------------\n    |\n    | These classes contain the logic to detect the visitor's referrer.\n    | You can disable specific sources or add as many as needed.\n    | Regardless of the number of sources defined, all values will be stored.\n    |\n    */\n    'sources' =\u003e [\n        \\Elegantly\\Referrer\\Sources\\UtmReferrerSource::class,\n        \\Elegantly\\Referrer\\Sources\\RequestHeaderSource::class,\n        \\Elegantly\\Referrer\\Sources\\GoogleClickIdSource::class,\n        \\Elegantly\\Referrer\\Sources\\MetaClickIdSource::class,\n        \\Elegantly\\Referrer\\Sources\\TikTokClickIdSource::class,\n    ],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Referrer Strategy\n    |--------------------------------------------------------------------------\n    |\n    | Define the strategy for storing referrer values. You can also customize\n    | the strategy for each source.\n    |\n    | 'last'  : Stores only the last captured value, ignoring previous ones.\n    | 'first' : Stores only the first captured value, ignoring subsequent ones.\n    | 'all'   : Stores all captured values.\n    |\n    */\n    'strategy' =\u003e Strategy::All,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Referrer Drivers\n    |--------------------------------------------------------------------------\n    |\n    | These classes contain the logic to store the visitor's referrer.\n    | By default, all drivers are disabled. To enable a driver, uncomment it\n    | or add a custom driver.\n    |\n    | Regardless of the number of drivers defined, they will all store\n    | referrer sources. When accessing referrer data, drivers may be merged,\n    | with the last driver overwriting the others.\n    |\n    | It is recommended to enable at least the Cookie driver for long-term\n    | storage and the Session driver for immediate storage.\n    |\n    */\n    'drivers' =\u003e [\n        // \\Elegantly\\Referrer\\Drivers\\CookieDriver::class =\u003e [\n        //     'name' =\u003e Str::slug(env('APP_NAME', 'laravel'), '_') . '_referrer',\n        //     /**\n        //      * Lifetime in seconds.\n        //      */\n        //     'lifetime' =\u003e 60 * 60 * 24 * 365,\n        // ],\n        // \\Elegantly\\Referrer\\Drivers\\SessionDriver::class =\u003e [\n        //     'key' =\u003e 'referrer',\n        // ],\n        // \\Elegantly\\Referrer\\Drivers\\ContextDriver::class =\u003e [\n        //     'key' =\u003e 'referrer',\n        // ],\n    ],\n];\n```\n\nIn the configuration file, enable one or more drivers by uncommenting them.\n\n### Middleware Configuration\n\nNext, add the `CaptureReferrerMiddleware` to your route:\n\n[Using Laravel v11](https://laravel.com/docs/11.x/middleware#registering-middleware):\n\n```php\nuse Elegantly\\Referrer\\CaptureReferrerMiddleware;\n\n-\u003ewithMiddleware(function (Middleware $middleware) {\n     $middleware-\u003eappend(CaptureReferrerMiddleware::class);\n})\n```\n\n[Using Laravel v10](https://laravel.com/docs/10.x/middleware#global-middleware):\n\n```php\nuse Elegantly\\Referrer\\CaptureReferrerMiddleware;\n\nnamespace App\\Http;\n\nuse Illuminate\\Foundation\\Http\\Kernel as HttpKernel;\n\nclass Kernel extends HttpKernel\n{\n    protected $middlewareGroups = [\n        'web' =\u003e [\n            // ...\n            \\Elegantly\\Referrer\\CaptureReferrerMiddleware::class,\n        ],\n    ];\n}\n```\n\nOnce configured, your referrer sources will be automatically captured.\n\n### Choosing a Strategy\n\nWhat happens when a user encounters multiple referrers during their navigation?\nFor example, a user might click on multiple Google Ads campaigns or links with different UTM parameters.\n\nThis package supports 3 capture strategies:\n\n-   First: Only capture the first referrer of each source\n-   Last: Only capture the last referrer of each source\n-   All: Capture all referrers\n\nFrom the config, you can define a strategy globally using:\n\n```php\nuse Elegantly\\Referrer\\Enums\\Strategy;\n\nreturn [\n    //...\n    'strategy' =\u003e Strategy::Last,\n    //...\n]\n```\n\nYou can also define the strategy per source like this:\n\n```php\nuse Elegantly\\Referrer\\Enums\\Strategy;\n\nreturn [\n    //...\n    'strategy' =\u003e Strategy::Last, // Global strategy\n\n    'sources' =\u003e [\n        \\Elegantly\\Referrer\\Sources\\UtmReferrerSource::class =\u003e [\n            'strategy' =\u003e Strategy::First, // Custom strategy for UTM referrers\n        ],\n        \\Elegantly\\Referrer\\Sources\\RequestHeaderSource::class,\n        \\Elegantly\\Referrer\\Sources\\GoogleClickIdSource::class,\n        \\Elegantly\\Referrer\\Sources\\MetaClickIdSource::class,\n        \\Elegantly\\Referrer\\Sources\\TikTokClickIdSource::class,\n    ],\n    //...\n]\n```\n\n### Retrieving the Visitor Referrer\n\nYou can retrieve the referrer sources using the facade:\n\n```php\nuse \\Elegantly\\Referrer\\Facades\\Referrer;\n\nReferrer::getSources(); // Merges all drivers together, with the last one having priority\nReferrer::getSourcesByDriver(); // Retrieves all driver values\n```\n\nRetrieve the first or last referrer value:\n\n```php\nuse \\Elegantly\\Referrer\\Sources\\UtmReferrerSource;\nuse \\Elegantly\\Referrer\\Sources\\GoogleClickIdSource;\nuse \\Elegantly\\Referrer\\Facades\\Referrer;\n\nReferrer::getSources()-\u003egetFirst(UtmReferrerSource::class);\n// Returns an instance of UtmReferrerSource\n\nReferrer::getSources()-\u003egetLast(GoogleClickIdSource::class);\n// Returns an instance of GoogleClickIdSource\n```\n\nRetrieve the oldest or latest referrer value from any source:\n\n```php\nuse \\Elegantly\\Referrer\\Facades\\Referrer;\n\nReferrer::getSources()-\u003egetOldest();\n// Returns an instance of ReferrerSource\n\nReferrer::getSources()-\u003egetLatest();\n// Returns an instance of ReferrerSource\n```\n\nHere is a complete example inside a controller:\n\n```php\nnamespace App\\Http\\Controllers\\Auth;\n\nuse App\\Http\\Controllers\\Controller;\nuse App\\Http\\Requests\\Auth\\RegisterRequest;\nuse App\\Models\\User;\nuse Illuminate\\Support\\Facades\\Auth;\nuse Elegantly\\Referrer\\Facades\\Referrer;\nuse \\Elegantly\\Referrer\\Sources\\UtmReferrerSource;\n\nclass RegisteredUserController extends Controller\n{\n    public function store(RegisterRequest $request)\n    {\n        $validated = $request-\u003evalidated();\n\n        $user = new User($validated);\n\n        /**\n         * The value returned will be the latest referrer value captured among all sources\n         */\n        $user-\u003ereferrer = (string) Referrer::getSources()-\u003egetLatest();\n\n        /**\n         * The value returned will be the first UTM captured\n         */\n        $user-\u003eutm = (string) Referrer::getSources()-\u003egetFirst(UtmReferrerSource::class);\n\n        $user-\u003esave();\n\n        Auth::login($user);\n\n        return redirect(\"/\");\n    }\n}\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) for information on how to report security vulnerabilities.\n\n## Credits\n\n-   [Quentin Gabriele](https://github.com/QuentinGab)\n-   [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see the [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felegantengineeringtech%2Flaravel-referrer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felegantengineeringtech%2Flaravel-referrer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felegantengineeringtech%2Flaravel-referrer/lists"}