From dfab91a71afd1bcfc9ee60a3463b3f80aab5127a Mon Sep 17 00:00:00 2001 From: MaxBUhe Date: Thu, 19 Jan 2023 15:31:56 +0100 Subject: [PATCH] adding missing standard-files; rebranding and moving ViewConfig extension --- .php-cs-fixer.php | 13 + Application/Extend/.ide-helper.php | 5 - CHANGELOG.md | 30 +++ IntelliSenseHelper.php | 18 ++ .../Extend => Modules/Core}/ViewConfig.php | 244 +++++++++--------- README.md | 118 ++++----- __README.md | 67 +++++ composer.json | 30 ++- metadata.php | 32 +-- phpstan.neon | 10 + phpunit.xml | 20 ++ 11 files changed, 377 insertions(+), 210 deletions(-) create mode 100644 .php-cs-fixer.php delete mode 100644 Application/Extend/.ide-helper.php create mode 100644 CHANGELOG.md create mode 100644 IntelliSenseHelper.php rename {Application/Extend => Modules/Core}/ViewConfig.php (96%) mode change 100755 => 100644 mode change 100755 => 100644 README.md create mode 100644 __README.md create mode 100644 phpstan.neon create mode 100644 phpunit.xml diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..f0512a0 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,13 @@ +in(__DIR__) +; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@PHP73Migration' => true, + '@PSR12' => true + ]) + ->setFinder($finder) +; \ No newline at end of file diff --git a/Application/Extend/.ide-helper.php b/Application/Extend/.ide-helper.php deleted file mode 100644 index 75eb3c4..0000000 --- a/Application/Extend/.ide-helper.php +++ /dev/null @@ -1,5 +0,0 @@ - + * @link http://www.oxidmodule.com + */ + +namespace D3\GoogleAnalytics4\Modules\Core{ + class ViewConfig_parent extends \OxidEsales\Eshop\Core\ViewConfig{} +} \ No newline at end of file diff --git a/Application/Extend/ViewConfig.php b/Modules/Core/ViewConfig.php old mode 100755 new mode 100644 similarity index 96% rename from Application/Extend/ViewConfig.php rename to Modules/Core/ViewConfig.php index 141dac2..ca5cc37 --- a/Application/Extend/ViewConfig.php +++ b/Modules/Core/ViewConfig.php @@ -1,123 +1,123 @@ - - */ - -namespace VanillaThunder\GoogleTagManager\Application\Extend; - -use OxidEsales\Eshop\Application\Controller\FrontendController; -use OxidEsales\Eshop\Core\Registry; -use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; -use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface; - -class ViewConfig extends ViewConfig_parent -{ - - // Google Tag Manager Container ID - private $sContainerId = null; - - public function getGtmContainerId() - { - if ($this->sContainerId === null) - { - $this->sContainerId = $this->getConfig()->getConfigParam('vt_gtm_sContainerID'); - } - return $this->sContainerId; - } - - private $blGA4enabled = null; - - public function isGA4enabled() - { - if ($this->blGA4enabled === null) - { - $this->sContainerId = $this->getConfig()->getConfigParam('vt_gtm_blEnableGA4'); - } - - return $this->blGA4enabled; - } - - public function getGtmDataLayer() - { - if (!$this->getGtmContainerId()) return "[]"; - - $oConfig = Registry::getConfig(); - $oView = $oConfig->getTopActiveView(); - /** @var FrontendController $oShop */ - //$oShop = oxRegistry::getConfig()->getActiveShop(); /** @var oxShop $oShop */ - $oUser = $oConfig->getUser(); - - $cl = $this->getTopActionClassName(); - $aPageTypes = [ - "content" => "cms", - "details" => "product", - "alist" => "listing", - "search" => "listing", - "basket" => "checkout", - "user" => "checkout", - "payment" => "checkout", - "order" => "checkout", - "thankyou" => "checkout", - ]; - - $dataLayer = [ - 'page' => [ - 'type' => $aPageTypes[$cl] ?? "unknown", - 'title' => $oView->getTitle(), - 'cl' => $cl, - ], - 'userid' => ($oUser ? $oUser->getId() : false), - 'sessionid' => session_id() ?? false, - //'httpref' => $_SERVER["HTTP_REFERER"] ?? "unknown" - ]; - - #return json_encode([$dataLayer], JSON_PRETTY_PRINT); - - unset($dataLayer["user"]["http"]); // das brauchen wir hier nicht - - - return json_encode([$dataLayer], JSON_PRETTY_PRINT); - /* - // --- Produktdaten --- - $transactionProducts = []; - foreach($oOrder->getOrderArticles() as $_prod ) $transactionProducts[] = [ - 'name' => '', // (erforderlich) Produktname String - 'sku' => '', // (erforderlich) Produkt-SKU String - 'category' => '', // (optional) Produktkategorie String - 'price' => '', // (erforderlich) Preis pro Einheit Numerischer Wert - 'quantity' => '' // (erforderlich) Anzahl der Artikel Numerischer Wert - ]; - - // --- Transaktionsdaten --- - - $dataLayer['transactionId'] = $oOrder->oxorder__oxordernr->value; // (erforderlich) Eindeutige Transaktionskennung String - $dataLayer['transactionAffiliation'] = $oShop->oxshops__oxname->value; // (optional) Partner oder Geschäft String - $dataLayer['transactionTotal'] = $oOrder->oxorder__oxtotalordersum->value; // (erforderlich) Gesamtwert der Transaktion Numerischer Wert - $dataLayer['transactionShipping'] = $oOrder->oxorder__oxdelcost->value; // (optional) Versandkosten für die Transaktion Numerischer Wert - $dataLayer['transactionTax'] = ''; // (optional) Steuerbetrag für die Transaktion Numerischer Wert - $dataLayer['transactionProducts'] = $transactionProducts; // (optional) Liste der bei der Transaktion erworbenen Artikel Array von Produktobjekten - */ - } - - public function triggerGA4events() - { - // general events - - } - - public function isPromotionList($listId) - { - $oConfig = Registry::getConfig(); - $aPromotionListIds = $oConfig->getConfigParam("") ?? ['bargainItems', 'newItems', 'topBox', 'alsoBought', 'accessories', 'cross']; - } + + */ + +namespace D3\GoogleAnalytics4\Modules\Core; + +use OxidEsales\Eshop\Application\Controller\FrontendController; +use OxidEsales\Eshop\Core\Registry; +use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface; + +class ViewConfig extends ViewConfig_parent +{ + + // Google Tag Manager Container ID + private $sContainerId = null; + + public function getGtmContainerId() + { + if ($this->sContainerId === null) + { + $this->sContainerId = $this->getConfig()->getConfigParam('vt_gtm_sContainerID'); + } + return $this->sContainerId; + } + + private $blGA4enabled = null; + + public function isGA4enabled() + { + if ($this->blGA4enabled === null) + { + $this->sContainerId = $this->getConfig()->getConfigParam('vt_gtm_blEnableGA4'); + } + + return $this->blGA4enabled; + } + + public function getGtmDataLayer() + { + if (!$this->getGtmContainerId()) return "[]"; + + $oConfig = Registry::getConfig(); + $oView = $oConfig->getTopActiveView(); + /** @var FrontendController $oShop */ + //$oShop = oxRegistry::getConfig()->getActiveShop(); /** @var oxShop $oShop */ + $oUser = $oConfig->getUser(); + + $cl = $this->getTopActionClassName(); + $aPageTypes = [ + "content" => "cms", + "details" => "product", + "alist" => "listing", + "search" => "listing", + "basket" => "checkout", + "user" => "checkout", + "payment" => "checkout", + "order" => "checkout", + "thankyou" => "checkout", + ]; + + $dataLayer = [ + 'page' => [ + 'type' => $aPageTypes[$cl] ?? "unknown", + 'title' => $oView->getTitle(), + 'cl' => $cl, + ], + 'userid' => ($oUser ? $oUser->getId() : false), + 'sessionid' => session_id() ?? false, + //'httpref' => $_SERVER["HTTP_REFERER"] ?? "unknown" + ]; + + #return json_encode([$dataLayer], JSON_PRETTY_PRINT); + + unset($dataLayer["user"]["http"]); // das brauchen wir hier nicht + + + return json_encode([$dataLayer], JSON_PRETTY_PRINT); + /* + // --- Produktdaten --- + $transactionProducts = []; + foreach($oOrder->getOrderArticles() as $_prod ) $transactionProducts[] = [ + 'name' => '', // (erforderlich) Produktname String + 'sku' => '', // (erforderlich) Produkt-SKU String + 'category' => '', // (optional) Produktkategorie String + 'price' => '', // (erforderlich) Preis pro Einheit Numerischer Wert + 'quantity' => '' // (erforderlich) Anzahl der Artikel Numerischer Wert + ]; + + // --- Transaktionsdaten --- + + $dataLayer['transactionId'] = $oOrder->oxorder__oxordernr->value; // (erforderlich) Eindeutige Transaktionskennung String + $dataLayer['transactionAffiliation'] = $oShop->oxshops__oxname->value; // (optional) Partner oder Geschäft String + $dataLayer['transactionTotal'] = $oOrder->oxorder__oxtotalordersum->value; // (erforderlich) Gesamtwert der Transaktion Numerischer Wert + $dataLayer['transactionShipping'] = $oOrder->oxorder__oxdelcost->value; // (optional) Versandkosten für die Transaktion Numerischer Wert + $dataLayer['transactionTax'] = ''; // (optional) Steuerbetrag für die Transaktion Numerischer Wert + $dataLayer['transactionProducts'] = $transactionProducts; // (optional) Liste der bei der Transaktion erworbenen Artikel Array von Produktobjekten + */ + } + + public function triggerGA4events() + { + // general events + + } + + public function isPromotionList($listId) + { + $oConfig = Registry::getConfig(); + $aPromotionListIds = $oConfig->getConfigParam("") ?? ['bargainItems', 'newItems', 'topBox', 'alsoBought', 'accessories', 'cross']; + } } \ No newline at end of file diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 4d49dd8..d1db9e8 --- a/README.md +++ b/README.md @@ -1,68 +1,70 @@ -# [vt] Google Tag Manager -Google Tag Manager integration for OXID eShop v6.2 und höher -module version 0.5.0 ( 2021-12-10 ) +[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md) + +# ![D3 Logo](https://logos.oxidmodule.com/d3logo_24x24.svg) Google-Analytics 4 für OXID eShop + +Google-Analytics 4 integration via 'Google Tag Manager' für den OXID eShop 6.x + +## Inhaltsverzeichnis + +- [Installation](#installation) +- [Verwendung](#verwendung) +- [Changelog](#changelog) +- [Lizenz](#lizenz) ## Installation -* ``composer require vanilla-thunder/oxid-module-gtm --no-update`` -* Modul aktivieren und Moduleinstellungen konfigurieren -## Tag Manager konfigurieren: -+ https://support.google.com/tagmanager/answer/9442095 +Dieses Paket erfordert einen mit Composer installierten OXID eShop in einer in der [composer.json](composer.json) definierten Version. -## Google Analytics 4 Einrichtung +Bitte tragen Sie den folgenden Abschnitt in die `composer.json` Ihres Projektes ein: -## GA4 Events / Customizing -für alle implementierten GA4 Events existieren Templates unter `source/modules/GoogleTagManager/Application/views/ga4/`, dabei entspricht der Dateiname dem Eventnamen in GA4. -Die Einbindung dieser Event-Templates erfolgt über TPL-Blöcke unter `source/modules/GoogleTagManager/Application/views/blocks/`. +``` + "extra": { + ... + } +``` -### aktuell zu beachtende Blöcke -- Suchergebnisse: search_results -- (muss hinzugefügt werden) aList: d3Ga4_view_item_list -- Detailseite: details_productmain_title -- add_to_basket-button: details_productmain_tobasket -- Warenkorb: checkout_basket_main -- Purchase | abgeschlossener Kauf: checkout_thankyou_main - -## Universal Analytics Events - -**"EE-Trigger" für Ecomemrce-Tags (Beispiel für Google Tag Manager):** -+ Triggertyp: Benutzerdefiniertes Ereignis -+ Ereignisname: ``ee\..*`` -+ Übereinstimmung mit regulärem Ausdruck verwenden -+ Diesen Trigger auslösen bei: Alle benutzerdefinierten Ereignisse - -**"EE-Tag" für Google Analytics Enhanced Ecommerce:** -+ Tag-Typ: Google Analytics - Universal Analytics -+ Tracking-Typ: Ereignis -+ Aktion: {{Event}} -+ Label: {{Event Label}} -+ Trigger : EE-Trigger - -## Verfügbare Datalayer Variablen -Für die einfachste Übersicht der enthaltenen Daten empfehle ich den Vorschau-Modus vom Google Tag Manager. - -Bei jedem Seitenaufruf wird die Datenschicht mit einigen wenigen Infos erstellt, die man zum reinen Erfassen der Seitenaufrufe benötigt: - + **page.type** - Seitentyp: default / cms / product / listing / checkout (an google analytics angelehnt) - + **page.title** - Seitentitel (außer Startseite, sie hat keinen Titel. Danke OXID...) - + **page.cl** - OXID Controller Klasse (start, search, etc) - + **userid** - oxID vom Benutzer bzw `false` falls nicht eingeloggt - + **sessionid** - session iD - -Alle für Ecommerce Tracking releavanten Daten werden mit speziellen Ecommerce Events in die Datenschicht eingefügt. -Hier ist ein Beispiel für die Einrichtung von Enhanced Ecomemrce Tracking über Google Tag Manager: +Öffnen Sie eine Kommandozeile und navigieren Sie zum Stammverzeichnis des Shops (Elternverzeichnis von source und vendor). Führen Sie den folgenden Befehl aus. Passen Sie die Pfadangaben an Ihre Installationsumgebung an. +```bash +php composer require d3/modulename:^2.0 +``` +Sofern nötig, bestätigen Sie bitte, dass Sie `package-name` erlauben, Code auszuführen. -### LICENSE AGREEMENT - [vt] google-tag-manager - Copyright (C) 2021 Marat Bedoev - info: info@mb-dev.pro oder so /** @todo: überarbeiten, wenn ich wieder nüchtern bin */ - - This program is free software; - you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; - either version 3 of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program; if not, see \ No newline at end of file +Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module". + +## Verwendung + +... + +## Changelog + +Siehe [CHANGELOG](CHANGELOG.md) für weitere Informationen. + +## Beitragen + +Wenn Sie eine Verbesserungsvorschlag haben, legen Sie einen Fork des Repositories an und erstellen Sie einen Pull Request. Alternativ können Sie einfach ein Issue erstellen. Fügen Sie das Projekt zu Ihren Favoriten hinzu. Vielen Dank. + +- Erstellen Sie einen Fork des Projekts +- Erstellen Sie einen Feature Branch (git checkout -b feature/AmazingFeature) +- Fügen Sie Ihre Änderungen hinzu (git commit -m 'Add some AmazingFeature') +- Übertragen Sie den Branch (git push origin feature/AmazingFeature) +- Öffnen Sie einen Pull Request + +## Lizenz +(Stand: 06.05.2021) + +Vertrieben unter der GPLv3 Lizenz. + +``` +Copyright (c) D3 Data Development (Inh. Thomas Dartsch) + +Diese Software wird unter der GNU GENERAL PUBLIC LICENSE Version 3 vertrieben. +``` + +Die vollständigen Copyright- und Lizenzinformationen entnehmen Sie bitte der [LICENSE](LICENSE.md)-Datei, die mit diesem Quellcode verteilt wurde. + +## weitere Lizenzen und Nutzungsbedingungen + +... \ No newline at end of file diff --git a/__README.md b/__README.md new file mode 100644 index 0000000..dadb102 --- /dev/null +++ b/__README.md @@ -0,0 +1,67 @@ +# [D3] Google Tag Manager +Google Tag Manager integration for OXID eShop v6.x + +## Installation +* ``composer require vanilla-thunder/oxid-module-gtm --no-update`` +* Modul aktivieren und Moduleinstellungen konfigurieren + +## Tag Manager konfigurieren: ++ https://support.google.com/tagmanager/answer/9442095 + +## Google Analytics 4 Einrichtung + +## GA4 Events / Customizing +für alle implementierten GA4 Events existieren Templates unter `source/modules/GoogleTagManager/Application/views/ga4/`, dabei entspricht der Dateiname dem Eventnamen in GA4. +Die Einbindung dieser Event-Templates erfolgt über TPL-Blöcke unter `source/modules/GoogleTagManager/Application/views/blocks/`. + +### aktuell zu beachtende Blöcke +- Suchergebnisse: search_results +- (muss hinzugefügt werden) aList: d3Ga4_view_item_list +- Detailseite: details_productmain_title +- add_to_basket-button: details_productmain_tobasket +- Warenkorb: checkout_basket_main +- Purchase | abgeschlossener Kauf: checkout_thankyou_main + +## Universal Analytics Events + +**"EE-Trigger" für Ecomemrce-Tags (Beispiel für Google Tag Manager):** ++ Triggertyp: Benutzerdefiniertes Ereignis ++ Ereignisname: ``ee\..*`` ++ Übereinstimmung mit regulärem Ausdruck verwenden ++ Diesen Trigger auslösen bei: Alle benutzerdefinierten Ereignisse + +**"EE-Tag" für Google Analytics Enhanced Ecommerce:** ++ Tag-Typ: Google Analytics - Universal Analytics ++ Tracking-Typ: Ereignis ++ Aktion: {{Event}} ++ Label: {{Event Label}} ++ Trigger : EE-Trigger + +## Verfügbare Datalayer Variablen +Für die einfachste Übersicht der enthaltenen Daten empfehle ich den Vorschau-Modus vom Google Tag Manager. + +Bei jedem Seitenaufruf wird die Datenschicht mit einigen wenigen Infos erstellt, die man zum reinen Erfassen der Seitenaufrufe benötigt: + + **page.type** - Seitentyp: default / cms / product / listing / checkout (an google analytics angelehnt) + + **page.title** - Seitentitel (außer Startseite, sie hat keinen Titel. Danke OXID...) + + **page.cl** - OXID Controller Klasse (start, search, etc) + + **userid** - oxID vom Benutzer bzw `false` falls nicht eingeloggt + + **sessionid** - session iD + +Alle für Ecommerce Tracking releavanten Daten werden mit speziellen Ecommerce Events in die Datenschicht eingefügt. +Hier ist ein Beispiel für die Einrichtung von Enhanced Ecomemrce Tracking über Google Tag Manager: + + + + +### LICENSE AGREEMENT + [vt] google-tag-manager + Copyright (C) 2021 Marat Bedoev + info: info@mb-dev.pro oder so /** @todo: überarbeiten, wenn ich wieder nüchtern bin */ + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 3 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program; if not, see \ No newline at end of file diff --git a/composer.json b/composer.json index 01488f1..8de7545 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,20 @@ { - "name": "vanilla-thunder/oxid-module-gtm", - "description": "Google Tag Manager with new Google Analytics 4 for OXID eShop v6.2+
more about GA4: Ecommerce (GA4) Developer Guide", + "name": "d3/google-analytics4", + "description": "Google Tag Manager with new Google Analytics 4 for OXID eShop 6.x", "type": "oxideshop-module", - "homepage": "https://github.com/vanilla-thunder/oxid-module-gtm", + "keywords": [ + "oxid", + "modules", + "eShop", + "d3", + "google", + "ga4", + "googleanalytics", + "gtm", + "configuration", + "license" + ], + "homepage": "https://www.d3data.de", "license": [ "GPL-3.0" ], @@ -10,11 +22,19 @@ { "name": "Marat Bedoev", "email": "hello@mb-dev.pro" + }, + { + "name": "D3 Data Development (Inh. Thomas Dartsch)", + "email": "info@shopmodule.com", + "homepage": "https://www.d3data.de" } ], + "support": { + "email": "support@shopmodule.com" + }, "extra": { "oxideshop": { - "target-directory": "vt/GoogleTagManager" + "target-directory": "d3/googleanalytics" } }, "require": { @@ -24,7 +44,7 @@ }, "autoload": { "psr-4": { - "VanillaThunder\\": "../../../source/modules/vt" + "D3\\GoogleAnalytics4": "../../../source/modules/d3/googleanalytics" } } } \ No newline at end of file diff --git a/metadata.php b/metadata.php index 35368ce..5a001fd 100755 --- a/metadata.php +++ b/metadata.php @@ -1,29 +1,21 @@ - **/ + + +use D3\GoogleAnalytics4\Modules\Core\ViewConfig; +use OxidEsales\Eshop\Core\ViewConfig as OEViewConfig; $sMetadataVersion = '2.1'; $aModule = [ - 'id' => 'vt-gtm', - 'title' => '[vt] Google Tag Manager', - 'description' => 'Google Tag Manager Integration for OXID eShop v6.2+', + 'id' => 'd3googleanalytics4', + 'title' => 'Google Analytics 4', + 'description' => 'Integration erfolgt via GoogleTagmanager und gtags.', 'thumbnail' => 'thumbnail.png', - 'version' => '0.5.0 ( 2021-07-17 )', - 'author' => 'Marat Bedoev', - 'email' => openssl_decrypt("Az6pE7kPbtnTzjHlPhPCa4ktJLphZ/w9gKgo5vA//p4=", str_rot13("nrf-128-pop"), str_rot13("gvalzpr")), - 'url' => 'https://github.com/vanilla-thunder/oxid-module-gtm', + 'version' => '1.0.0.0', + 'author' => 'Data Development (Inh.: Thomas Dartsch)', + 'email' => 'support@shopmodule.com', + 'url' => 'https://www.oxidmodule.com/', 'extend' => [ - \OxidEsales\Eshop\Core\ViewConfig::class => VanillaThunder\GoogleTagManager\Application\Extend\ViewConfig::class + OEViewConfig::class => ViewConfig::class ], 'templates' => [ // GA4 events diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b6e0779 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,10 @@ +parameters: + scanFiles: + - IntelliSenseHelper.php + - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php + - ../../oxid-esales/oxideshop-ce/source/overridablefunctions.php + level: 9 + phpVersion: 70100 + checkMissingIterableValueType: false + ignoreErrors: + - '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#' diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..516e222 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,20 @@ + + + + + src + + + + + + + ./Tests + + +