This repository has been archived by the owner on May 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathadditional-scripts.min.liquid
18 lines (14 loc) · 2.85 KB
/
additional-scripts.min.liquid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{%- if first_time_accessed -%}
<script> var dataLayerData = {'page': {'template': 'Checkout > Success', 'currentPage': {{ current_page | json }}, 'currency': {{ shop.currency | json }}, }, 'customer': {}, 'transaction': {}, 'cart': {}, 'product': {}, 'collection': {} }; {%- if customer -%} dataLayerData.customer = {'id': {{ customer.id | json }}, 'firstName': {{ customer.first_name | json }}, 'surname': {{ customer.last_name | json }}, 'email': {{ customer.email | json }}, 'ordersCount': {{ customer.orders_count | json }}, 'totalSpent': {{ customer.total_spent | money_without_currency | json }}, 'acceptsMarketing': {{ customer.accepts_marketing | json }}, 'tags': {{ customer.tags | json }} }; {%- endif -%} dataLayerData.transaction = {'status': {{ checkout.order.financial_status | json }}, 'id': {{ checkout.order.order_number | json }}, 'subtotal': {{ checkout.order.subtotal_price | money_without_currency | json}}, 'total': {{ checkout.order.total_price | money_without_currency | json }}, 'tax': {{ checkout.order.tax_price | money_without_currency | json }}, 'shipping': {{ checkout.order.shipping_price | money_without_currency | json }}, 'shippingMethod': {{ checkout.order.shipping_methods.first.title | json }}, 'paymentType': {{ checkout.order.transactions.first.gateway | json }}, 'date': {{ checkout.order.created_at | date:"%Y-%m-%d" |json }}, 'currency': {{ shop.currency | json }}, 'discounts': [ {%- for discount in checkout.order.discounts -%} {'title': {{ discount.title | json }}, 'code': {{ discount.code | json }}, 'amount': {{ discount.amount | money_without_currency json }} }, {%- endfor -%} ], 'transactionProducts': [ {%- for line_item in checkout.order.line_items -%} {'id': {{ line_item.product_id | json }}, 'sku': {{ line_item.sku | json}}, 'name': {{ line_item.title | json }}, 'price': {{ line_item.line_price | money_without_currency | json }}, 'quantity': {{ line_item.quantity | json }}, 'category': {{ line_item.product.type | json }}, 'brand': {{ line_item.product.vendor | json }}, 'variant': {{ line_item.variant.title | json }}, 'variant_id': {{ line_item.variant_id | json }} }, {%- endfor -%} ] }; window.dataLayer = window.dataLayer || []; window.dataLayer.push(dataLayerData); </script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
{%- endif -%}