trypost/app/Http/Controllers/Auth/Concerns/PreservesUtmParameters.php
Paulo Castellano 2e9e0f716b feat: capture signup UTMs/IP and add GitHub OAuth login
Persists marketing attribution and registration metadata for new users
across the three signup paths (email, Google, GitHub):

- 5 utm_* columns + registration_ip on the users table
- PreservesUtmParameters trait stores incoming utm_* query params on
  the register/redirect GET, retrieves them on the POST/callback —
  surviving the OAuth round-trip via session
- request()->ip() captured at the controller layer

Adds GitHub as a second OAuth provider:

- GitHubController mirroring the Google one (now renamed from
  SocialLoginController for symmetry)
- Settings → Authentication can connect/disconnect GitHub like Google
- Single SocialLogin.vue component replaces the per-provider buttons
  on Login/Register, rendering each enabled provider plus a single
  "or continue with" divider

UserFactory gains defaults for the new nullable columns so model
strict-mode access in tests doesn't trip.
2026-05-04 18:42:25 -03:00

48 lines
1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Auth\Concerns;
use Illuminate\Http\Request;
trait PreservesUtmParameters
{
private const array UTM_KEYS = [
'utm_source',
'utm_medium',
'utm_campaign',
'utm_term',
'utm_content',
];
/**
* @return array<string, string>
*/
private function extractUtmParameters(Request $request): array
{
return array_filter(
array_map(
fn (string $value) => mb_substr($value, 0, 255),
array_filter($request->only(self::UTM_KEYS), 'is_string'),
),
);
}
private function storeUtmParameters(Request $request): void
{
$utms = $this->extractUtmParameters($request);
if ($utms !== []) {
$request->session()->put('utm_parameters', $utms);
}
}
/**
* @return array<string, string>
*/
private function retrieveUtmParameters(): array
{
return session()->pull('utm_parameters', []);
}
}