Basic way to add Analytics in WordPress only to live site

For developers working in WordPress, it is extremely important to make sure you use WP_DEBUG on your local setup and any development environments. Otherwise you are flying somewhat blind. Since you should not use it on your live servers, you can use this constant to trigger other events. One example is a really simple way to keep Analytics code from reporting activity on your local and staging sites.

In its most basic form, you can wrap the Analtyics code in the header:

<?php if (! defined('WP_DEBUG') || ! WP_DEBUG ) : ?>
	<script>
		[Analytics code]
	</script>
<?php endif; ?>

You could also add an action to create the same effect:

add_action( 'wp_head', 'custom_add_analytics_production' );
function custom_add_analytics_production() {
	if (! defined('WP_DEBUG') || ! WP_DEBUG ) : ?>
		<script>
			[Analytics code]
		</script>
	<?php endif;
}

The benefit here would be to put the analytics code into an area where you customize settings for a client site. A super simple method, you just need to make sure you are setting WP_DEBUG correctly.