From 13b84b6295efe42fbe8d9c5232f65ab3db600f8e Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Thu, 25 Jan 2024 15:52:17 -0500 Subject: [PATCH] Add support for custom domain using GTM JS client --- Block/DataLayer.php | 18 ++++++++++++ Block/GtmCode.php | 18 ++++++++++++ Helper/Data.php | 39 ++++++++++++++++++++++++++ composer.json | 2 +- etc/adminhtml/system.xml | 42 +++++++++++++++++++++++----- view/frontend/templates/iframe.phtml | 4 +++ view/frontend/templates/js.phtml | 8 ++++-- 7 files changed, 121 insertions(+), 10 deletions(-) diff --git a/Block/DataLayer.php b/Block/DataLayer.php index 35a2d45..08479e2 100755 --- a/Block/DataLayer.php +++ b/Block/DataLayer.php @@ -95,4 +95,22 @@ public function addJsInHead($store_id = null) { return (int) $this->_gtmHelper->addJsInHead($store_id); } + + /** + * @param null $store_id + * @return bool + */ + public function isAdvancedSettingsEnabled($store_id = null) + { + return $this->_gtmHelper->isAdvancedSettingsEnabled($store_id); + } + + /** + * @param null $store_id + * @return string + */ + public function getAdvancedSettingsJsCode($store_id = null) + { + return $this->_gtmHelper->getAdvancedSettingsJsCode($store_id); + } } diff --git a/Block/GtmCode.php b/Block/GtmCode.php index 27b1e46..88c96cb 100755 --- a/Block/GtmCode.php +++ b/Block/GtmCode.php @@ -72,4 +72,22 @@ protected function _toHtml() return parent::_toHtml(); } + + /** + * @param null $store_id + * @return bool + */ + public function isAdvancedSettingsEnabled($store_id = null) + { + return $this->_gtmHelper->isAdvancedSettingsEnabled($store_id); + } + + /** + * @param null $store_id + * @return string + */ + public function getAdvancedSettingsIframeCode($store_id = null) + { + return $this->_gtmHelper->getAdvancedSettingsIframeCode($store_id); + } } diff --git a/Helper/Data.php b/Helper/Data.php index c4a6906..74598a1 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -219,6 +219,45 @@ public function isCategoryLayerEnabled($store_id = null) ); } + /** + * @param null $store_id + * @return bool + */ + public function isAdvancedSettingsEnabled($store_id = null) + { + return $this->scopeConfig->isSetFlag( + 'googletagmanager/advanced_settings/enabled', + ScopeInterface::SCOPE_STORE, + $store_id + ); + } + + /** + * @param null $store_id + * @return string + */ + public function getAdvancedSettingsJsCode($store_id = null) + { + return $this->scopeConfig->getValue( + 'googletagmanager/advanced_settings/js_code', + ScopeInterface::SCOPE_STORE, + $store_id + ); + } + + /** + * @param null $store_id + * @return string + */ + public function getAdvancedSettingsIframeCode($store_id = null) + { + return $this->scopeConfig->getValue( + 'googletagmanager/advanced_settings/iframe_code', + ScopeInterface::SCOPE_STORE, + $store_id + ); + } + /** * @param ProductInterface $product * @param array $viewItem diff --git a/composer.json b/composer.json index bf8ec9f..a29a3a7 100755 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "magepal/magento2-google-analytics4": "Prepare for the future with Google Analytics 4. Learn more at https://www.magepal.com/google-analytics-4-for-google-tag-manager.html" }, "type": "magento2-module", - "version": "2.7.4", + "version": "2.7.5", "autoload": { "files": [ "registration.php" diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 253422b..b80ad96 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -32,15 +32,15 @@ that make it very similar, yet more powerful than Enhanced Ecommerce. Gain access to GA4 new approach to privacy-first tracking, channel measurement, and AI based predictive data with our new Google Analytics 4 extension. +
+ Adding Facebook Pixel, Bing UET, or other third-party JavaScript to your site using Google Tag Manager? + Learn how simple and easy it is to integrate any third party service with our new DataLayer extension. +
Want to learn more about your customers? Gain valuable insight on your customers shopping behavior, sales performance and more. Upgrade to our new Enhanced E-commerce today, to take full advantage of Google Analytics most valuable features and reports.
-
- Adding Facebook Pixel, Bing UET, or other third-party JavaScript to your site using Google Tag Manager? - Learn how simple and easy it is to integrate any third party service with our new DataLayer extension. -

]]> @@ -99,9 +99,7 @@ 0 - - Note: Data Layer event firing Order may change - + Note: Data Layer events firing sequence may change. @@ -128,6 +126,36 @@ + + + + + + Magento\Config\Model\Config\Source\Yesno + + + + + + + + required-entry + + 1 + + + + + + + + + required-entry + + 1 + + + diff --git a/view/frontend/templates/iframe.phtml b/view/frontend/templates/iframe.phtml index ec06c3d..f14198b 100755 --- a/view/frontend/templates/iframe.phtml +++ b/view/frontend/templates/iframe.phtml @@ -9,6 +9,10 @@ ?> +isAdvancedSettingsEnabled()): ?> + + getAdvancedSettingsIframeCode() ?> + diff --git a/view/frontend/templates/js.phtml b/view/frontend/templates/js.phtml index 4569b4b..9301ab6 100755 --- a/view/frontend/templates/js.phtml +++ b/view/frontend/templates/js.phtml @@ -15,7 +15,7 @@ $containerCode = $block->getEmbeddedCode(); -isGdprEnabled() || !$block->addJsInHead()): ?> +isAdvancedSettingsEnabled()): ?> + getAdvancedSettingsJsCode() ?> + + +isGdprEnabled() || !$block->addJsInHead()) && !$block->isAdvancedSettingsEnabled()) : ?>