forked from mattrude/base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle-analytics.php
75 lines (73 loc) · 2.58 KB
/
google-analytics.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
function google_analytics() {
if ( is_user_logged_in() ) {
?>
<!--User is logged in, so this request will NOT be tracked by Google Analytics-->
<?php
} else {
global $Panel;
$GAEnabled = $Panel->Settings('GoogleAnalyticsEnabled');
$GAID = $Panel->Settings('GoogleAnalyticsID');
if ($GAEnabled == 'true') {
if ($GAID != NULL) { ?>
<!--Begin Google Analytics tracking script-->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("<?php echo $GAID; ?>");
pageTracker._trackPageview();
} catch(err) {}
</script>
<!--End Google Analytics tracking script-->
<?php } else {
?>
<!--No user is logged in and Google Analytics is enabled, but there is not Google Analytics ID filled in-->
<?php
}
} else {
?>
<!--No user is logged in and Google Analytics is disabled-->
<?php
}
}
}
function async_google_analytics() {
if ( is_user_logged_in() ) {
?>
<!--User is logged in, so this request will NOT be tracked by Google Asynchronous Analytics-->
<?php
} else {
global $Panel;
$GAEnabled = $Panel->Settings('GoogleAnalyticsEnabled');
$GAID = $Panel->Settings('GoogleAnalyticsID');
if ($GAEnabled == 'true') {
if ($GAID != NULL) { ?>
<!--Begin Google Asynchronous Analytics tracking script-->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<?php echo $GAID; ?>']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
}
</script>
<!--End Google Asynchronous Analytics tracking script-->
<?php } else {
?>
<!--No user is logged in and Google Asynchronous Analytics is enabled, but there is not Google Analytics ID filled in-->
<?php
}
} else {
?>
<!--No user is logged in and Google Asynchronous Analytics is disabled-->
<?php
}
}
}
?>