Deploy Ladill Link / deploy (push) Successful in 32s
Record parsed user-agent and geo data on clicks, then surface breakdowns and richer recent-click context on per-link and account analytics views. Co-authored-by: Cursor <cursoragent@cursor.com>
41 lines
986 B
PHP
41 lines
986 B
PHP
<?php
|
|
|
|
namespace App\Support\Link;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
final class LinkGeoResolver
|
|
{
|
|
public static function countryCode(Request $request): ?string
|
|
{
|
|
foreach (['CF-IPCountry', 'X-Country-Code', 'CloudFront-Viewer-Country'] as $header) {
|
|
$value = $request->header($header);
|
|
if (! is_string($value) || strlen($value) !== 2) {
|
|
continue;
|
|
}
|
|
|
|
$code = strtoupper($value);
|
|
if (! in_array($code, ['XX', 'T1'], true)) {
|
|
return $code;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static function countryLabel(?string $code): string
|
|
{
|
|
if ($code === null || $code === '') {
|
|
return 'Unknown';
|
|
}
|
|
|
|
if (function_exists('locale_get_display_region')) {
|
|
$name = locale_get_display_region('_'.$code, 'en');
|
|
|
|
return is_string($name) && $name !== '' ? $name : $code;
|
|
}
|
|
|
|
return $code;
|
|
}
|
|
}
|