def getTrackingScriptString(jobid=None):
    """
    For injecting tracking script into a web page.
    
    jobid -> current jobid. Adds "jobid" custom variable to events and page views on this page.
    """
    customVarString = ""
    
    if jobid is not None:
        customVarString = "_gaq.push(['_setCustomVar',1,'jobid','{jobid}',3]);".format(jobid=str(jobid))
        
    #If you look closely you'll see escaped { and }.
    string = """<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-11026338-3']);
  _gaq.push(['_setDomainName', 'none']);
  _gaq.push(['_setAllowLinker', true]);
  {customVar}
  _gaq.push(['_trackPageview']);

  (function() {{
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  }})();

</script>""".format(customVar=customVarString)
    return string