-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use messenger to track proxied requests
- Loading branch information
Showing
12 changed files
with
234 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
{ | ||
"name": "tinect/matomo", | ||
"version": "4.2.0", | ||
"description": "Matomo plugin for shopware 6", | ||
"type": "shopware-platform-plugin", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Tinect\\Matomo\\": "src/" | ||
"name": "tinect/matomo", | ||
"version": "4.2.0", | ||
"description": "Matomo plugin for shopware 6", | ||
"type": "shopware-platform-plugin", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Tinect\\Matomo\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"shopware/core": "~6.6.0", | ||
"shopware/storefront": "*" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan-deprecation-rules": "^1.1" | ||
}, | ||
"conflict": { | ||
"jinya/matomo-shopware-plugin": "*" | ||
}, | ||
"extra": { | ||
"shopware-plugin-class": "Tinect\\Matomo\\TinectMatomo", | ||
"label": { | ||
"de-DE": "Matomo Tracking", | ||
"en-GB": "Matomo Tracking" | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"symfony/runtime": true | ||
} | ||
}, | ||
"scripts": { | ||
"phpstan": [ | ||
"vendor/bin/phpstan analyze $1" | ||
] | ||
} | ||
}, | ||
"require": { | ||
"shopware/core": "~6.6.0" | ||
}, | ||
"conflict": { | ||
"jinya/matomo-shopware-plugin": "*" | ||
}, | ||
"extra": { | ||
"shopware-plugin-class": "Tinect\\Matomo\\TinectMatomo", | ||
"label": { | ||
"de-DE": "Matomo Tracking", | ||
"en-GB": "Matomo Tracking" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-deprecation-rules/rules.neon | ||
|
||
parameters: | ||
level: max | ||
paths: | ||
- src | ||
checkGenericClassInNonGenericObjectType: false | ||
|
||
excludePaths: | ||
- ecs.php | ||
- vendor | ||
- **/tests/** | ||
|
||
ignoreErrors: | ||
- | ||
message: """ | ||
#no value type specified in iterable type array# | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tinect\Matomo\MessageQueue; | ||
|
||
use Shopware\Core\System\SystemConfig\SystemConfigService; | ||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
use Tinect\Matomo\Service\StaticHelper; | ||
|
||
#[AsMessageHandler] | ||
class TrackHandler | ||
{ | ||
public function __construct( | ||
private readonly SystemConfigService $systemConfigService | ||
) { | ||
} | ||
|
||
public function __invoke(TrackMessage $message): void | ||
{ | ||
$authToken = $this->systemConfigService->getString('TinectMatomo.config.matomoauthtoken'); | ||
|
||
if ($authToken === '') { | ||
return; | ||
} | ||
|
||
$matomoUrl = StaticHelper::getMatomoUrl($this->systemConfigService); | ||
|
||
if ($matomoUrl === null) { | ||
return; | ||
} | ||
|
||
$matomoUrl .= 'matomo.php?'; | ||
|
||
$parameter = $message->parameters; | ||
$parameter['cdt'] = $message->unixTimestamp; | ||
$parameter['token_auth'] = $authToken; | ||
|
||
if (!empty($message->clientIp) && $message->clientIp !== '::1') { | ||
$parameter['cip'] = $message->clientIp; | ||
} | ||
|
||
foreach ($parameter as $key => $value) { | ||
$matomoUrl .= $key . '=' . urlencode((string) $value) . '&'; | ||
} | ||
|
||
$stream_options = ['http' => [ | ||
'user_agent' => $message->userAgent, | ||
'header' => 'Accept-Language: ' . str_replace(["\n", "\t", "\r"], '', $message->acceptLanguage) . "\r\n", | ||
'timeout' => 5, | ||
]]; | ||
$ctx = stream_context_create($stream_options); | ||
|
||
file_get_contents($matomoUrl, false, $ctx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tinect\Matomo\MessageQueue; | ||
|
||
use Shopware\Core\Framework\MessageQueue\LowPriorityMessageInterface; | ||
|
||
class TrackMessage implements LowPriorityMessageInterface | ||
{ | ||
public function __construct( | ||
public readonly ?string $clientIp, | ||
public readonly string $userAgent, | ||
public readonly string $acceptLanguage, | ||
public readonly int $unixTimestamp, | ||
public readonly array $parameters, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tinect\Matomo\Migration; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Shopware\Core\Framework\Migration\MigrationStep; | ||
|
||
class Migration1714244310CompleteMatomoServer extends MigrationStep | ||
{ | ||
public function getCreationTimestamp(): int | ||
{ | ||
return 1714244310; | ||
} | ||
|
||
public function update(Connection $connection): void | ||
{ | ||
$connection->executeStatement('UPDATE system_config SET | ||
configuration_value = JSON_SET(configuration_value, "$._value", CONCAT("https://", JSON_UNQUOTE(JSON_EXTRACT(configuration_value, "$._value")))) | ||
WHERE configuration_key = "TinectMatomo.config.matomoserver" AND | ||
JSON_UNQUOTE(JSON_EXTRACT(configuration_value, "$._value")) NOT LIKE "http%"'); | ||
} | ||
|
||
public function updateDestructive(Connection $connection): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tinect\Matomo\Service; | ||
|
||
use Shopware\Core\System\SystemConfig\SystemConfigService; | ||
|
||
class StaticHelper | ||
{ | ||
public static function getMatomoUrl(SystemConfigService $systemConfigService): ?string | ||
{ | ||
$matomoServer = $systemConfigService->getString('TinectMatomo.config.matomoserver'); | ||
|
||
if ($matomoServer === '') { | ||
return null; | ||
} | ||
|
||
return \rtrim($matomoServer, '/') . '/'; | ||
} | ||
} |
Oops, something went wrong.