This code works for google Adwords remarketing to capture the specific product a customer viewed
Change the [YOUR ADWORDS ACCOUNT ID] to your actual
<!-- google remarketing tag - Google AdWords -->
{% comment %} Instructions on using the code. Firstly, all the code can be pasted into an empty section at the bottom of your template.liquid file. Secondly, in the line below, where it shows google_conversion_id = 0, delete the 0 and add your conversion id (found in AdWords) {% endcomment %}
{% assign google_conversion_id = [YOUR ADWORDS ACCOUNT ID] %}
{% assign shopify_store_country = 'US' %}
<script type="text/javascript">
{% if template contains 'cart' %}
var google_tag_params = {
ecomm_prodid: [{% for item in cart.items %}'shopify_{{ shopify_store_country }}_{{ item.product.id }}_{{ item.variant.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
ecomm_pagetype: 'cart',
ecomm_totalvalue: {{ cart.total_price | money_without_currency | remove: ',' }}
};
{% elsif template contains 'collection' %}
var google_tag_params = {
ecomm_prodid: [{% for item in collection.products limit:5 %}'shopify_{{ shopify_store_country }}_{{ item.id }}_{{ item.variants.first.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
ecomm_pagetype: 'category',
ecomm_category: '{{ collection.handle }}'
};
{% elsif template contains 'index' %}
var google_tag_params = {
ecomm_pagetype: 'home'
};
{% elsif template contains 'product' %}
var google_tag_params = {
ecomm_prodid: 'shopify_{{ shopify_store_country }}_{{ product.id }}_{{ product.selected_or_first_available_variant.id }}',
ecomm_pagetype: 'product',
ecomm_totalvalue: {{ product.selected_or_first_available_variant.price | money_without_currency | remove: ',' }}
};
{% elsif template contains 'search' %}
var google_tag_params = {
ecomm_prodid: [{% for item in search.results limit:5 %}'shopify_{{ shopify_store_country }}_{{ item.id }}_{{ item.variants.first.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
ecomm_pagetype: 'searchresults'
};
{% elsif template contains 'cart' %}
var google_tag_params = {
ecomm_prodid: [{% for item in search.results limit:5 %}'shopify_{{ shopify_store_country }}_{{ item.id }}_{{ item.variants.first.id }}'{% unless forloop.last %}, {% endunless %}{% endfor %}],
ecomm_pagetype: 'searchresults'
};
{% else %}
var google_tag_params = {
ecomm_pagetype: 'other'
};
{% endif %}
/* <![CDATA[ */
var google_conversion_id = {{ google_conversion_id }};
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/{{ google_conversion_id }}/?value=0&guid=ON&script=0"/>
</div>
</noscript>
<!-- google remarketing tag - Google AdWords -->