Skip to content

Instantly share code, notes, and snippets.

@joe-dempsey
Created January 31, 2019 12:37
Show Gist options
  • Save joe-dempsey/c2dbf5304ebef407167c669b18096f81 to your computer and use it in GitHub Desktop.
Save joe-dempsey/c2dbf5304ebef407167c669b18096f81 to your computer and use it in GitHub Desktop.
main ad implementation tracking liquid
<!---------------------------below code to go in theme ---------------------------------- -->
<!---------------------------below code to go in theme ---------------------------------- -->
<!---------------------------below code to go in theme ---------------------------------- -->
{% capture url %}{{ shop.domain }}{% endcapture %}
{% capture collectionsList %}{% for collection in product.collections %}{{ collection.title | strip | strip_html | escape }}|,;{% endfor %}{% endcapture %}
{% capture stock %}{% if product.available %}1{% else %}0{% endif %}{% endcapture %}
{% assign current_variant = product.selected_or_first_available_variant %}
{% capture token %}add_unique_token{% endcapture %}
{% if template contains 'index' %}
<!---------------------------mainad loaded ---------------------------------- -->
<!---------------------------Home Pixel Start---------------------------------- -->
<script type='text/javascript'>
rtgsettings ={
'pdt_url': '{{url }}',
'pagetype': 'home',
'key': 'WG',
'token': '{{ token }}',
'layer': 'iframe'
};
(function(d) {
var s = d.createElement('script'); s.async = true;s.id='madv2014rtg';s.type='text/javascript';
s.src = (d.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.mainadv.com/Visibility/Rtgwg2-min.js';
var a = d.getElementsByTagName('script')[0]; a.parentNode.insertBefore(s, a);
}(document));
</script>
<!---------------------------Home Pixel END---------------------------------- -->
{% elsif template contains 'collection' %}
<!---------------------------Category Pixel Start---------------------------------- -->
<script type='text/javascript'>
rtgsettings ={
'pdt_url': '{{url }}',
'pdt_category_list': '{{ collection.title | escape }}',
'pagetype': 'category',
'key': 'WG',
'token': '{{ token }}',
'layer': 'iframe'
};
(function(d) {
var s = d.createElement('script'); s.async = true;s.id='madv2014rtg';s.type='text/javascript';
s.src = (d.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.mainadv.com/Visibility/Rtgwg2-min.js';
var a = d.getElementsByTagName('script')[0]; a.parentNode.insertBefore(s, a);
}(document));
</script>
<!---------------------------Category Pixel END---------------------------------- -->
{% elsif template contains 'product' %}
<!---------------------------Product Pixel Start---------------------------------- -->
<script type='text/javascript'>
rtgsettings ={
'pdt_id': '{{ product.id }}',
'pdt_sku': '{{ current_variant.sku }}',
'pdt_name': '{{ product.title | escape }}',
'pdt_price': '{{ product.price | money_without_currency }}',
'pdt_amount': '{{ product.price_min | money_without_currency }}',
'pdt_currency': '{{ shop.currency }}',
'pdt_url': '{{url }}{{ product.url }}',
'pdt_photo': '{{ product.featured_image | product_img_url: 'master' }}',
'pdt_instock': '{{ stock }}',
'pdt_expdate': '',
'pdt_category_list': '{{collectionsList }}',
'pdt_smalldescription': '{{ product.description | strip_html | escape | strip_newlines | strip }}',
'pagetype': 'product',
'key': 'WG',
'token': '{{ token }}',
'layer': 'iframe'
};
(function(d) {
var s = d.createElement('script'); s.async = true;s.id='madv2014rtg';s.type='text/javascript';
s.src = (d.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.mainadv.com/Visibility/Rtgwg2-min.js';
var a = d.getElementsByTagName('script')[0]; a.parentNode.insertBefore(s, a);
}(document));
</script>
<!---------------------------Product Pixel END---------------------------------- -->
{% elsif template contains 'cart' %}
<!---------------------------Basket Pixel Start---------------------------------- -->
{% capture orderItemIds %}{% for item in cart.items %}{{ item.product.id }}|,;{% endfor %}{% endcapture %}
{% capture orderItemSKU %}{% for item in cart.items %}{{ item.sku }}|,;{% endfor %}{% endcapture %}
{% capture orderItemsCollections %}{% for item in cart.items %}{% for collection in item.product.collections %}{{ collection.title | strip | strip_html | escape }}|,;{% endfor %}{% endfor %}{% endcapture %}
<script type='text/javascript'>
rtgsettings ={
'pdt_id': '{{ orderItemIds }}',
'pdt_sku': '{{orderItemSKU }}',
'pdt_category_list': '{{ orderItemsCollections }}',
'pdt_url': '{{url }}/cart',
'ty_orderamt':'{{ cart.total_price | money_without_currency }}',
'ty_orderdate':'{{ "now" | date: "%m-%d-%Y" }}',
'ty_orderstatus':'basket',
'pagetype': 'basket',
'key': 'WG',
'token': '{{ token }}',
'layer': 'iframe'
};
(function(d) {
var s = d.createElement('script'); s.async = true;s.id='madv2014rtg';s.type='text/javascript';
s.src = (d.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.mainadv.com/Visibility/Rtgwg2-min.js';
var a = d.getElementsByTagName('script')[0]; a.parentNode.insertBefore(s, a);
}(document));
</script>
<!---------------------------Basket Pixel END------------------------------------>
{% endif %}
<!---------------------------below code to go in checkout conv. scripts ---------------------------------- -->
<!---------------------------below code to go in checkout conv. scripts ---------------------------------- -->
<!---------------------------below code to go in checkout conv. scripts ---------------------------------- -->
<!---------------------------checkout Pixel Start---------------------------------- -->
{% capture orderItemIds %}{% for item in order.line_items %}{{ item.product.id }}|,;{% endfor %}{% endcapture %}
{% capture orderItemSKU %}{% for item in order.line_items %}{{ item.sku }}|,;{% endfor %}{% endcapture %}
{% capture orderItemsCollections %}{% for item in order.line_items %}{% for collection in item.product.collections %}{{ collection.title | strip | strip_html | escape }}|,;{% endfor %}{% endfor %}{% endcapture %}
{% capture token %}add_unique_token{% endcapture %}
<script type='text/javascript'>
rtgsettings ={
'pdt_id': '{{ orderItemIds }}',
'pdt_sku': '{{ orderItemSKU }}',
'pdt_category_list': '{{ orderItemsCollections }}',
'ty_orderid':'{{ order.name }}',
'ty_orderamt':'{{ order.total_price }}',
'ty_orderdate':'{{ order.created_at }}',
'ty_orderstatus':'{{ order.fulfillment_status }}',
'ty_cusname':'{{ order.customer.name }}',
'ty_cusid':'{{ order.customer.id }}',
'ty_custype':'Online shop',
'ty_cuscoupon':'{% for discount_application in order.discount_applications %}{{ discount_application.title }}{% endfor %}',
'pagetype': 'checkout',
'key': 'WG',
'token': '{{ token }}',
'layer': 'iframe'
};
(function(d) {
var s = d.createElement('script'); s.async = true;s.id='madv2014rtg';s.type='text/javascript';
s.src = (d.location.protocol == 'https:' ? 'https:' : 'http:') + '//www.mainadv.com/Visibility/Rtgwg2-min.js';
var a = d.getElementsByTagName('script')[0]; a.parentNode.insertBefore(s, a);
}(document));
</script>
<!---------------------------Checkout Pixel END---------------------------------- -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment