File tree Expand file tree Collapse file tree 2 files changed +18
-25
lines changed
app/code/Magento/GoogleGtag Expand file tree Collapse file tree 2 files changed +18
-25
lines changed Original file line number Diff line number Diff line change @@ -83,20 +83,6 @@ public function getPageName(): ?string
83
83
return $ this ->_getData ('page_name ' );
84
84
}
85
85
86
- /**
87
- * Render GA tracking scripts
88
- *
89
- * @return string
90
- */
91
- protected function _toHtml ()
92
- {
93
- if (!$ this ->googleGtagConfig ->isGoogleAnalyticsAvailable ()) {
94
- return '' ;
95
- }
96
-
97
- return parent ::_toHtml ();
98
- }
99
-
100
86
/**
101
87
* Return cookie restriction mode value.
102
88
*
@@ -206,7 +192,8 @@ public function getAnalyticsData()
206
192
'currentWebsite ' => $ this ->getCurrentWebsiteId (),
207
193
'cookieName ' => Cookie::IS_USER_ALLOWED_SAVE_COOKIE ,
208
194
'pageTrackingData ' => $ this ->getPageTrackingData ($ this ->googleGtagConfig ->getMeasurementId ()),
209
- 'ordersTrackingData ' => $ this ->getOrdersTrackingData ()
195
+ 'ordersTrackingData ' => $ this ->getOrdersTrackingData (),
196
+ 'googleAnalyticsAvailable ' => $ this ->googleGtagConfig ->isGoogleAnalyticsAvailable ()
210
197
];
211
198
return $ this ->serializer ->serialize ($ analyticData );
212
199
}
Original file line number Diff line number Diff line change 3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
7
+ /** @var $block \Magento\GoogleGtag\Block\Ga */
8
+ /** @var \Magento\Framework\Escaper $escaper */
9
+
10
+ $ analyticsData = $ block ->getAnalyticsData ();
6
11
?>
7
- <?php /** @var $block \Magento\GoogleGtag\Block\Ga */ ?>
8
- <?php /** @var \Magento\Framework\Escaper $escaper */ ?>
9
- <!-- BEGIN GOOGLE ANALYTICS 4 CODE -->
10
- <script type="text/x-magento-init">
11
- {
12
- "*": {
13
- "Magento_GoogleGtag/js/google-analytics": <?= /* @noEscape */ $ block ->getAnalyticsData () ?>
12
+
13
+ <?php if ($ analyticsData ['googleAnalyticsAvailable ' ]): ?>
14
+ <!-- BEGIN GOOGLE ANALYTICS 4 CODE -->
15
+ <script type="text/x-magento-init">
16
+ {
17
+ "*": {
18
+ "Magento_GoogleGtag/js/google-analytics": <?= /* @noEscape */ $ block ->getAnalyticsData () ?>
19
+ }
14
20
}
15
- }
16
- </script >
17
- <!-- END GOOGLE ANALYTICS 4 CODE -- >
21
+ </script>
22
+ <!-- END GOOGLE ANALYTICS 4 CODE -- >
23
+ <?php endif ; ? >
You can’t perform that action at this time.
0 commit comments