Sha256: 0cf65e89920c93a5ff1f77fae0ef5c29d7ac3ffe4e0192119027ede2efa7f411

Contents?: true

Size: 1.91 KB

Versions: 6

Compression:

Stored size: 1.91 KB

Contents

<% if tracker = Spree::Tracker.current %>
  <script>
    (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', '<%= tracker.analytics_id %>');
    ga('send', 'pageview');

    <% if flash[:commerce_tracking] && @order.present? %>
      <%# more info: https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce %>
      ga('require', 'ecommerce', 'ecommerce.js');
      ga('ecommerce:addTransaction', {
        'id': '<%= j @order.number %>',                                    // Transaction ID. Required.
        'affiliation': '<%= Spree::Config[:site_name] %>',                // Affiliation or store name.
        'revenue': '<%= @order.total %>',                                // Grand Total.
        'shipping': '<%= @order.adjustments.shipping.sum(:amount) %>',  // Shipping.
        'tax': '<%= @order.adjustments.tax.sum(:amount) %>',           // Tax.
        'currencyCode': '<%= current_currency %>'                     // local currency code.
      });
      <% @order.line_items.each do |line_item| %>
        ga('ecommerce:addItem', {
          'id': '<%= j @order.number %>',                        // Transaction ID. Required.
          'name': '<%= j line_item.variant.product.name %>',    // Product name. Required.
          'sku': '<%= j line_item.variant.sku %>',             // SKU/code.
          'category': '',                                     // Category or variation.
          'price': '<%= line_item.price %>',                 // Unit price.
          'quantity': '<%= line_item.quantity %>'           // Quantity.
        });
      <% end %>
      ga('ecommerce:send');
    <% end %>
  </script>
<% end %>

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_frontend-2.1.5 app/views/spree/shared/_google_analytics.html.erb
spree_frontend-2.1.4 app/views/spree/shared/_google_analytics.html.erb
spree_frontend-2.1.3 app/views/spree/shared/_google_analytics.html.erb
spree_frontend-2.1.2 app/views/spree/shared/_google_analytics.html.erb
spree_frontend-2.1.1 app/views/spree/shared/_google_analytics.html.erb
spree_frontend-2.1.0 app/views/spree/shared/_google_analytics.html.erb