<% if tracker = Spree::Tracker.current %>

  <%= javascript_tag do -%>
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
  <% end -%>

  <%= javascript_tag do -%>
    var pageTracker = _gat._getTracker("<%= tracker.analytics_id %>");
    pageTracker._initData();
    pageTracker._trackPageview();
  <% end -%>

  <% if flash[:commerce_tracking] %>

    <%= javascript_tag do -%>
      // report e-commerce transaction information when applicable
      pageTracker._addTrans(
      "<%= @order.number %>",    //Order Number
      "",    //Affiliation
      "<%= @order.total %>",    //Order total
      "<%= @order.adjustments.tax.sum(:amount).to_s %>",    //Tax Amount
      "<%= @order.adjustments.shipping.sum(:amount).to_s %>",    //Ship Amount
      "",    //City
      "",    //State
      ""    //Country
      );
      <% @order.line_items.each do |line_item| %>
        pageTracker._addItem("<%= @order.number %>", "<%= line_item.variant.sku %>", "<%= line_item.variant.product.name %>",
          "" /*Product Category*/, "<%= line_item.price %>", "<%= line_item.quantity %>");
      <% end %>
      pageTracker._trackTrans();
    <% end -%>

  <% end %>

<% end %>
