Sfoglia il codice sorgente

Merge pull request #1167 from yannouchou/v2-master

Support for GA Tracking code
causefx 7 anni fa
parent
commit
49d6e51b23
3 ha cambiato i file con 26 aggiunte e 0 eliminazioni
  1. 7 0
      api/functions/organizr-functions.php
  2. 18 0
      api/functions/static-globals.php
  3. 1 0
      index.php

+ 7 - 0
api/functions/organizr-functions.php

@@ -1115,6 +1115,13 @@ function getCustomizeAppearance()
 							'value' => 'bottom'
 						)
 					)
+				),
+				array(
+					'type' => 'input',
+					'name' => 'gaTrackingID',
+					'label' => 'Google Analytics Tracking ID',
+					'placeholder' => 'e.g. UA-XXXXXXXXX-X',
+					'value' => $GLOBALS['gaTrackingID']
 				)
 			),
 			'Colors & Themes' => array(

+ 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 - 0
index.php

@@ -298,6 +298,7 @@
 <script src="https://js.pusher.com/4.1/pusher.min.js"
         integrity="sha384-e9MoFh6Cw/uluf+NZ6MJwfJ1Dm7UOvJf9oTBxxCYDyStJeeAF0q53ztnEbLLDSQP"
         crossorigin="anonymous"></script>
+<?php echo googleTracking(); ?>
 <?php echo pluginFiles('js');
 echo formKey(); ?>
 </body>