Last active
December 7, 2017 11:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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