Skip to content

Commit

Permalink
feat: move plugin name to TinectMatomo
Browse files Browse the repository at this point in the history
  • Loading branch information
tinect committed Mar 18, 2024
1 parent dcf64aa commit ae74675
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 88 deletions.
8 changes: 0 additions & 8 deletions .github/dependabot.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/pack-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jinya-matomo.js
tinect-matomo.js
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 23 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
32 changes: 32 additions & 0 deletions src/Migration/Migration1710796428MigrateJinyaConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Tinect\Matomo\Migration;

use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Migration\MigrationStep;

class Migration1710796428MigrateJinyaConfig extends MigrationStep
{
public function getCreationTimestamp(): int
{
return 1710796428;
}

public function update(Connection $connection): void
{
$existingConfig = $connection->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
{
}
}
4 changes: 2 additions & 2 deletions src/Resources/config/config.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/master/src/Core/System/SystemConfig/Schema/config.xsd">
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/System/SystemConfig/Schema/config.xsd">
<card>
<title>Jinya Matomo Tracking</title>
<title>Tinect Matomo Tracking</title>
<input-field>
<name>matomoserver</name>
<label>Matomo Server</label>
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="JinyaMatomo\Service\CustomCookieProvider"
<service id="Tinect\Matomo\Service\CustomCookieProvider"
decorates="Shopware\Storefront\Framework\Cookie\CookieProviderInterface">
<argument type="service" id="JinyaMatomo\Service\CustomCookieProvider.inner" />
<argument type="service" id="Tinect\Matomo\Service\CustomCookieProvider.inner" />
</service>

<service id="JinyaMatomo\Storefront\Controller\ProxyController" public="true">
<service id="Tinect\Matomo\Storefront\Controller\ProxyController" public="true">
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
<argument type="service" id="cache.object"/>
<call method="setContainer">
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/views/storefront/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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') %}
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/storefront/layout/meta.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

{% block layout_head_meta_tags %}
{{ parent() }}
<link rel="preconnect" crossorigin href="//{{ config("JinyaMatomo.config.matomoserver") }}">
<link rel="preconnect" crossorigin href="//{{ config("TinectMatomo.config.matomoserver") }}">
{% endblock %}
7 changes: 2 additions & 5 deletions src/Service/CustomCookieProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace JinyaMatomo\Service;
namespace Tinect\Matomo\Service;

use Shopware\Storefront\Framework\Cookie\CookieProviderInterface;

Expand All @@ -20,11 +20,8 @@ class CustomCookieProvider implements CookieProviderInterface
],
];

private CookieProviderInterface $originalService;

public function __construct(CookieProviderInterface $service)
public function __construct(private readonly CookieProviderInterface $originalService)
{
$this->originalService = $service;
}

public function getCookieGroups(): array
Expand Down
51 changes: 17 additions & 34 deletions src/Storefront/Controller/ProxyController.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
<?php declare(strict_types=1);

namespace JinyaMatomo\Storefront\Controller;
namespace Tinect\Matomo\Storefront\Controller;

use Shopware\Core\Framework\Adapter\Cache\CacheCompressor;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\Framework\Adapter\Cache\CacheValueCompressor;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Cache\CacheInterface;

/**
* @RouteScope(scopes={"storefront"})
* @Route(defaults={"_routeScope"={"storefront"}})
*/
class ProxyController extends StorefrontController
{
private SystemConfigService $systemConfigService;

private AdapterInterface $cache;

private int $cacheTime = 86400;

public function __construct(SystemConfigService $systemConfigService, AdapterInterface $cache)
public function __construct(
private readonly SystemConfigService $systemConfigService,
private readonly CacheInterface $cache)
{
$this->systemConfigService = $systemConfigService;
$this->cache = $cache;
}

/**
Expand All @@ -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();
Expand 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');
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/JinyaMatomo.php → src/TinectMatomo.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php declare(strict_types=1);

namespace JinyaMatomo;
namespace Tinect\Matomo;

use Shopware\Core\Framework\Plugin;

class JinyaMatomo extends Plugin
class TinectMatomo extends Plugin
{
}

0 comments on commit ae74675

Please sign in to comment.