| 1 |
<?php |
| 2 |
|
| 3 |
add_action('wp_footer', 'smart_add_footer_code'); |
| 4 |
|
| 5 |
add_action('wp_head', 'smart_add_header_code'); |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
function smart_add_header_code($arg) { |
| 10 |
|
| 11 |
if(get_option('smart_analytics_header_enabled')) { |
| 12 |
|
| 13 |
echo get_option('smart_analytics_header_code'); |
| 14 |
|
| 15 |
} |
| 16 |
|
| 17 |
return $arg; |
| 18 |
|
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
function smart_add_footer_code($arg) { |
| 24 |
|
| 25 |
if(get_option('smart_analytics_enabled')) { ?> |
| 26 |
|
| 27 |
<script type="text/javascript"> |
| 28 |
|
| 29 |
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| 30 |
|
| 31 |
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
| 32 |
|
| 33 |
</script> |
| 34 |
|
| 35 |
<script type="text/javascript"> |
| 36 |
|
| 37 |
var pageTracker = _gat._getTracker("<?php echo get_option('smart_analytics_id'); ?>"); |
| 38 |
|
| 39 |
pageTracker._trackPageview(); |
| 40 |
|
| 41 |
</script> |
| 42 |
|
| 43 |
<?php } |
| 44 |
|
| 45 |
if(get_option('smart_analytics_footer_enabled')) { |
| 46 |
|
| 47 |
echo get_option('smart_analytics_footer_code'); |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
return $arg; |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
// action function for adding the administrative page |
| 58 |
|
| 59 |
function smart_add_analytics() { ?> |
| 60 |
|
| 61 |
<div class="wrap"> |
| 62 |
|
| 63 |
<h2>WP-INSERT : Tracking Codes</h2> |
| 64 |
|
| 65 |
<?php show_support_options(); ?> |
| 66 |
|
| 67 |
<form method="post" action="options.php"> |
| 68 |
|
| 69 |
<?php wp_nonce_field('update-options'); ?> |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
<table class="form-table"> |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
<tr valign="top"> |
| 78 |
|
| 79 |
<th scope="row">Google Analytics Tracker ID |
| 80 |
|
| 81 |
<br/><input id="smart_analytics_enabled" name="smart_analytics_enabled" type="checkbox" value="1"<?php if(get_option('smart_analytics_enabled')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 82 |
|
| 83 |
<td><input id="smart_analytics_id" name="smart_analytics_id" type="text" value="<?php echo get_option('smart_analytics_id'); ?>" style="width:350px;" /><br/> |
| 84 |
|
| 85 |
<small>( Paste your Google Analytics Tracker ID (XX-XXXXX-X) above )</small></td> |
| 86 |
|
| 87 |
</tr> |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
<tr valign="top"> |
| 92 |
|
| 93 |
<th scope="row">Insert Code into Header<br/> |
| 94 |
|
| 95 |
<br/><input id="smart_analytics_header_enabled" name="smart_analytics_header_enabled" type="checkbox" value="1"<?php if(get_option('smart_analytics_header_enabled')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 96 |
|
| 97 |
<td><textarea id="smart_analytics_header_code" name="smart_analytics_header_code" style="width:350px;height:150px;"><?php echo get_option('smart_analytics_header_code'); ?></textarea><br/> |
| 98 |
|
| 99 |
<small>( Paste Analytics or similar code in the box above )</small></td> |
| 100 |
|
| 101 |
</tr> |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
<tr valign="top"> |
| 106 |
|
| 107 |
<th scope="row">Insert Code into Footer<br/> |
| 108 |
|
| 109 |
<br/><input id="smart_analytics_footer_enabled" name="smart_analytics_footer_enabled" type="checkbox" value="1"<?php if(get_option('smart_analytics_footer_enabled')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 110 |
|
| 111 |
<td><textarea id="smart_analytics_footer_code" name="smart_analytics_footer_code" style="width:350px;height:150px;"><?php echo get_option('smart_analytics_footer_code'); ?></textarea><br/> |
| 112 |
|
| 113 |
<small>( Paste Analytics or similar code in the box above )</small></td> |
| 114 |
|
| 115 |
</tr> |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
</table> |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
<input type="hidden" name="action" value="update" /> |
| 124 |
|
| 125 |
<input type="hidden" name="page_options" value="smart_analytics_enabled,smart_analytics_id,smart_analytics_header_enabled,smart_analytics_header_code,smart_analytics_footer_enabled,smart_analytics_footer_code" /> |
| 126 |
|
| 127 |
<p class="submit"> |
| 128 |
|
| 129 |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> |
| 130 |
|
| 131 |
</p> |
| 132 |
|
| 133 |
</form> |
| 134 |
|
| 135 |
</div> |
| 136 |
|
| 137 |
<?php } ?> |