% if settings.FEATURES.get('SEGMENT_IO_LMS'):
<!-- begin Segment.io -->
<script type="text/javascript">
  // Asynchronously load Segment.io's analytics.js library
  window.analytics||(window.analytics=[]),window.analytics.methods=["identify","track","trackLink","trackForm","trackClick","trackSubmit","page","pageview","ab","alias","ready","group","on","once","off"],window.analytics.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics}};for(var i=0;i<window.analytics.methods.length;i++){var method=window.analytics.methods[i];window.analytics[method]=window.analytics.factory(method)}window.analytics.load=function(t){var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n)},window.analytics.SNIPPET_VERSION="2.0.8",
  analytics.load("${ settings.SEGMENT_IO_LMS_KEY }");
  analytics.page();

  % if user.is_authenticated():
    window.identifyUser("${user.id}", "${user.email}", "${user.username}");
  % endif
</script>
<!-- end Segment.io -->
% else:
<!-- dummy segment.io -->
<script type="text/javascript">
  var analytics = {
    track: function() { return; },
    pageview: function() { return; }
  };
</script>
<!-- end dummy segment.io -->
% endif
