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

  <%= javascript_tag do -%>
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', '<%= tracker.analytics_id -%>']);
    _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);
    })();
    <% 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 %>
