If you want to know how a visitor got on your site you can check the referer request header. Yeah, it's misspelled. That header contains the url of the previously visited page. Unfortunately browsers will fill that header regardless of the previous url was an internal or external one. So after the first click on an internal link you won't know anymore on which site a visitor was on previously.

Our new laravel-referer package aims to fix that problem. Once the package is installed it will remember the original referer in session. So even after a users clicks around on your site, you are still able to detect which site he or she visited previously.

Because users are also often tracked using UTM Codes the package will also remember the utm_source query parameter.

The easiest way to retrieve the referer is by just resolving it out of the container:

use App \ Spatie \ Referer \ Referer ; $referer = app(Referer::class)->get();

Or you could opt to use Laravel's 5.4 fancy new automatic facades:

use Facades \ Spatie \ Referer \ Referer ; $referer = Referer::get();

To know more take a look at the readme of the package on GitHub.

https://github.com/spatie/laravel-referer