Skip to content

Instantly share code, notes, and snippets.

@mariadanieldeepak
Last active December 7, 2017 11:15
Show Gist options
  • Save mariadanieldeepak/1ceb49ce3abf859b526f7ab7232033c0 to your computer and use it in GitHub Desktop.
Save mariadanieldeepak/1ceb49ce3abf859b526f7ab7232033c0 to your computer and use it in GitHub Desktop.
Use this script on the Thank You Page in Shopify to send the values to GTM
<!-- Start: Send variables to GTM -->
<script type="text/javascript">
{% if checkout.order_id or checkout.id %}
var productId = "",
isInsolesOnlyOrder = "true";
{% for line_item in checkout.line_items %}
{% if line_item.product.type != 'Insole' %}
isInsolesOnlyOrder = "false";
{% endif %}
productId += "{{ line_item.product.id }}";
productId += ",";
{% endfor %}
// Remove the last comma from ProductId.
if ( productId.indexOf( "," ) > -1 ) {
productId = productId.slice( 0, -1 );
}
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'isInsolesOnlyOrder': isInsolesOnlyOrder
});
window.dataLayer.push({
'productId': productId
});
{% endif %}
</script>
<!-- End: Send variables to GTM -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment