Skip to content

Commit e753f2a

Browse files
committed
Rid of <<<script script;
1 parent 6a9d259 commit e753f2a

File tree

5 files changed

+53
-65
lines changed

5 files changed

+53
-65
lines changed

Block/AbstractDataLayer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ protected function _toHtml(): string
6262
if ($dataLayer) {
6363
$json = json_encode($dataLayer);
6464
$json = str_replace('"getMfGtmCustomerIdentifier()"', 'getMfGtmCustomerIdentifier()', $json);
65-
$script = <<<script
65+
$script = '
6666
window.dataLayer = window.dataLayer || [];
67-
window.dataLayer.push({$json});
68-
script;
67+
window.dataLayer.push(' . $json . ');
68+
';
6969
return $this->mfSecureRenderer->renderTag('script', ['style' => 'display:none'], $script, false);
7070
}
7171
}

Block/Adminhtml/System/Config/Form/InfoMeasurementProtocol.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
4747
$html .= 'GA4 Measurement Protocol is not available while <a href="#mfgoogletagmanager_server_container-head">GTM Server Container</a> is enabled.';
4848
$html .= '</div>';
4949

50-
$script = <<<script
50+
$script = '
5151
require(["jquery", "Magento_Ui/js/modal/alert", "domReady!"], function($, alert){
5252
setInterval(function(){
5353
if (parseInt($("#mfgoogletagmanager_server_container_enabled").val())) {
@@ -57,7 +57,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
5757
}
5858
}, 1000);
5959
});
60-
script;
60+
';
6161

6262
$html .= $this->mfSecureRenderer->renderTag('script', [], $script, false);
6363

Block/Adminhtml/System/Config/Form/InfoPlan.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
4949
? 'This option is available in <strong>Extra</strong> plan only.'
5050
: 'This option is available in <strong>Plus or Extra</strong> plans only.';
5151

52-
$script = <<<script
52+
$script = '
5353
require(["jquery", "Magento_Ui/js/modal/alert", "domReady!"], function($, alert){
5454
setInterval(function(){
5555
var plusSection = $("#{$this->getSectionId()}-state").parent(".section-config");
@@ -78,7 +78,7 @@ class: "action primary accept",
7878
});
7979
}, 1000);
8080
});
81-
script;
81+
';
8282

8383
$html .= $this->mfSecureRenderer->renderTag('script', [], $script, false);
8484

view/adminhtml/templates/system/config/button/export-container-button.phtml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (!isset($escaper)) {
2222
<br/>
2323
<?= __('Once the JSON file is downloaded, upload it to %1 > Choose %2 Container > Admin > Import Container.', '<a href="https://tagmanager.google.com/" title="Google Tag Manager" target="_blank">Google Tag Manager</a>', ucfirst($block->getConteinderType())) ?>
2424
</p>
25-
<?php $script = <<<script
25+
<?php $script = "
2626
require([
2727
'jquery',
2828
'domReady!'
@@ -32,8 +32,7 @@ if (!isset($escaper)) {
3232
window.location='{$escaper->escapeUrl($block->getContainerGenerateUrl())}';
3333
});
3434
});
35-
script;
36-
?>
35+
"; ?>
3736
<?= /* @noEscape */ $mfSecureRenderer->renderTag('script', [], $script, false) ?>
3837
</div>
3938

view/frontend/templates/js_code.phtml

Lines changed: 44 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ if (!isset($escaper)) {
1818
$script = '';
1919
?>
2020
<!-- Google Tag Manager -->
21-
<?php if ($block->isSpeedOptimizationEnabled() && $block->getRequest()->getModuleName() !== 'checkout') { ?>
22-
<?php $script .= <<<script
21+
<?php if ($block->isSpeedOptimizationEnabled() && $block->getRequest()->getModuleName() !== 'checkout') { ?>
22+
<?php $script .= "
2323
document.addEventListener('scroll', mfGtmUserActionDetect);
2424
document.addEventListener('mousemove', mfGtmUserActionDetect);
2525
document.addEventListener('touchstart', mfGtmUserActionDetect);
@@ -31,17 +31,15 @@ $script = '';
3131
window.mfGtmUserActionDetected = true;
3232
mfLoadGtm();
3333
}
34-
script;
35-
?>
36-
<?php } else { ?>
37-
<?php $script .= <<<script
34+
"; ?>
35+
<?php } else { ?>
36+
<?php $script .= "
3837
window.mfGtmUserActionDetected = true;
39-
script;
40-
?>
41-
<?php } ?>
38+
"; ?>
39+
<?php } ?>
4240

43-
<?php if ($block->isProtectCustomerDataEnabled()) { ?>
44-
<?php $script .= <<<script
41+
<?php if ($block->isProtectCustomerDataEnabled()) { ?>
42+
<?php $script .= "
4543
window.dataLayer = window.dataLayer || [];
4644
function gtag() { dataLayer.push(arguments); }
4745
gtag('consent', 'default', {
@@ -59,22 +57,20 @@ script;
5957
'wait_for_update': 2000
6058
});
6159
/* cookieyes.com start */
62-
gtag("set", "ads_data_redaction", true);
63-
gtag("set", "url_passthrough", true);
60+
gtag('set', 'ads_data_redaction', true);
61+
gtag('set', 'url_passthrough', true);
6462
/* cookieyes.com end */
65-
script;
66-
?>
63+
"; ?>
6764

68-
<?php if ($block->isLoadBeforeConsent()) { ?>
69-
<?php $script .= <<<script
65+
<?php if ($block->isLoadBeforeConsent()) { ?>
66+
<?php $script .= "
7067
window.mfGtmLoadBeforeCookieAllowed = true;
7168
mfLoadGtm();
72-
script;
73-
?>
74-
<?php } ?>
69+
"; ?>
70+
<?php } ?>
7571

76-
<?php if ($block->isCookieRestrictionModeEnabled()) { ?>
77-
<?php $script .= <<<script
72+
<?php if ($block->isCookieRestrictionModeEnabled()) { ?>
73+
<?php $script .= "
7874
(function () {
7975
function getCookieValue(cookieName) {
8076
let name = cookieName + '=';
@@ -134,21 +130,19 @@ script;
134130
}, 1000);
135131
}
136132
})();
137-
script;
138-
?>
139-
<?php } ?>
133+
"; ?>
134+
<?php } ?>
140135

141-
<?php } else { ?>
142-
<?php $script .= <<<script
136+
<?php } else { ?>
137+
<?php $script .= "
143138
window.mfGtmUserCookiesAllowed = true;
144139
mfLoadGtm();
145-
script;
146-
?>
147-
<?php } ?>
148-
<?php $script .= <<<script
140+
"; ?>
141+
<?php } ?>
142+
<?php $script .= "
149143
150144
function getMfGtmCustomerIdentifier() {
151-
return localStorage.getItem("mf_gtm_customer_identifier") ? localStorage.getItem("mf_gtm_customer_identifier") : null;
145+
return localStorage.getItem('mf_gtm_customer_identifier') ? localStorage.getItem('mf_gtm_customer_identifier') : null;
152146
}
153147
154148
function mfLoadGtm() {
@@ -157,35 +151,32 @@ script;
157151
158152
if (window.mfGTMTriedToLoad) return;
159153
window.mfGTMTriedToLoad = true;
160-
script;
161-
?>
162-
<?php if ($block->getPublicId()) { ?>
163-
<?php if ('use_public_id' === $block->getConfig()->getInstallGtm()) { ?>
164-
<?php $script .= <<<script
154+
"; ?>
155+
<?php if ($block->getPublicId()) { ?>
156+
<?php if ('use_public_id' === $block->getConfig()->getInstallGtm()) { ?>
157+
<?php $script .= "
165158
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
166159
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
167160
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
168161
'https:' + '/' + '/' + 'www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
169162
})(window,document,'script','dataLayer','{$escaper->escapeHtml($block->getPublicId())}');
170-
script;
171-
?>
172-
<?php } elseif ('use_head_and_body_script' === $block->getConfig()->getInstallGtm()) { ?>
173-
<?php $script .= $block->getGtmScript(); ?>
174-
<?php } ?>
175-
<?php } ?>
176-
<?php $script .= <<<script
163+
"; ?>
164+
<?php } elseif ('use_head_and_body_script' === $block->getConfig()->getInstallGtm()) { ?>
165+
<?php $script .= $block->getGtmScript(); ?>
166+
<?php } ?>
167+
<?php } ?>
168+
<?php $script .= "
177169
}
178-
script;
179-
?>
170+
"; ?>
180171
<?= /* @noEscape */ $mfSecureRenderer->renderTag('script', [], $script, false) ?>
181172

182173
<?php if (!$mfHyvaThemeDetection->execute()) { ?>
183-
<?php $script = <<<script
174+
<?php $script = "
184175
if (!window.MagefanRocketJsCustomOptimization && window.require)
185176
require(['jquery', 'Magento_Customer/js/customer-data'], function ($, customer) {
186177
function updateMfGtmCustomerIdentifier(data) {
187178
if (data.mf_gtm_customer_identifier) {
188-
localStorage.setItem("mf_gtm_customer_identifier", data.mf_gtm_customer_identifier);
179+
localStorage.setItem('mf_gtm_customer_identifier', data.mf_gtm_customer_identifier);
189180
}
190181
}
191182
let customerData = customer.get('customer');
@@ -195,27 +186,25 @@ script;
195186
}.bind(this));
196187
updateMfGtmCustomerIdentifier(customerData());
197188
});
198-
script;
199-
?>
189+
"; ?>
200190
<?= /* @noEscape */ $mfSecureRenderer->renderTag('script', [], $script, false) ?>
201191
<?php } else { ?>
202-
<?php $script = <<<script
192+
<?php $script = "
203193
/* Hyva code */
204194
function mfHyvaGtmSetCustomerIdentifier(event) {
205195
let data, j;
206196
let sections = event.detail.data;
207197
for (j in sections) {
208198
data = sections[j];
209199
if (data.mf_gtm_customer_identifier) {
210-
localStorage.setItem("mf_gtm_customer_identifier", data.mf_gtm_customer_identifier);
200+
localStorage.setItem('mf_gtm_customer_identifier, data.mf_gtm_customer_identifier);
211201
return;
212202
}
213203
}
214204
}
215-
window.addEventListener("private-content-loaded", mfHyvaGtmSetCustomerIdentifier);
205+
window.addEventListener('private-content-loaded', mfHyvaGtmSetCustomerIdentifier);
216206
/* End Hyva code */
217-
script;
218-
?>
207+
"; ?>
219208
<?= /* @noEscape */ $mfSecureRenderer->renderTag('script', [], $script, false) ?>
220209
<?php } ?>
221210
<!-- End Google Tag Manager -->

0 commit comments

Comments
 (0)