DN_Google_Analytics

The Google Analytics by DN DN Google Analytics class.

Defined (1)

The class is defined in the following location(s).

/class.dn_google_analytics.php  
  1. class DN_Google_Analytics { 
  2.  
  3. function __construct() { 
  4. add_action( 'wp_head', array( $this, 'add_google_analytics' ), 1 ); 
  5.  
  6. public function add_google_analytics() { 
  7. $options = get_option( 'dn_google_analytics_settings_option' ); 
  8.  
  9. if ( ( $tracking_id = $options['tracking_id'] ) == null) { return; } 
  10.  
  11. ?> 
  12.  
  13. <!-- This website runs Google Analytics by DN --> 
  14. <script> 
  15. (function(i, s, o, g, r, a, m) {i['GoogleAnalyticsObject']=r;i[r]=i[r]||function() { 
  16. (i[r].q=i[r].q||[]).push(arguments)}, i[r].l=1*new Date();a=s.createElement(o),  
  17. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a, m) 
  18. })(window, document, 'script', '//www.google-analytics.com/analytics.js', '__gaTracker'); 
  19.  
  20. __gaTracker('create', '<?php echo $tracking_id ?>', 'auto'); 
  21. __gaTracker('set', 'forceSSL', true); 
  22. <?php if ( isset( $options['anonymize_ip'] ) ) echo "__gaTracker('set', 'anonymizeIp', true);\n" ?> 
  23. <?php if ( is_404() ) : ?> 
  24. __gaTracker('send', 'pageview', '/404error/?url=' + document.location.pathname + document.location.search + '&from=' + document.referrer ); 
  25. <?php else : ?> 
  26. __gaTracker('send', 'pageview'); 
  27. <?php endif ?> 
  28.  
  29. </script> 
  30. <!-- End Google Analytics by DN --> 
  31.  
  32. <?php 
  33.  
  34.