Is using craft.config to access siteUrl possible? In the past I would comment out analytics code on my dev and staging sites then uncomment the code when it went live. I ran across this page in the Craft docs the other day and started thinking, can I use this to access the siteUrl from the environment variable array and specify a value in my conditional (i.e. {% craft.config.environmentVariable('siteUrl', 'http://www.example.com') %}? This way I can add the analytics code and only worry about it loading on the live site.
Yes, if you set up proper multi environment configs, this isn't very hard. My config/general.php file usually look something like this:

return array(

  '*' =&gt; array(
     // some general settings here
  ),

  'mydomain.craft.dev' =&gt; array(
    'environment' =&gt; 'local',
    'devMode' =&gt; true,
    'useCompressedJs' =&gt; false,
    'siteUrl' =&gt; 'http://mydomain.craft.dev/',

    'environmentVariables' =&gt; array(
      'fileSystemPath' =&gt; $_SERVER['DOCUMENT_ROOT'] . '/../',
      'publicRootPath'    =&gt; 'public/'
    ),
  ),

  // staging and other environments here

  'mydomain.com' =&gt; array(
    'environment' =&gt; 'prod',
    'devMode' =&gt; false,
    'useCompressedJs' =&gt; true,
    'siteUrl' =&gt; 'http://mydomain.com/',

    'environmentVariables' =&gt; array(
      'fileSystemPath' =&gt; '/path/to/system/root/',
      'publicRootPath' =&gt; 'html/'
    )
  ) 

);


Then, to only include the GA tracking tag when I'm on the prod server, I include this in my html head:

{% if craft.config.environment=='prod'  %}
  &lt;script&gt;
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-XXXXXXXX-X', 'auto');
    ga('send', 'pageview');
  &lt;/script&gt;
{% endif %}


You could of course check siteUrl instead, but I prefer to use something a little more abstract. Just in case the siteUrl changes.