opengovernment/askthem

View on GitHub
app/views/shared/_chartbeat.html.erb

Summary

Maintainability
Test Coverage
<% if Rails.env.production? && ENV["CHARTBEAT_HOSTNAME"].present? -%>
<script type="text/javascript">
  var _sf_async_config = { uid: <%= ENV["CHARTBEAT_UID"] -%>, domain: '<%= ENV["CHARTBEAT_HOSTNAME"] -%>', useCanonical: true };
  (function() {
    function loadChartbeat() {
      window._sf_endpt = (new Date()).getTime();
      var e = document.createElement('script');
      e.setAttribute('language', 'javascript');
      e.setAttribute('type', 'text/javascript');
      e.setAttribute('src','//static.chartbeat.com/js/chartbeat.js');
      document.body.appendChild(e);
    };
    var oldonload = window.onload;
    window.onload = (typeof window.onload != 'function') ?
      loadChartbeat : function() { oldonload(); loadChartbeat(); };
  })();
</script>
<% end -%>