<script id="ga-params" type="text/javascript">
  var GOVUK = GOVUK || {};
  GOVUK.Analytics = GOVUK.Analytics || {};
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-26179049-1']);
  if(document.domain=='www.gov.uk') {
    _gaq.push(['_setDomainName', '.www.gov.uk']);
  } else {
    _gaq.push(['_setDomainName', document.domain]);
  }
  _gaq.push(['_setAllowLinker', true]);
</script>
<%# This is here rather than in application to guarantee that GOVUK and _gaq exist %>
<%= javascript_include_tag 'analytics' %>

<script type="text/javascript">
  _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>

<script id="ga-params" type="text/javascript">
  var GOVUK = GOVUK || {};
  GOVUK.Analytics = GOVUK.Analytics || {};
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-26179049-1']);
  if(document.domain=='www.gov.uk') {
    _gaq.push(['_setDomainName', '.www.gov.uk']);
  } else {
    _gaq.push(['_setDomainName', document.domain]);
  }
  _gaq.push(['_setAllowLinker', true]);
    // track pixel density ratio
  if (window.devicePixelRatio) {
    _gaq.push(['_setCustomVar', 11, 'Pixel Ratio', String(window.devicePixelRatio), 2 ]);
  }
</script>
<%# This is here rather than in application to guarantee that GOVUK and _gaq exist %>
<%= javascript_include_tag 'analytics' %>

<script type="text/javascript">
  _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>

Add pixel ratio density tracking in Google Analytics
Add pixel ratio density tracking in Google Analytics 

I've added this to the _google_analytics partial that gets included in the main template because I couldn't find a relevant place to add it in the analytics javascript files are they tracking event success.

I did try adding this to core.js but that would have required another page tracking call to GA which I was worried may have impacted our analytics. Custom Variables must be set before any tracking calls, and as this is where the main tracking call is made, it made sense to me to add it here.

If this is incorrect or there is a better home for this please let me know.