<% if Spree::Gtm.activated? %> <%= javascript_tag do %> <% if @order.present? and @order.email.present? %> dataLayer.push({'transactionEmail': '<%= @order.email %>'}); <% end %> <% if current_page?('/cart') and @order.number.nill? %> dataLayer.push({'cart': [ <%=raw @order.line_items.map { |line_item| "{ 'sku': '#{h line_item.variant.sku}', 'name': '#{h line_item.variant.product.name}', 'category': '', 'price': #{h line_item.price}, 'quantity': #{h line_item.quantity}}" } .join(",") %> ] }); <% end %> <% if @product %> dataLayer.push({'product': [ 'name': '<%= @product.name %>', 'sku': '<%= @product.sku %>', 'price': '<%= @product.price %>' ] }); <% end %> <% if @category %> dataLayer.push({'category': ['name': '<%= @category.name %>']}); <% end %> <% if @search %> dataLayer.push({'search': ['name': '<%= @category.name %>']}); <% end %> <% if @order.present? and @order.user.present? %> dataLayer.push({'userid': '<%= @order.user.id %>'}); <% end %> <% if @order.present? && @order.bill_address.present? %> dataLayer.push({ 'transactionId': '<%= @order.number %>', 'transactionAffiliation': 'Yourcompanyname', 'transactionTotal': <%= @order.total %>, 'transactionTax': <%= @order.additional_tax_total %>, 'transactionShipping': <%= @order.shipment_total %>, 'transactionCity': '<%= @order.bill_address.city %>', 'transactionState': '<%= @order.bill_address.state_text %>', 'transactionZip': '<%= @order.bill_address.zipcode %>', 'transactionEmail': '<%= @order.email %>', 'transactionProducts': [ <%=raw @order.line_items.map { |line_item| "{ 'sku': '#{h line_item.variant.sku}', 'name': '#{h line_item.variant.product.name}', 'category': '', 'price': #{h line_item.price}, 'quantity': #{h line_item.quantity}}" } .join(",") %> ] }); <% if @order.user.present? and @order.user.orders.complete.count==1 %> dataLayer.push({ 'event': 'first_time_user_conversion' }); <% end %> <% end %> <% end %> <% end %>