WordPress: Disable Google Analytics in preview

Each time you preview your blog post in WordPress to ensure that everything is in order, your page view goes up in Google Analytics or other analytics service. This messes up your Google Analytics stats by increasing the pageviews. You can easily prevent this with a conditional tag called is_preview(). Wrap your Google Analytics code with this conditions.

<?php 
if( !is_preview()) {
  # Google Analytics Code #
}
?>

You can use the is_preview condition for other purposes a well.