chexton
12/17/2014 - 12:06 AM

shopify.js

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>