File tree Expand file tree Collapse file tree 4 files changed +69
-27
lines changed
app/code/Magento/GoogleGtag/view/frontend Expand file tree Collapse file tree 4 files changed +69
-27
lines changed 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 10
10
$ analyticsData = $ block ->getAnalyticsData ();
11
11
?>
12
12
13
- <?php if ($ analyticsData[ ' googleAnalyticsAvailable ' ] ): ?>
13
+ <?php if ($ analyticsData ): ?>
14
14
<!-- BEGIN GOOGLE ANALYTICS 4 CODE -->
15
15
<script type="text/x-magento-init">
16
16
{
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments