# How to setup Ecomstack
Create a snippet called "ecomstack.liquid" and paste the following code:
Example
<!-- Ecomstack script start -->
<script>
(function(){
var d = window.location.hostname.replace ("www.",""); //replace this with your own domain, if you need the script to run anywhere
var fl = function (u) {
var l = document.createElement('script'); l.type = 'text/javascript'; l.async = true; l.src = u;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(l, s);
};
fl ("https://files2.vtcdn.net/" + d + "/loader.min.js");
window._vteq = window._vteq || [];
setTimeout(function(){if (!window._vtsdk) {fl ('https://storage.googleapis.com/cdn.vtcdn.net/' + d + '/loader.js');}}, 1100);
})();
</script>
{% if request.path contains 'products/' %}
<script>
window._vteq = window._vteq || [];
window._vteq.push({
"viewitem": {
itemId: "{{ product.selected_or_first_available_variant.id }}"
}
});
</script>
{% endif %}
{% if request.path contains 'collections/' %}
<script>
window._vteq = window._vteq || [];
window._vteq.push({
"viewcategory": {
category: "{{ collection.id }}"
}
});
</script>
{% endif %}
{% if search.terms %}
<script>
window._vteq = window._vteq || [];
window._vteq.push({
"search": {
query: "{{ search.terms }}"
}
});
</script>
{% endif %}
{% if request.path contains 'checkout' %}
<script>
window._vteq = window._vteq || [];
window._vteq.push({
checkout: {
step: "one-step-checkout",
items: [{% for item in cart.items %}"{{ item.variant.id }}"{% unless forloop.last %},{% endunless %}{% endfor %}]
}
});
</script>
{% endif %}
{% if request.path contains "checkout/thanks/" %}
<script>
var items = [
{% for line_item in order.line_items %}
{
id: {{ line_item.variant.id }},
quantity: {{ line_item.quantity }}
}{% unless forloop.last %},{% endunless %}
{% endfor %}
];
window._vteq = window._vteq || [];
window._vteq.push({
confirmation: {
items: items,
email: "{{ order.email }}",
orderId: {{ order.id }},
total: {{ order.total_price | divided_by: 100 | round }}
}
});
</script>
{% endif %}
<!-- Ecomstack script end -->
Save it and include it in your theme file just before the closing of your tag.