Skip to content

Instantly share code, notes, and snippets.

@dfrdmn
Last active April 28, 2017 19:23
Show Gist options
  • Save dfrdmn/0647f98681e59251f4c07b899edf51c7 to your computer and use it in GitHub Desktop.
Save dfrdmn/0647f98681e59251f4c07b899edf51c7 to your computer and use it in GitHub Desktop.
Google remarketing code for Shopify
{% comment %}Create a file called `google-remarketing.liquid` in the snippets subdirectory of your template with the following code. Be sure to insert your merchant ID.{% endcomment %}
{% if template contains 'index' %}
<script type="text/javascript">
var google_tag_params = {
ecomm_pagetype: 'home',
};
</script>
{% elsif template contains 'collection' %}
<script type="text/javascript">
var google_tag_params = {
ecomm_pagetype: 'category',
};
</script>
{% elsif template contains 'product' %}
<script type="text/javascript">
var google_tag_params = {
ecomm_prodid: '{{ product.metafields.google.gmc_id }}',
ecomm_pagetype: 'product',
ecomm_totalvalue: {{ product.price | money_without_currency }}
};
</script>
{% elsif template contains 'cart' %}
<script type="text/javascript">
var google_tag_params = {
ecomm_prodid: [{% for item in cart.items %}'{{item.product.id}}'{% unless forloop.last %},{% endunless %}{% endfor %}],
ecomm_pagetype: 'cart',
ecomm_totalvalue: {{cart.total_price | money_without_currency }}
}
</script>
{% elsif template contains 'search' %}
<script type="text/javascript">
var google_tag_params = {
ecomm_pagetype: 'searchresults'
}
</script>
{% else %}
<script type="text/javascript">
var google_tag_params = {
ecomm_pagetype: 'other',
};
</script>
{% endif %}
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = << INSERT MERCHANT 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/<< INSERT MERCHANT ID >>/?value=0&amp;guid=ON&amp;script=0" />
</div>
</noscript>
{% comment %} In Settings -> Checkout -> Additional scripts, add the following{% endcomment %}
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = << INSERT MERCHANT 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/<< INSERT MERCHANT ID>>/?value=0&amp;guid=ON&amp;script=0" />
</div>
</noscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment