1. Go to this page and download the library: Download fsuuaas/utm-tracker library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fsuuaas / utm-tracker example snippets
use Fsuuaas\UtmTracker\Concerns\HasUtm;
use Fsuuaas\UtmTracker\Concerns\SavesUtm;
class Trial extends Model
{
use HasUtm, SavesUtm;
}
$trial->utmRecord; // MorphOne, latest touch — the one you almost always want
$trial->utm; // MorphMany, every row ever recorded for this model
$trial->recordUtm(); // resolve from the current request
$trial->recordUtm(UtmData::fromRecord($lead)); // copy attribution from another model
// Suppress capture for a block — imports, back-fills, admin-created records.
Trial::withoutUtmCapture(function () {
Trial::factory()->count(50)->create();
});
// config/utm-tracker.php
'model' => \Fsuuaas\UtmTracker\Models\UtmRecord::class,
'table' => 'utm_records',
'auto_capture' => true, // record automatically on model creation
'defer_until_commit' => true, // wait for the enclosing transaction to commit
'single_record' => true, // one row per model; false keeps every touch
'record_without_attribution' => true, // false = skip rows with no real campaign
'ip' => 'request', // 'request' | 'anonymize' | 'none'
'cookie_name' => 'utm_data',
'cookie_days' => 365,
'cookie_domain' => null, // e.g. '.example.com' for cross-subdomain attribution
'same_site' => 'Lax',
'mcf_max_touches' => 10,
'direct_handling' => 'first_only', // 'first_only' | 'always' | 'ignore'
'max_bytes' => 3500, // cookie size ceiling before browsers silently drop it
'legacy_cookies' => ['traffic_source'],
'referral_sources' => [
'google' => 'Google', 'fb' => 'Facebook', /* ... */
],
use Fsuuaas\UtmTracker\Fields\Field;
use Fsuuaas\UtmTracker\UtmTracker;
UtmTracker::fields(fn ($registry) => $registry->add(
new Field('fbclid', limit: 255, indexed: true)
));
blade
{{-- once per layout, as early as possible, before analytics tags --}}
<x-utm-tracker::script />