4
0
Yann 7 жил өмнө
parent
commit
fd173065ab

+ 2 - 1
api/functions/organizr-functions.php

@@ -1119,7 +1119,8 @@ function getCustomizeAppearance()
 				array(
 					'type' => 'input',
 					'name' => 'gaTrackingID',
-					'label' => 'Google Analytics Tracking ID (e.g. UA-XXXXXXXXX-X)',
+					'label' => 'Google Analytics Tracking ID',
+					'placeholder' => 'e.g. UA-XXXXXXXXX-X',
 					'value' => $GLOBALS['gaTrackingID']
 				)
 			),

+ 18 - 0
api/functions/static-globals.php

@@ -127,4 +127,22 @@ function matchBrackets($text, $brackets = 's')
 	}
 	preg_match($pattern, $text, $match);
 	return $match[1];
+}
+
+function googleTracking()
+{
+	if (isset($GLOBALS['quickConfig']['gaTrackingID'])) {
+		if ($GLOBALS['quickConfig']['gaTrackingID'] !== '') {
+			return '
+				<script async src="https://www.googletagmanager.com/gtag/js?id=' . $GLOBALS['quickConfig']['gaTrackingID'] . '"></script>
+    			<script>
+				    window.dataLayer = window.dataLayer || [];
+				    function gtag(){dataLayer.push(arguments);}
+				    gtag("js", new Date());
+				    gtag("config","' . $GLOBALS['quickConfig']['gaTrackingID'] . '");
+    			</script>
+			';
+		}
+	}
+	return null;
 }

+ 1 - 10
index.php

@@ -298,16 +298,7 @@
 <script src="https://js.pusher.com/4.1/pusher.min.js"
         integrity="sha384-e9MoFh6Cw/uluf+NZ6MJwfJ1Dm7UOvJf9oTBxxCYDyStJeeAF0q53ztnEbLLDSQP"
         crossorigin="anonymous"></script>
-<?php if ($GLOBALS['gaTrackingID']) { ?>
-    <script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $GLOBALS['gaTrackingID']; ?>"></script>
-    <script>
-    window.dataLayer = window.dataLayer || [];
-    function gtag(){dataLayer.push(arguments);}
-    gtag('js', new Date());
-
-    gtag('config', '<?php echo $GLOBALS['gaTrackingID']; ?>');
-    </script>
-<?php } ?>
+<?php echo googleTracking(); ?>
 <?php echo pluginFiles('js');
 echo formKey(); ?>
 </body>