mirror of
https://github.com/shlinkio/shlink.git
synced 2025-12-10 11:05:50 -06:00
Merge pull request #2392 from wuuei/patch-1
Fix Matomo country logging by sending country code instead of country
This commit is contained in:
commit
bc77750713
@ -24,7 +24,7 @@
|
||||
"doctrine/migrations": "^3.8",
|
||||
"doctrine/orm": "^3.3",
|
||||
"donatj/phpuseragentparser": "^1.10",
|
||||
"endroid/qr-code": "^6.0",
|
||||
"endroid/qr-code": "<6.0.4",
|
||||
"friendsofphp/proxy-manager-lts": "^1.0",
|
||||
"geoip2/geoip2": "^3.1",
|
||||
"guzzlehttp/guzzle": "^7.9",
|
||||
|
||||
@ -11,6 +11,8 @@ use Shlinkio\Shlink\Core\Visit\Entity\Visit;
|
||||
use Shlinkio\Shlink\Core\Visit\Repository\VisitIterationRepositoryInterface;
|
||||
use Throwable;
|
||||
|
||||
use function strtolower;
|
||||
|
||||
readonly class MatomoVisitSender implements MatomoVisitSenderInterface
|
||||
{
|
||||
public function __construct(
|
||||
@ -60,7 +62,7 @@ readonly class MatomoVisitSender implements MatomoVisitSenderInterface
|
||||
if ($location !== null) {
|
||||
$tracker
|
||||
->setCity($location->cityName)
|
||||
->setCountry($location->countryName)
|
||||
->setCountry(strtolower($location->countryCode))
|
||||
->setLatitude($location->latitude)
|
||||
->setLongitude($location->longitude);
|
||||
}
|
||||
|
||||
@ -43,6 +43,9 @@ class MatomoVisitSenderTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideTrackerMethods')]
|
||||
/**
|
||||
* @param array<string, string[]> $invokedMethods
|
||||
*/
|
||||
public function visitIsSentToMatomo(Visit $visit, string|null $originalIpAddress, array $invokedMethods): void
|
||||
{
|
||||
$tracker = $this->createMock(MatomoTracker::class);
|
||||
@ -66,8 +69,8 @@ class MatomoVisitSenderTest extends TestCase
|
||||
)->willReturn($tracker);
|
||||
}
|
||||
|
||||
foreach ($invokedMethods as $invokedMethod) {
|
||||
$tracker->expects($this->once())->method($invokedMethod)->willReturn($tracker);
|
||||
foreach ($invokedMethods as $invokedMethod => $args) {
|
||||
$tracker->expects($this->once())->method($invokedMethod)->with(...$args)->willReturn($tracker);
|
||||
}
|
||||
|
||||
$this->trackerBuilder->expects($this->once())->method('buildMatomoTracker')->willReturn($tracker);
|
||||
@ -81,18 +84,28 @@ class MatomoVisitSenderTest extends TestCase
|
||||
yield 'located regular visit' => [
|
||||
Visit::forValidShortUrl(ShortUrl::withLongUrl('https://shlink.io'), Visitor::empty())
|
||||
->locate(VisitLocation::fromGeolocation(new Location(
|
||||
countryCode: 'countryCode',
|
||||
countryCode: 'US',
|
||||
countryName: 'countryName',
|
||||
regionName: 'regionName',
|
||||
city: 'city',
|
||||
latitude: 123,
|
||||
longitude: 123,
|
||||
longitude: 456,
|
||||
timeZone: 'timeZone',
|
||||
))),
|
||||
'1.2.3.4',
|
||||
['setCity', 'setCountry', 'setLatitude', 'setLongitude', 'setIp'],
|
||||
[
|
||||
'setCity' => ['city'],
|
||||
'setCountry' => ['us'],
|
||||
'setLatitude' => [123],
|
||||
'setLongitude' => [456],
|
||||
'setIp' => ['1.2.3.4'],
|
||||
],
|
||||
];
|
||||
yield 'fallback IP' => [
|
||||
Visit::forBasePath(Visitor::fromParams(remoteAddress: '5.6.7.8')),
|
||||
null,
|
||||
['setIp' => ['5.6.7.0']],
|
||||
];
|
||||
yield 'fallback IP' => [Visit::forBasePath(Visitor::fromParams(remoteAddress: '1.2.3.4')), null, ['setIp']];
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideUrlsToTrack')]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user