plug_google_analytics.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. if (!class_exists("plug_google_analytics")) {
  3. class plug_google_analytics {
  4. function __construct($ns) {
  5. $this->title = __("Google Analytics","dagsopt");
  6. $this->pluginname = $ns->pluginname;
  7. $this->file = $ns->file;
  8. $this->ns = $ns;
  9. }
  10. function start() {
  11. add_action('wp_footer',array(&$this,'footer'),100);
  12. }
  13. function footer() {
  14. $id = get_option($this->pluginname."_google_analytics_id");
  15. if(!empty($id)){
  16. ?>
  17. <script type="text/javascript">
  18. var _gaq = _gaq || [];
  19. _gaq.push(['_setAccount', '<?php echo($id); ?>']);
  20. _gaq.push(['_setDomainName', '<?php echo(get_option($this->pluginname."_google_analytics_domain")); ?>']);
  21. _gaq.push(['_trackPageview']);
  22. (function() {
  23. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  24. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  25. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  26. })();
  27. </script>
  28. <?php
  29. }
  30. }
  31. function help(){
  32. ?>
  33. <?php echo(__("Adds google analytics snippet in footer","dagsopt")) ?>
  34. <?php
  35. }
  36. function Option($pre){
  37. update_option ( $pre.'_id', $_POST [ $pre.'_id' ] );
  38. update_option ( $pre.'_domain', $_POST [ $pre.'_domain' ] );
  39. }
  40. function admin_line($pre){
  41. ?>
  42. <?php echo(__("Google Analytics ID:","dagsopt")) ?><br><input type="text" name="<?php echo( $pre.'_id' ); ?>" value="<?php echo(stripcslashes(get_option($pre."_id"))); ?>" > <br>
  43. <?php echo(__("Google Analytics Domain:","dagsopt")) ?><br><input type="text" name="<?php echo( $pre.'_domain' ); ?>" value="<?php echo(stripcslashes(get_option($pre."_domain"))); ?>" >
  44. <?php
  45. }
  46. }
  47. global $plug_google_analytics;
  48. $plug_google_analytics = new plug_google_analytics($this);
  49. $this->dagsopt['plug_google_analytics'] = $plug_google_analytics;
  50. }