forked from analyzify/shopify-ga4-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{% comment %} Purchase data layer v2.0 - part of "Shopify GA4 Kit" by Analyzify | ||
Visit https://analyzify.app/shopify-google-analytics/ga4 for complete tutorial | ||
{% endcomment %} | ||
|
||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
var shipping_price = '{{shipping_price | money_without_currency }}'; | ||
shipping_price = shipping_price.replace(",", "."); | ||
var total_price = '{{total_price | money_without_currency }}'; | ||
total_price = total_price.replace(",", "."); | ||
var tax_price = '{{tax_price | money_without_currency }}'; | ||
tax_price = tax_price.replace(",", "."); | ||
var orderItemsName = [] | ||
var orderItemsPrice = [] | ||
var orderItemsQuantity = [] | ||
var orderItemsId = [] | ||
var totalQuantity = 0; | ||
|
||
{% for line_item in line_items %} | ||
orderItemsName.push( '{{ line_item.product.title | remove: "'" | remove: '"'}}') | ||
orderItemsPrice.push('{{ line_item.price | times: 0.01 }}'); | ||
orderItemsQuantity.push('{{ line_item.quantity }}'); | ||
orderItemsId.push('{{ line_item.product_id }}'); | ||
totalQuantity += {{ line_item.quantity }}; | ||
{% endfor %} | ||
|
||
{% if first_time_accessed %} | ||
window.dataLayer.push({ | ||
'page_type': 'purchase', | ||
'event': 'analyzify_purchase', | ||
'currency': "{{ shop.currency }}", | ||
'totalValue': total_price, | ||
'shipping': shipping_price, | ||
'tax': tax_price, | ||
'payment_type': '{{order.transactions[0].gateway}}', | ||
'transaction_id': "{{order.name}}", | ||
'productName': orderItemsName, | ||
'productPrice': orderItemsPrice, | ||
'productQuantity': orderItemsQuantity, | ||
'productId': orderItemsId, | ||
}); | ||
{% endif %} | ||
</script> | ||
|