diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 5a98fda..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: 2 -updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - time: "04:00" - open-pull-requests-limit: 10 diff --git a/.github/workflows/pack-plugin.yml b/.github/workflows/pack-plugin.yml index 9db39f8..084f157 100644 --- a/.github/workflows/pack-plugin.yml +++ b/.github/workflows/pack-plugin.yml @@ -6,9 +6,9 @@ on: jobs: build: - uses: FriendsOfShopware/workflows/.github/workflows/github.yml@main + uses: FriendsOfShopware/actions/.github/workflows/github.yml@main with: - extensionName: JinyaMatomo - shopwareVersion: 6.4.10 + extensionName: TinectMatomo + shopwareVersion: 6.4.11 secrets: ghToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 484dd71..21070c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -jinya-matomo.js +tinect-matomo.js diff --git a/LICENSE b/LICENSE index 32b76ea..1ce8c69 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Jinya CMS +Copyright (c) 2024 tinect Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b7055b7..6691c96 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,11 @@ # Matomo Shopware 6 Plugin This plugin for Shopware 6 connects your shop to the Open Source and self-hostable Matomo platform. +The plugin is based as fork from [Jinya-CMS/matomo-shopware-plugin](https://github.com/Jinya-CMS/matomo-shopware-plugin). ## Features +* Proxied tracking to prevent blocking * Track page views * Track product views * Track orders - -## Status - -This is in an early development state. diff --git a/composer.json b/composer.json index 69b6928..7c25881 100644 --- a/composer.json +++ b/composer.json @@ -1,22 +1,26 @@ { - "name": "jinya/matomo-shopware-plugin", - "version": "1.0.6", - "description": "Matomo plugin for shopware 6", - "type": "shopware-platform-plugin", - "license": "MIT", - "autoload": { - "psr-4": { - "JinyaMatomo\\": "src/" + "name": "tinect/matomo", + "version": "2.0.0", + "description": "Matomo plugin for shopware 6", + "type": "shopware-platform-plugin", + "license": "MIT", + "autoload": { + "psr-4": { + "Tinect\\Matomo\\": "src/" + } + }, + "require": { + "php": "~8.1||~8.2||~8.3", + "shopware/core": "~6.4.11" + }, + "conflict": { + "jinya/matomo-shopware-plugin": "*" + }, + "extra": { + "shopware-plugin-class": "Tinect\\Matomo\\TinectMatomo", + "label": { + "de-DE": "Matomo Tracking", + "en-GB": "Matomo Tracking" + } } - }, - "require": { - "shopware/core": "~6.4.0" - }, - "extra": { - "shopware-plugin-class": "JinyaMatomo\\JinyaMatomo", - "label": { - "de-DE": "Matomo Tracking", - "en-GB": "Matomo Tracking" - } - } } diff --git a/src/Migration/Migration1710796428MigrateJinyaConfig.php b/src/Migration/Migration1710796428MigrateJinyaConfig.php new file mode 100644 index 0000000..7bb5f71 --- /dev/null +++ b/src/Migration/Migration1710796428MigrateJinyaConfig.php @@ -0,0 +1,32 @@ +fetchAllAssociative('SELECT * FROM system_config WHERE configuration_key LIKE "JinyaMatomo.config.%"'); + + if (count($existingConfig) === 0) { + return; + } + + $connection->executeStatement('DELETE FROM system_config WHERE configuration_key LIKE "TinectMatomo.config.%"'); + $connection->executeStatement('UPDATE system_config SET configuration_key = REPLACE(configuration_key, \'JinyaMatomo.config.\', \'TinectMatomo.config.\') WHERE configuration_key LIKE "JinyaMatomo.config.%"'); + } + + public function updateDestructive(Connection $connection): void + { + } +} diff --git a/src/Resources/config/config.xml b/src/Resources/config/config.xml index da05856..412f705 100644 --- a/src/Resources/config/config.xml +++ b/src/Resources/config/config.xml @@ -1,8 +1,8 @@ + xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/System/SystemConfig/Schema/config.xsd"> - Jinya Matomo Tracking + Tinect Matomo Tracking matomoserver diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 8dcd51c..3e5f495 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -5,12 +5,12 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - + - + diff --git a/src/Resources/views/storefront/base.html.twig b/src/Resources/views/storefront/base.html.twig index a70288c..b13cd6e 100644 --- a/src/Resources/views/storefront/base.html.twig +++ b/src/Resources/views/storefront/base.html.twig @@ -35,12 +35,12 @@ ]); {% endif %} - {% set phpTrackingPath = config("JinyaMatomo.config.phpTrackingPath") %} + {% set phpTrackingPath = config("TinectMatomo.config.phpTrackingPath") %} {% if phpTrackingPath is empty %} {% set phpTrackingPath = 'matomo.php' %} {% endif %} - {% set jsTrackingPath = config("JinyaMatomo.config.jsTrackingPath") %} + {% set jsTrackingPath = config("TinectMatomo.config.jsTrackingPath") %} {% if jsTrackingPath is empty %} {% set jsTrackingPath = 'matomo.js' %} {% endif %} @@ -53,8 +53,8 @@ window._paq.push(['enableLinkTracking']); } - {% set matomoServer = config("JinyaMatomo.config.matomoserver") %} - {% set proxyTracking = config("JinyaMatomo.config.activateProxyTracking") %} + {% set matomoServer = config("TinectMatomo.config.matomoserver") %} + {% set proxyTracking = config("TinectMatomo.config.activateProxyTracking") %} {% if proxyTracking %} {% set trackerUrl = seoUrl('frontend.matomo.proxy') %} {% set trackerJsSrc = seoUrl('frontend.matomo.proxy') %} @@ -65,7 +65,7 @@ {% if matomoServer %} window._paq.push(['setTrackerUrl', '{{ trackerUrl }}']); - window._paq.push(['setSiteId', '{{ config("JinyaMatomo.config.matomosite") }}']); + window._paq.push(['setSiteId', '{{ config("TinectMatomo.config.matomosite") }}']); (function () { const d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; g.type = 'text/javascript'; diff --git a/src/Resources/views/storefront/layout/meta.html.twig b/src/Resources/views/storefront/layout/meta.html.twig index 23588eb..ca5cb5c 100644 --- a/src/Resources/views/storefront/layout/meta.html.twig +++ b/src/Resources/views/storefront/layout/meta.html.twig @@ -2,5 +2,5 @@ {% block layout_head_meta_tags %} {{ parent() }} - + {% endblock %} diff --git a/src/Service/CustomCookieProvider.php b/src/Service/CustomCookieProvider.php index 2a54afd..e1f0a5b 100644 --- a/src/Service/CustomCookieProvider.php +++ b/src/Service/CustomCookieProvider.php @@ -1,6 +1,6 @@ originalService = $service; } public function getCookieGroups(): array diff --git a/src/Storefront/Controller/ProxyController.php b/src/Storefront/Controller/ProxyController.php index a73d23b..a8d1cd2 100644 --- a/src/Storefront/Controller/ProxyController.php +++ b/src/Storefront/Controller/ProxyController.php @@ -1,32 +1,28 @@ systemConfigService = $systemConfigService; - $this->cache = $cache; } /** @@ -39,14 +35,14 @@ public function matomoProxy(Request $request): Response $response = new Response(); $response->headers->set('x-robots-tag', 'noindex,follow'); - $configs = $this->systemConfigService->get('JinyaMatomo.config'); + $configs = $this->systemConfigService->get('TinectMatomo.config'); if (!isset($configs['matomoserver'], $configs['matomoauthtoken'])) { $response->setStatusCode(Response::HTTP_FORBIDDEN); return $response; } - $matomoServer = 'https://' . \rtrim($configs['matomoserver'], '/') . '/'; + $matomoServer = 'https://' . \rtrim((string) $configs['matomoserver'], '/') . '/'; $authToken = $configs['matomoauthtoken']; $parameter = $request->query->all(); @@ -55,18 +51,9 @@ public function matomoProxy(Request $request): Response } $url = $matomoServer . 'matomo.php?cip=' . $this->getClientIp($request) . '&token_auth=' . $authToken . '&'; - /*if (isset($parameter['aname'])) { - $parameter['action_name'] = $parameter['aname']; - unset($parameter['aname']); - } - - if (isset($parameter['ids'])) { - $parameter['idsite'] = $parameter['ids']; - unset($parameter['ids']); - }*/ foreach ($parameter as $key => $value) { - $url .= $key . '=' . urlencode($value) . '&'; + $url .= $key . '=' . urlencode((string) $value) . '&'; } $response->headers->set('Content-Type', 'image/webp'); @@ -117,22 +104,18 @@ private function requestJs(Response $response, string $matomoServer): Response $response->headers->set('Content-Type', 'application/javascript; charset=UTF-8'); $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, '1'); - $cacheItem = $this->cache->getItem('tinectmatomojs'); - - if ($cacheItem->isHit()) { - $matomoJs = CacheCompressor::uncompress($cacheItem); - } else { - $matomoJs = file_get_contents($matomoServer . 'matomo.js'); - $cacheItem = CacheCompressor::compress($cacheItem, $matomoJs); + $cacheValue = $this->cache->get('tinectmatomojs', function (CacheItem $cacheItem) use ($matomoServer) { $cacheItem->expiresAfter(new \DateInterval('PT' . $this->cacheTime . 'S')); - $this->cache->save($cacheItem); - } + return CacheValueCompressor::compress(file_get_contents($matomoServer . 'matomo.js')); + }); + + $matomoJs = CacheValueCompressor::uncompress($cacheValue); if ($matomoJs) { //$matomoJs = str_replace(['"action_name="', 'idsite='], ['"aname="', 'ids='], $matomoJs); $response->setContent($matomoJs); } else { - $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR); + $response->setStatusCode(Response::HTTP_SERVICE_UNAVAILABLE); } return $response; diff --git a/src/JinyaMatomo.php b/src/TinectMatomo.php similarity index 55% rename from src/JinyaMatomo.php rename to src/TinectMatomo.php index 5464d20..e9614f7 100644 --- a/src/JinyaMatomo.php +++ b/src/TinectMatomo.php @@ -1,9 +1,9 @@