├── Api ├── ContainerInterface.php ├── DataLayer │ ├── BeginCheckoutInterface.php │ ├── Cart │ │ └── ItemInterface.php │ ├── Order │ │ └── ItemInterface.php │ ├── Product │ │ └── ItemInterface.php │ ├── PurchaseInterface.php │ ├── ViewCartInterface.php │ └── ViewItemInterface.php └── Transaction │ └── LogInterface.php ├── Block ├── AbstractDataLayer.php ├── Adminhtml │ └── System │ │ └── Config │ │ └── Form │ │ ├── Attention.php │ │ ├── EventList.php │ │ ├── ExportServerContainerButton.php │ │ ├── ExportWebContainerButton.php │ │ ├── Info.php │ │ ├── InfoMeasurementProtocol.php │ │ ├── InfoPlan.php │ │ ├── InfoPlanExtra.php │ │ ├── InfoPlanPlus.php │ │ └── ProtectCustomerData.php ├── DataLayer │ ├── BeginCheckout.php │ ├── Other.php │ ├── Purchase.php │ ├── PurchaseGetOrderFromRequest.php │ ├── ViewCart.php │ └── ViewItem.php └── GtmCode.php ├── Controller ├── Adminhtml │ ├── ContainerGenerate.php │ └── WebContainer │ │ └── Generate.php └── LastOrder │ └── DataLayer.php ├── LICENSE.txt ├── Model ├── AbstractDataLayer.php ├── Config.php ├── Config │ └── Source │ │ ├── BrandAttribute.php │ │ ├── InstallGtmOptions.php │ │ ├── OrderStatuses.php │ │ └── ProductAttribute.php ├── DataLayer │ ├── AbstractOrder.php │ ├── BeginCheckout.php │ ├── Cart │ │ └── Item.php │ ├── Order │ │ └── Item.php │ ├── Product │ │ └── Item.php │ ├── Purchase.php │ ├── ViewCart.php │ └── ViewItem.php ├── ResourceModel │ ├── Transaction.php │ └── Transaction │ │ └── Collection.php ├── Transaction.php ├── Transaction │ └── Log.php ├── TransactionRepository.php └── WebContainer.php ├── Plugin ├── Magefan │ └── GoogleTagManager │ │ └── Api │ │ └── DataLayer │ │ └── PurchaseInterface.php └── Magento │ ├── Customer │ └── CustomerData │ │ └── Customer.php │ └── Framework │ └── App │ └── Config │ └── ScopeConfig.php ├── README.md ├── Setup └── Patch │ └── Schema │ └── ChangePath.php ├── composer.json ├── etc ├── acl.xml ├── adminhtml │ ├── routes.xml │ └── system.xml ├── config.xml ├── csp_whitelist.xml ├── db_schema.xml ├── di.xml ├── frontend │ ├── di.xml │ └── routes.xml └── module.xml ├── registration.php └── view ├── adminhtml └── templates │ └── system │ └── config │ ├── button │ └── export-container-button.phtml │ └── event │ └── list.phtml └── frontend ├── layout ├── catalog_product_view.xml ├── checkout_cart_index.xml ├── checkout_index_index.xml ├── checkout_onepage_success.xml ├── default.xml ├── hyva_checkout_index_index.xml ├── p2c2p_payment_success.xml └── redsys_checkout_success.xml └── templates ├── js_code.phtml └── no_js_code.phtml /Api/ContainerInterface.php: -------------------------------------------------------------------------------- 1 | config = $config; 41 | $this->mfSecureRenderer = $mfSecureRenderer ?: \Magento\Framework\App\ObjectManager::getInstance() 42 | ->get(SecureHtmlRendererInterface::class); 43 | parent::__construct($context, $data); 44 | } 45 | 46 | /** 47 | * Get GTM datalayer 48 | * 49 | * @return array 50 | */ 51 | abstract protected function getDataLayer(): array; 52 | 53 | /** 54 | * Init GTM datalayer 55 | * 56 | * @return string 57 | */ 58 | protected function _toHtml(): string 59 | { 60 | if ($this->config->isEnabled()) { 61 | $dataLayer = $this->getDataLayer(); 62 | if ($dataLayer) { 63 | $json = json_encode($dataLayer); 64 | $json = str_replace('"getMfGtmCustomerIdentifier()"', 'getMfGtmCustomerIdentifier()', $json); 65 | $script = ' 66 | window.dataLayer = window.dataLayer || []; 67 | window.dataLayer.push(' . $json . '); 68 | '; 69 | return $this->mfSecureRenderer->renderTag('script', ['style' => 'display:none'], $script, false); 70 | } 71 | } 72 | 73 | return ''; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Block/Adminhtml/System/Config/Form/Attention.php: -------------------------------------------------------------------------------- 1 | 28 | Attention! Once you change and save the "Web/Server Container", "Google Analytics 4" or "Google Ads" settings, 29 | please don\'t forget to scroll down to the "Export Container" section 30 | and click the "Generate JSON Container & Download File" button to export container data. 31 | After you save the file, 32 | import it to your Google Tag Manager container. 33 | '; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Block/Adminhtml/System/Config/Form/EventList.php: -------------------------------------------------------------------------------- 1 | moduleManager = $moduleManager; 38 | parent::__construct($context, $data); 39 | } 40 | 41 | /** 42 | * Set template to itself 43 | * 44 | * @return $this 45 | */ 46 | protected function _prepareLayout(): EventList 47 | { 48 | parent::_prepareLayout(); 49 | if (!$this->getTemplate()) { 50 | $this->setTemplate(static::EVENT_LIST_TEMPLATE); 51 | } 52 | return $this; 53 | } 54 | 55 | /** 56 | * Render event list 57 | * 58 | * @param AbstractElement $element 59 | * @return string 60 | */ 61 | public function render(AbstractElement $element): string 62 | { 63 | // Remove scope label 64 | $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); 65 | return parent::render($element); 66 | } 67 | 68 | /** 69 | * Get the event list and scripts contents 70 | * 71 | * @param AbstractElement $element 72 | * @return string 73 | */ 74 | protected function _getElementHtml(AbstractElement $element): string 75 | { 76 | return $this->_toHtml(); 77 | } 78 | 79 | /** 80 | * Retrieve true if GTM Plus is enabled 81 | * 82 | * @return bool 83 | */ 84 | public function isPlusEnabled(): bool 85 | { 86 | return (bool)$this->moduleManager->isEnabled('Magefan_GoogleTagManagerPlus'); 87 | } 88 | 89 | /** 90 | * Retrieve true if GTM Extra is enabled 91 | * 92 | * @return bool 93 | */ 94 | public function isExtraEnabled(): bool 95 | { 96 | return (bool)$this->moduleManager->isEnabled('Magefan_GoogleTagManagerExtra'); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Block/Adminhtml/System/Config/Form/ExportServerContainerButton.php: -------------------------------------------------------------------------------- 1 | getUrl( 24 | 'mfgoogletagmanagerextra/serverContainer/generate', 25 | [ 26 | 'store_id' => (int)$this->getRequest()->getParam('store') ?: null, 27 | 'website_id' => (int)$this->getRequest()->getParam('website') ?: null 28 | ] 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Block/Adminhtml/System/Config/Form/ExportWebContainerButton.php: -------------------------------------------------------------------------------- 1 | unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); 38 | return parent::render($element); 39 | } 40 | 41 | /** 42 | * Get the button and scripts contents 43 | * 44 | * @param AbstractElement $element 45 | * @return string 46 | */ 47 | protected function _getElementHtml(AbstractElement $element): string 48 | { 49 | return $this->_toHtml(); 50 | } 51 | 52 | /** 53 | * @return string 54 | */ 55 | public function getConteinderType() 56 | { 57 | return $this->conteinerType; 58 | } 59 | 60 | /** 61 | * @return string 62 | */ 63 | public function getContainerGenerateUrl() 64 | { 65 | return $this->getUrl( 66 | 'mfgoogletagmanager/webContainer/generate', 67 | [ 68 | 'store_id' => (int)$this->getRequest()->getParam('store') ?: null, 69 | 'website_id' => (int)$this->getRequest()->getParam('website') ?: null 70 | ] 71 | ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Block/Adminhtml/System/Config/Form/Info.php: -------------------------------------------------------------------------------- 1 | '; 24 | $html .= 'GA4 Measurement Protocol is not available while GTM Server Container is enabled.'; 25 | $html .= ''; 26 | 27 | $script = ' 28 | require(["jquery", "Magento_Ui/js/modal/alert", "domReady!"], function($, alert){ 29 | setInterval(function(){ 30 | if (parseInt($("#mfgoogletagmanager_server_container_enabled").val())) { 31 | $("#ga4mp-disabled").show(); 32 | } else { 33 | $("#ga4mp-disabled").hide(); 34 | } 35 | }, 1000); 36 | }); 37 | '; 38 | 39 | $html .= $this->mfSecureRenderer->renderTag('script', [], $script, false); 40 | 41 | return $html; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Block/Adminhtml/System/Config/Form/InfoPlan.php: -------------------------------------------------------------------------------- 1 | getModuleVersion->execute($this->getModuleName() . $this->getMinPlan())) { 39 | return ''; 40 | } 41 | 42 | $html = ''; 43 | 44 | if ($text = $this->getText()) { 45 | $textHtml = '