Skip to content

Instantly share code, notes, and snippets.

@ryantownsend
Created March 3, 2015 15:20
Show Gist options
  • Select an option

  • Save ryantownsend/07bbe847f510364df15b to your computer and use it in GitHub Desktop.

Select an option

Save ryantownsend/07bbe847f510364df15b to your computer and use it in GitHub Desktop.
{% if qubit_page_type == blank %}
{% assign qubit_page_type = "Content" %}
{% endif %}
{% if cart_delivery_price == null %}
{% include 'cart_delivery_price' %}
{% endif %}
<script>
{% assign line_item_index = 0 %}
{% assign discount_index = 0 %}
window.universal_variable = {
version: "1.2.0",
events: [],
page: {
type: "{{ qubit_page_type }}"
{% if collection != blank %}
, breadcrumb: ["{{ collection.title }}"]
{% elsif qubit_page_type == "Content" %}
, breadcrumb: [
{% if article != blank %}
"{{ article.blog.title }}",
"{{ article.title }}"
{% elsif blog != blank %}
"{{ blog.title }}"
{% else %}
"{{ page_title }}"
{% endif %}
]
{% endif %}
},
{% if product %}
product: {
id: "{{ product.id }}",
url: "http://{{ shop.domain }}{{ product.url }}",
name: "{{ product.title }}",
{% if collection != blank %}
category: "{{ collection.title }}",
{% else if product.collections.size > 0 %}
category: "{{ product.collections.first.title }}",
{% endif %}
currency: "{{ shop.currency }}",
unit_price: {{ product.selected_or_first_available_variant.price | divided_by: 100.0 }},
unit_sale_price: {{ product.selected_or_first_available_variant.price | divided_by: 100.0 }},
sku_code: "{{ product.selected_or_first_available_variant.sku }}",
stock: {{ product.selected_or_first_available_variant.inventory_quantity }}
},
{% endif %}
{% if collection and template contains 'collection' %}
listing: {
items: [
{% paginate collection.products by 500 %}
{% for product in collection.products %}
{% if forloop.index > 1 %},{% endif %}
{
id: "{{ product.id }}",
url: "http://{{ shop.domain }}{{ product.url }}",
name: "{{ product.title }}",
{% if collection != blank %}
category: "{{ collection.title }}",
{% else if product.collections.size > 0 %}
category: "{{ product.collections.first.title }}",
{% endif %}
currency: "{{ shop.currency }}",
unit_price: {{ product.selected_or_first_available_variant.price | divided_by: 100.0 }},
unit_sale_price: {{ product.selected_or_first_available_variant.price | divided_by: 100.0 }},
sku_code: "{{ product.selected_or_first_available_variant.sku }}",
stock: {{ product.selected_or_first_available_variant.inventory_quantity }}
}
{% endfor %}
{% endpaginate %}
]
},
{% endif %}
{% if customer %}
user: {
name: "{{ customer.name }}",
user_id: "{{ customer.id }}",
email: "{{ customer.email }}",
language: "en-gb"{% if customer.orders.size > 0 %},
returning: true,
has_transacted: true{% endif %}
},
{% else %}
user: {
language: "en-gb"
},
{% endif %}
basket: {
currency: "{{ shop.currency }}",
subtotal: {{ cart.total_price | divided_by: 100.0 }},
subtotal_include_tax: true,
tax: {{ cart.total_price | times: 0.2 | divided_by: 100.0 }},
total: {{ cart.total_price | divided_by: 100.0 }},
line_items: [
{% for line_item in cart.items %}
{% assign line_item_index = line_item_index | plus: 1 %}
{% if line_item_index > 1 %},{% endif %}
{
product: {
id: "{{ line_item.id }}",
url: "http://{{ shop.domain }}{{ line_item.variant.url }}",
name: "{{ line_item.title }}",
currency: "{{ shop.currency }}",
category: "{{ line_item.product.collections.first.title }}",
unit_price: {{ line_item.price | divided_by: 100.0 }},
unit_sale_price: {{ line_item.line_price | divided_by: 100.0 }},
sku_code: "{{ line_item.sku }}",
stock: {{ line_item.variant.inventory_quantity }}
},
quantity: {{ line_item.quantity }},
subtotal: {{ line_item.line_price | divided_by: 100.0 }}
}
{% endfor %}
],
shipping_cost: {{ cart_delivery_price | divided_by: 100.0 }}
}
}
</script>
<script src="//d3c3cq33003psk.cloudfront.net/opentag-104025-1369374.js"
async="async" defer="defer"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment