Skip to content

Commit d3f1cce

Browse files
author
Yuriy
committed
11294-enable-web-container
1 parent 25b64a9 commit d3f1cce

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

etc/adminhtml/system.xml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@
3333
<group id="web_container" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" >
3434
<label>Web Container</label>
3535
<attribute type="expanded">1</attribute>
36-
<!--
37-
<field id="enable" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
38-
<label>Enable</label>
36+
<field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
37+
<label>Enable Web Container</label>
3938
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
4039
</field>
41-
-->
4240
<field id="install_gtm" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
4341
<label>Google Tag Manager Installation Method</label>
42+
<depends>
43+
<field id="enabled">1</field>
44+
</depends>
4445
<source_model>Magefan\GoogleTagManager\Model\Config\Source\InstallGtmOptions</source_model>
4546
</field>
4647
<field id="public_id" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
@@ -68,12 +69,14 @@
6869
]]>
6970
</comment>
7071
<depends>
72+
<field id="enabled">1</field>
7173
<field id="mfgoogletagmanager/web_container/install_gtm">use_public_id</field>
7274
</depends>
7375
</field>
7476
<field id="script_content" translate="label comment" type="textarea" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
7577
<label>Head Script</label>
7678
<depends>
79+
<field id="enabled">1</field>
7780
<field id="mfgoogletagmanager/web_container/install_gtm">use_head_and_body_script</field>
7881
</depends>
7982
<comment>
@@ -95,6 +98,7 @@
9598
<field id="noscript_content" translate="label comment" type="textarea" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
9699
<label>Body Noscript</label>
97100
<depends>
101+
<field id="enabled">1</field>
98102
<field id="mfgoogletagmanager/web_container/install_gtm">use_head_and_body_script</field>
99103
</depends>
100104
<comment>
@@ -112,6 +116,9 @@
112116
</field>
113117
<field id="account_id" translate="label comment" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
114118
<label>Account ID</label>
119+
<depends>
120+
<field id="enabled">1</field>
121+
</depends>
115122
<comment>
116123
<![CDATA[
117124
<p>Please get the <a href="https://tagmanager.google.com/" title="Google Tag Manager" target="_blank">Google Tag Manager</a> account ID from the GTM Workspace URL path. E.g.<br/>
@@ -121,6 +128,9 @@
121128
</field>
122129
<field id="container_id" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
123130
<label>Container ID</label>
131+
<depends>
132+
<field id="enabled">1</field>
133+
</depends>
124134
<comment>
125135
<![CDATA[
126136
<p>Please get the <a href="https://tagmanager.google.com/" title="Google Tag Manager" target="_blank">Google Tag Manager</a> container ID from the GTM Workspace URL path. E.g.<br/>
@@ -449,6 +459,9 @@ To create a new secret, navigate in the
449459
</group>
450460
<group id="container" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
451461
<label>Export Web Container</label>
462+
<depends>
463+
<field id="mfgoogletagmanager/web_container/enabled">1</field>
464+
</depends>
452465
<field id="export" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
453466
<frontend_model>Magefan\GoogleTagManager\Block\Adminhtml\System\Config\Form\ExportWebContainerButton</frontend_model>
454467
</field>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<mftype>1</mftype>
1515
</general>
1616
<web_container>
17+
<enabled>1</enabled>
1718
<install_gtm>use_public_id</install_gtm>
1819
<script_content/>
1920
<noscript_content/>

view/frontend/templates/js_code.phtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ $script = '';
140140
"; ?>
141141
<?php } ?>
142142
<?php $script .= "
143-
143+
144144
function getMfGtmCustomerIdentifier() {
145145
return localStorage.getItem('mf_gtm_customer_identifier') ? localStorage.getItem('mf_gtm_customer_identifier') : null;
146146
};
@@ -152,7 +152,7 @@ $script = '';
152152
if (window.mfGTMTriedToLoad) return;
153153
window.mfGTMTriedToLoad = true;
154154
"; ?>
155-
<?php if ($block->getPublicId()) { ?>
155+
<?php if ($block->getConfig()->webContainerEnabled() && $block->getPublicId()) { ?>
156156
<?php if ('use_public_id' === $block->getConfig()->getInstallGtm()) { ?>
157157
<?php $script .= "
158158
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
@@ -180,7 +180,7 @@ $script = '';
180180
}
181181
}
182182
let customerData = customer.get('customer');
183-
183+
184184
customerData.subscribe(function (data) {
185185
updateMfGtmCustomerIdentifier(data);
186186
}.bind(this));

view/frontend/templates/no_js_code.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (!isset($escaper)) {
1212
$escaper = $block;
1313
}
1414
?>
15-
<?php if ($block->getPublicId() && (!$block->isProtectCustomerDataEnabled() || $block->isLoadBeforeConsent())) { ?>
15+
<?php if ($block->getConfig()->webContainerEnabled() && $block->getPublicId() && (!$block->isProtectCustomerDataEnabled() || $block->isLoadBeforeConsent())) { ?>
1616
<!-- Google Tag Manager (noscript) -->
1717
<?php if ('use_public_id' === $block->getConfig()->getInstallGtm()) { ?>
1818
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=<?= $escaper->escapeHtml($block->getPublicId()) ?>"

0 commit comments

Comments
 (0)