<script type="text/javascript">

<% if @options[:tracker] %>
  (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', '<%= @options[:tracker] %>', <%= @tracker_options %>);

<% if @options[:enhanced_link_attribution] %>
  ga('require', 'linkid', 'linkid.js');
<% end %>

<% if @options[:anonymize_ip] %>
  ga('set', 'anonymizeIp', true);
<% end %>

<% if @options[:adjusted_bounce_rate_timeouts] %>
<% @options[:adjusted_bounce_rate_timeouts].each do |timeout| %>
    setTimeout(ga('send', 'event', '<%= "#{timeout.to_s}_seconds" %>', 'read'),<%= timeout*1000 %>);
<% end %>
<% end %>

<% end %>

<% if @options[:tracker_vars]
        @options[:tracker_vars].each do |var|
%>
    ga('send', <%= var.write() %>);
<% end
  end
   %>

<% if @options[:advertising] %>
  ga('require', 'displayfeatures');
<% end %>

<% if @options[:ecommerce] %>
  ga('require', 'ecommerce', 'ecommerce.js');
<% end %>

<% if @options[:tracker] %>
   ga('send', 'pageview');
<% end %>

</script>