Analytics.php
1.12 KB
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
<?php
namespace Tz\WordPress\Tools\Analytics;
use Tz;
use Tz\WordPress\Tools;
const OPTION_NAME = 'tz_analytics';
call_user_func(function() {
Vars::$options = new Tools\WP_Option(OPTION_NAME);
Tools\add_actions(__NAMESPACE__ . '\Actions');
if (is_admin()) {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'Settings.php');
}
});
class Actions {
public static function wp_print_scripts() {
if (Tz\LIVE !== 1 || empty(Vars::$options['api_key'])) {
return;
}
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<?php echo Vars::$options['api_key']; ?>']);
_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';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php
}
}
class Vars {
public static $options;
}
?>