This repository was archived by the owner on Jun 25, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 1010$ hasGATracking = false ;
1111
1212if (! empty ($ trackingId )) {
13- $ hasGATracking = true ;
1413?>
1514 <script>
1615 window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
1918 </script>
2019 <script async src='https://www.google-analytics.com/analytics.js'></script>
2120<?php
21+ } else {
22+ ?>
23+ <script>
24+ window.ga = function () {
25+ // Null object pattern to avoid `if (window.ga)` wherever ga is used.
26+ }
27+ </script>
28+ <?php
2229}
2330?>
2431
25-
2632<?php
2733// This block of code is intended to be temporary until the transition from
2834// Google's Universal Analytics to GA4 type projects has been completed
2935$ trackingIdGA4 = htmlentities ($ this ->configuration ->getValue ('analytics.trackingIdGA4 ' ));
3036if (! empty ($ trackingIdGA4 )) {
31- $ hasGATracking = true ;
3237?>
3338 <!-- Google tag (gtag.js) -->
3439 <script async src="https://www.googletagmanager.com/gtag/js?id=<?= $ trackingIdGA4 ?> "></script>
@@ -40,13 +45,11 @@ function gtag(){dataLayer.push(arguments);}
4045 gtag('config', '<?= $ trackingIdGA4 ?> ');
4146 </script>
4247<?php
43- }
44-
45- if (! $ hasGATracking ) {
48+ } else {
4649?>
4750 <script>
48- window.ga = function () {
49- // Null object pattern to avoid `if (window.ga )` wherever ga is used.
51+ window.dataLayer = function () {
52+ // Null object pattern to avoid `if (window.dataLayer )` wherever dataLayer is used.
5053 }
5154 </script>
5255<?php
You can’t perform that action at this time.
0 commit comments