File tree Expand file tree Collapse file tree 6 files changed +87
-52
lines changed Expand file tree Collapse file tree 6 files changed +87
-52
lines changed Original file line number Diff line number Diff line change @@ -83,20 +83,6 @@ public function getPageName(): ?string
8383 return $ this ->_getData ('page_name ' );
8484 }
8585
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-
10086 /**
10187 * Return cookie restriction mode value.
10288 *
@@ -206,7 +192,8 @@ public function getAnalyticsData()
206192 'currentWebsite ' => $ this ->getCurrentWebsiteId (),
207193 'cookieName ' => Cookie::IS_USER_ALLOWED_SAVE_COOKIE ,
208194 'pageTrackingData ' => $ this ->getPageTrackingData ($ this ->googleGtagConfig ->getMeasurementId ()),
209- 'ordersTrackingData ' => $ this ->getOrdersTrackingData ()
195+ 'ordersTrackingData ' => $ this ->getOrdersTrackingData (),
196+ 'googleAnalyticsAvailable ' => $ this ->googleGtagConfig ->isGoogleAnalyticsAvailable ()
210197 ];
211198 return $ this ->serializer ->serialize ($ analyticData );
212199 }
Original file line number Diff line number Diff line change 88/** @var \Magento\Framework\View\Element\Template $block */
99/** @var \Magento\Framework\Escaper $escaper */
1010/** @var \Magento\GoogleGtag\ViewModel\Adwords $adsViewModel */
11+
1112$ adsViewModel = $ block ->getViewModel ();
1213?>
1314
1415<?php if ($ adsViewModel ->isGoogleAdwordsConfigurable () && $ adsViewModel ->isGoogleAdwordsActive ()): ?>
15- <?php $ conversionId = $ adsViewModel ->getConversionId (); ?>
16- <?php $ conversionLabel = $ adsViewModel ->getConversionLabel (); ?>
17- <script>
18- gtag(
19- 'event',
20- 'conversion',
21- {'send_to': '<?= $ block ->escapeHtml ($ conversionId ) ?> ' + '/'
22- + '<?= $ block ->escapeHtml ($ conversionLabel ) ?> '}
23- );
16+ <?php $ conversionId = $ block ->escapeHtml ($ adsViewModel ->getConversionId ()); ?>
17+ <?php $ conversionLabel = $ block ->escapeHtml ($ adsViewModel ->getConversionLabel ()); ?>
18+ <?php $ gtagSiteSrc = $ adsViewModel ->getConversionGtagGlobalSiteTagSrc (); ?>
19+ <!-- BEGIN GOOGLE ADWORDS CODE -->
20+ <script type="text/x-magento-init">
21+ {
22+ "*": {
23+ "Magento_GoogleGtag/js/google-adwords": {
24+ "conversionId": "<?= $ block ->escapeHtml ($ conversionId ); ?> ",
25+ "gtagSiteSrc": "<?= $ block ->escapeHtml ($ gtagSiteSrc ); ?> ",
26+ "conversionLabel": "<?= $ block ->escapeHtml ($ conversionLabel ); ?> "
27+ }
28+ }
29+ }
2430 </script>
31+ <!-- END GOOGLE ADWORDS CODE -->
2532<?php endif ?>
Original file line number Diff line number Diff line change 33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
7+ /** @var $block \Magento\GoogleGtag\Block\Ga */
8+ /** @var \Magento\Framework\Escaper $escaper */
9+
10+ $ analyticsData = $ block ->getAnalyticsData ();
611?>
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 ): ?>
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+ }
1420 }
15- }
16- </script >
17- <!-- END GOOGLE ANALYTICS 4 CODE -- >
21+ </script>
22+ <!-- END GOOGLE ANALYTICS 4 CODE -- >
23+ <?php endif ; ? >
Original file line number Diff line number Diff line change @@ -14,22 +14,16 @@ $adsViewModel = $block->getViewModel();
1414<?php if ($ adsViewModel ->isGoogleAdwordsConfigurable () && $ adsViewModel ->isGoogleAdwordsActive ()): ?>
1515 <?php $ conversionId = $ adsViewModel ->getConversionId (); ?>
1616 <?php $ gtagSiteSrc = $ adsViewModel ->getConversionGtagGlobalSiteTagSrc (); ?>
17- <script>
18- if (!window.gtag) {
19- // Inject Global Site Tag
20- var gtagScript = document.createElement('script');
21- gtagScript.type = 'text/javascript';
22- gtagScript.async = true;
23- gtagScript.src = '<?= $ block ->escapeHtml ($ gtagSiteSrc ) ?> ';
24- document.head.appendChild(gtagScript);
25-
26- window.dataLayer = window.dataLayer || [];
27-
28- function gtag(){dataLayer.push(arguments);}
29- gtag('js', new Date());
30- gtag('set', 'developer_id.dYjhlMD', true);
31- } else {
32- gtag('config', '<?= $ block ->escapeHtml ($ conversionId ) ?> ');
17+ <!-- BEGIN GOOGLE ADWORDS CODE -->
18+ <script type="text/x-magento-init">
19+ {
20+ "*": {
21+ "Magento_GoogleGtag/js/google-adwords": {
22+ "conversionId": "<?= $ block ->escapeHtml ($ conversionId ); ?> ",
23+ "gtagSiteSrc": "<?= $ block ->escapeHtml ($ gtagSiteSrc ); ?> "
24+ }
3325 }
34- </script>
26+ }
27+ </script>
28+ <!-- END GOOGLE ADWORDS CODE -->
3529<?php endif ?>
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright © Magento, Inc. All rights reserved.
3+ * See COPYING.txt for license details.
4+ */
5+ /* jscs:disable */
6+ /* eslint-disable */
7+ define ( [
8+ 'jquery'
9+ ] , function ( $ ) {
10+ 'use strict' ;
11+
12+ /**
13+ * @param {Object } config
14+ */
15+ return function ( config ) {
16+ if ( ! window . gtag ) {
17+ // Inject Global Site Tag
18+ var gtagScript = document . createElement ( 'script' ) ;
19+ gtagScript . type = 'text/javascript' ;
20+ gtagScript . async = true ;
21+ gtagScript . src = config . gtagSiteSrc ;
22+ document . head . appendChild ( gtagScript ) ;
23+
24+ window . dataLayer = window . dataLayer || [ ] ;
25+
26+ function gtag ( ) { dataLayer . push ( arguments ) ; }
27+ gtag ( 'js' , new Date ( ) ) ;
28+ gtag ( 'set' , 'developer_id.dYjhlMD' , true ) ;
29+ if ( config . conversionLabel ) {
30+ gtag (
31+ 'event' ,
32+ 'conversion' ,
33+ { 'send_to' : config . conversionId + '/'
34+ + config . conversionLabel }
35+ ) ;
36+ }
37+ } else {
38+ gtag ( 'config' , config . conversionId ) ;
39+ }
40+ }
41+ } ) ;
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class Data extends AbstractHelper
2121 /**
2222 * Xml path google experiments enabled
2323 */
24- private const XML_PATH_ENABLED = 'google/analytics/experiments ' ;
24+ public const XML_PATH_ENABLED = 'google/analytics/experiments ' ;
2525
2626 /**
2727 * Xml path google experiments enabled for GA4
You can’t perform that action at this time.
0 commit comments