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
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 8
8
/** @var \Magento\Framework\View\Element\Template $block */
9
9
/** @var \Magento\Framework\Escaper $escaper */
10
10
/** @var \Magento\GoogleGtag\ViewModel\Adwords $adsViewModel */
11
+
11
12
$ adsViewModel = $ block ->getViewModel ();
12
13
?>
13
14
14
15
<?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
+ }
24
30
</script>
31
+ <!-- END GOOGLE ADWORDS CODE -->
25
32
<?php endif ?>
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 ): ?>
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 ; ? >
Original file line number Diff line number Diff line change @@ -14,22 +14,16 @@ $adsViewModel = $block->getViewModel();
14
14
<?php if ($ adsViewModel ->isGoogleAdwordsConfigurable () && $ adsViewModel ->isGoogleAdwordsActive ()): ?>
15
15
<?php $ conversionId = $ adsViewModel ->getConversionId (); ?>
16
16
<?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
+ }
33
25
}
34
- </script>
26
+ }
27
+ </script>
28
+ <!-- END GOOGLE ADWORDS CODE -->
35
29
<?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
21
21
/**
22
22
* Xml path google experiments enabled
23
23
*/
24
- private const XML_PATH_ENABLED = 'google/analytics/experiments ' ;
24
+ public const XML_PATH_ENABLED = 'google/analytics/experiments ' ;
25
25
26
26
/**
27
27
* Xml path google experiments enabled for GA4
You can’t perform that action at this time.
0 commit comments