Skip to content

Instantly share code, notes, and snippets.

@chexton
Created December 17, 2014 00:06
Show Gist options
  • Save chexton/c9694d9632fe98657e65 to your computer and use it in GitHub Desktop.
Save chexton/c9694d9632fe98657e65 to your computer and use it in GitHub Desktop.
shopify.js
//
//--------
//1. Edit theme.liquid, add this before </head>. REPLACE THE API KEY AREA OF THIS SNIPPET
<script type="text/javascript">
var _veroq = _veroq || [];
_veroq.push(['init', { api_key: 'YOUR_API_KEY' } ]);
_veroq.push(['trackPageview']);
(function() {var ve = document.createElement('script'); ve.type = 'text/javascript'; ve.async = true; ve.src = '//getvero.com/assets/m.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ve, s);})();
</script>
{% if shop.customer_accounts_enabled and customer %}
<script>
_veroq.push(['user', {
email: '{{ customer.email }}',
first_name: '{{ customer.first_name }}',
last_name: '{{ customer.last_name }}',
customer_id: '{{ customer.id }}',
order_count: '{{ customer.orders_count }}',
total_spent: '{{ customer.total_spent }}'
}]);
</script>
{% endif %}
//
//--------
//2. Edit cart.liquid in your theme and add this to the bottom:
{% if cart.item_count > 0 %}
<script>
products = [];
jQuery(document).ready(function(){
{% for line in cart.items %}
products.push({
'product_id': '{% if line.sku and line.sku != "" %}{{ line.sku }}{% else %}{{ line.product.id }}{% endif %}',
'price': '{{ line.price | money_without_currency }}',
'quantity': '{{ line.quantity }}',
'title': '{{ line.title }}',
'url': '{{ shop.url }}{{ line.product.url }}',
'image_url': '{{ line.product.featured_image | product_img_url}}'
});
{% endfor %}
_veroq.push(['track', 'viewed_cart', {products: products}])
});
</script>
{% endif %}
//
//--------
//3. Add this in the conversion snippets box for checkout, i.e here: https://testgetvero.myshopify.com/admin/settings/payments
<script type="text/javascript">
var _veroq = _veroq || [];
_veroq.push(['init', { api_key: 'YOUR_API_KEY' } ]);
(function() {var ve = document.createElement('script'); ve.type = 'text/javascript'; ve.async = true; ve.src = '//getvero.com/assets/m.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ve, s);})();
</script>
<script>
products = [];
jQuery(document).ready(function(){
_veroq.push(['user', {
email: '{{ customer.email }}',
first_name: '{{ customer.first_name }}',
last_name: '{{ customer.last_name }}',
customer_id: '{{ customer.id }}',
order_count: '{{ customer.orders_count }}',
total_spent: '{{ customer.total_spent }}'
}]);
{% for line in line_items %}
_veroq.push (['track', 'purchased_product', {
'order_number': '{{ order_number }}',
'order_date': '{{ created_at }}',
'product_id': '{% if line.sku and line.sku != "" %}{{ line.sku }}{% else %}{{ line.product.id }}{% endif %}',
'price': '{{ line.price | money_without_currency }}',
'quantity': '{{ line.quantity }}',
'title': '{{ line.title }}',
'url': '{{ shop.url }}{{ line.product.url }}',
'image_url': '{{ line.product.featured_image | product_img_url}}'
}]);
products.push({
'order_number': '{{ order_number }}',
'order_date': '{{ created_at }}',
'product_id': '{% if line.sku and line.sku != "" %}{{ line.sku }}{% else %}{{ line.product.id }}{% endif %}',
'price': '{{ line.price | money_without_currency }}',
'quantity': '{{ line.quantity }}',
'title': '{{ line.title }}',
'url': '{{ shop.url }}{{ line.product.url }}',
'image_url': '{{ line.product.featured_image | product_img_url}}'
});
{% endfor %}
_veroq.push(['track', 'checked_out', {products: products}]);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment