Analytics.php
1.77 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Tz\WordPress\Tools\Analytics;
use Tz;
use Tz\WordPress\Tools;
const VERSION = 1;
const OPTION_NAME = 'tz_analytics';
const OPTION_GROUP = 'reading';
const OPTION_SECTION = 'tz_analytics_main';
call_user_func(function() {
Vars::$options = new Tools\WP_Option(OPTION_NAME);
Tools\add_actions(__NAMESPACE__ . '\Actions');
});
function validate($data) {
return $data;
}
class Actions {
public static function admin_init() {
register_setting(OPTION_GROUP, OPTION_NAME, __NAMESPACE__ . '\validate');
add_settings_section(OPTION_SECTION, 'Google Analytics', function() {}, OPTION_GROUP);
Tools\add_settings_fields(__NAMESPACE__ . '\Fields', OPTION_GROUP, OPTION_SECTION);
}
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']);
// _gaq.push(['_trackEvent', 'download', 'Membership', 'sub category?']);
(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 Fields {
public static function api_key() {
echo '<input type="text" name="' . OPTION_NAME . '[' . __FUNCTION__ . ']" id="' . __FUNCTION__ . '" value="' . Vars::$options[__FUNCTION__] . '" />';
}
}
class Vars {
public static $options;
}
?>