Skip to content

Commit dea677e

Browse files
committed
fix: country icon in analytics page
1 parent aec714c commit dea677e

1 file changed

Lines changed: 71 additions & 1 deletion

File tree

src/Services/AnalyticsService.php

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function getCountriesData($query, bool $withPercentages): array
297297
'name' => $country['country'],
298298
'count' => $country['count'],
299299
'percentage' => $percentage,
300-
'code' => strtolower((string) $country['country']),
300+
'code' => $this->getCountryCode($country['country']),
301301
];
302302
})->toArray();
303303
}
@@ -437,4 +437,74 @@ public function getDurationExpression(string $column): string
437437
default => "TIMESTAMPDIFF(SECOND, MIN({$column}), MAX({$column}))"
438438
};
439439
}
440+
441+
protected function getCountryCode(string $countryName): string
442+
{
443+
$countryMap = [
444+
'Afghanistan' => 'af',
445+
'Albania' => 'al',
446+
'Algeria' => 'dz',
447+
'Argentina' => 'ar',
448+
'Australia' => 'au',
449+
'Austria' => 'at',
450+
'Bangladesh' => 'bd',
451+
'Belgium' => 'be',
452+
'Brazil' => 'br',
453+
'Bulgaria' => 'bg',
454+
'Canada' => 'ca',
455+
'Chile' => 'cl',
456+
'China' => 'cn',
457+
'Colombia' => 'co',
458+
'Croatia' => 'hr',
459+
'Czech Republic' => 'cz',
460+
'Denmark' => 'dk',
461+
'Egypt' => 'eg',
462+
'Finland' => 'fi',
463+
'France' => 'fr',
464+
'Germany' => 'de',
465+
'Greece' => 'gr',
466+
'Hungary' => 'hu',
467+
'Iceland' => 'is',
468+
'India' => 'in',
469+
'Indonesia' => 'id',
470+
'Iran' => 'ir',
471+
'Iraq' => 'iq',
472+
'Ireland' => 'ie',
473+
'Israel' => 'il',
474+
'Italy' => 'it',
475+
'Japan' => 'jp',
476+
'Jordan' => 'jo',
477+
'Kenya' => 'ke',
478+
'Malaysia' => 'my',
479+
'Mexico' => 'mx',
480+
'Netherlands' => 'nl',
481+
'New Zealand' => 'nz',
482+
'Nigeria' => 'ng',
483+
'Norway' => 'no',
484+
'Pakistan' => 'pk',
485+
'Philippines' => 'ph',
486+
'Poland' => 'pl',
487+
'Portugal' => 'pt',
488+
'Romania' => 'ro',
489+
'Russia' => 'ru',
490+
'Saudi Arabia' => 'sa',
491+
'Singapore' => 'sg',
492+
'Slovakia' => 'sk',
493+
'Slovenia' => 'si',
494+
'South Africa' => 'za',
495+
'South Korea' => 'kr',
496+
'Spain' => 'es',
497+
'Sweden' => 'se',
498+
'Switzerland' => 'ch',
499+
'Thailand' => 'th',
500+
'Turkey' => 'tr',
501+
'Ukraine' => 'ua',
502+
'United Arab Emirates' => 'ae',
503+
'United Kingdom' => 'gb',
504+
'United States' => 'us',
505+
'Vietnam' => 'vn',
506+
];
507+
508+
return $countryMap[$countryName] ?? strtolower(substr($countryName, 0, 2));
509+
}
440510
}

0 commit comments

Comments
 (0)