Add GeoIP country fallback for link click analytics.
Deploy Ladill Link / deploy (push) Successful in 39s
Deploy Ladill Link / deploy (push) Successful in 39s
Resolve countries from CDN headers first, then MaxMind GeoLite2 via visitor IP, with an artisan command to download and refresh the database. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -25,6 +25,8 @@ class LinkAnalyticsTest extends TestCase
|
||||
|
||||
public function test_redirect_records_device_browser_os_and_country(): void
|
||||
{
|
||||
config(['link.geoip_database' => base_path('tests/fixtures/GeoLite2-Country-Test.mmdb')]);
|
||||
|
||||
$user = $this->user();
|
||||
ShortLink::create([
|
||||
'user_id' => $user->id,
|
||||
@@ -50,6 +52,30 @@ class LinkAnalyticsTest extends TestCase
|
||||
$this->assertSame('GH', $click->country);
|
||||
}
|
||||
|
||||
public function test_redirect_records_country_from_ip_when_proxy_header_missing(): void
|
||||
{
|
||||
config(['link.geoip_database' => base_path('tests/fixtures/GeoLite2-Country-Test.mmdb')]);
|
||||
|
||||
$user = $this->user();
|
||||
ShortLink::create([
|
||||
'user_id' => $user->id,
|
||||
'slug' => 'geo-ip',
|
||||
'source_app' => 'link',
|
||||
'source_kind' => 'redirect',
|
||||
'is_managed_here' => true,
|
||||
'destination_url' => 'https://example.com/target',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->withServerVariables(['REMOTE_ADDR' => '81.2.69.142'])
|
||||
->withHeaders([
|
||||
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||
])->get('https://ladl.link/geo-ip')
|
||||
->assertRedirect('https://example.com/target');
|
||||
|
||||
$this->assertSame('GB', LinkClick::first()?->country);
|
||||
}
|
||||
|
||||
public function test_breakdown_for_link_groups_clicks_by_device(): void
|
||||
{
|
||||
$user = $this->user();
|
||||
|
||||
Reference in New Issue
Block a user