Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- INICIO SCRIPT PARA GERAR DATALAYER →
- {% comment %} Purchase data layer v2.1 - part of "Shopify GA4 Kit" by Analyzify
- Visit https://analyzify.app/shopify-google-analytics/ga4 for complete tutorial
- {% endcomment %}
- {% assign template_name = template.name %}
- <script type="text/javascript">
- window.dataLayer = window.dataLayer || [];
- window.appStart = function(){
- window.allPageHandle = function(){
- window.dataLayer.push({
- event: "ga4kit_info",
- contentGroup: "{{ template_name }}",
- {% if customer %}
- userType: "member",
- customer: {
- id: "{{- checkout.customer.id | json -}}",
- lastOrder: "{{- customer.last_order.created_at | date: '%B %d, %Y %I:%M%p' -}}",
- orderCount: "{{- checkout.customer.orders_count | json -}}",
- totalSpent: "{{- checkout.customer.total_spent | times: 0.01 | json -}}",
- tags: {{- checkout.customer.tags | json -}}
- }
- {% else %}
- userType: "visitor",
- {% endif %}
- });
- };
- allPageHandle();
- {% if first_time_accessed and post_purchase_page_accessed != true %}
- var shippingPrice = "{{shipping_price | money_without_currency }}".replace(",", ".");
- var totalPrice = "{{checkout.total_price | money_without_currency }}".replace(",", ".");
- var taxPrice = "{{tax_price | money_without_currency }}".replace(",", ".");
- var orderItemsName = [];
- var orderItemsId = [];
- var orderItemsCategory = [];
- var orderItemsBrand = [];
- var orderItemsType = [];
- var orderItemsPrice = [];
- var orderItemsSku = [];
- var orderItemsvariantId = [];
- var orderItemsQuantity = [];
- var orderItemsvariantTitle = [];
- var totalQuantity = 0;
- {% for line_item in checkout.line_items %}
- orderItemsName.push("{{ line_item.product.title | remove: "'" | remove: '"'}}");
- orderItemsId.push("{{ line_item.product_id }}");
- orderItemsPrice.push("{{ line_item.price | times: 0.01 }}");
- orderItemsSku.push("{{ line_item.sku | remove: "'" | remove: '"' }}");
- orderItemsQuantity.push("{{ line_item.quantity }}");
- orderItemsvariantId.push("{{ line_item.variant_id }}");
- orderItemsvariantTitle.push("{{ line_item.variant.title }}");
- orderItemsCategory.push("{{ line_item.product.collections.last.title | remove: "'" | remove: '"' }}");
- orderItemsBrand.push("{{ line_item.vendor | remove: "'" | remove: '"' }}");
- orderItemsType.push("{{ line_item.product.type | remove: "'" | remove: '"' }}");
- totalQuantity += {{ line_item.quantity }};
- {% endfor %}
- window.dataLayer.push({
- page_type: "purchase",
- event: "analyzify_purchase",
- currency: "{{ shop.currency }}",
- totalValue: totalPrice,
- totalValueStatic: totalPrice,
- currencyRate: window.Shopify.currency.rate,
- shipping: shippingPrice,
- tax: taxPrice,
- payment_type: "{{order.transactions[0].gateway}}",
- {% if order.name %}
- transaction_id: "{{order.name | remove: "'" | remove: '"'}}",
- {% else %}
- transaction_id: "{{checkout.id | remove: "'" | remove: '"'}}",
- {% endif %}
- productName: orderItemsName,
- productId: orderItemsId,
- productBrand: orderItemsBrand,
- productCategory: orderItemsCategory,
- productVariantId: orderItemsvariantId,
- productVariantTitle: orderItemsvariantTitle,
- productSku: orderItemsSku,
- productType: orderItemsSku,
- productPrice: orderItemsPrice,
- productQuantity: orderItemsQuantity,
- });
- {% endif %}
- }
- appStart();
- </script>
- <script>
- var ecommerce = {
- 'transaction_id': '{{checkout.order_number | json}}',
- 'affiliation': {{shop.name | json}},
- 'value': {{checkout.total_price | money_without_currency | replace: ',', '.' | json}},
- 'tax': {{checkout.tax_price | money_without_currency | replace: ',','.' | json}},
- 'shipping': {{checkout.shipping_price | money_without_currency | replace: ',','.' | json}},
- 'subtotal': {{checkout.subtotal_price | money_without_currency| replace: ',','.' | json}},
- 'currency': {{checkout.currency | json}},
- {% for discount in checkout.discounts %}
- 'coupon': {{discount.code | json}},
- 'discount' : {{discount.amount | money_without_currency | json}},
- {% endfor %}
- 'email': {{checkout.email | json}},
- 'phone': {{checkout.phone | json}},
- 'first_name': {{customer_address.first_name | json}},
- 'fullName' : {{checkout.billing_address.name | json}},
- 'firstName' : {{checkout.billing_address.first_name | json}},
- 'lastName' : {{checkout.billing_address.last_name | json}},
- 'address1' : {{checkout.billing_address.address1 | json}},
- 'address2' : {{checkout.billing_address.address2 | json}},
- 'street' : {{checkout.billing_address.street | json}},
- 'city' : {{checkout.billing_address.city | json}},
- 'province' : {{checkout.billing_address.province | json}},
- 'province_code' : {{checkout.billing_address.province_code | json}},
- 'customer_id' : {{checkout.customer_id | json}},
- 'zip' : {{checkout.billing_address.zip | json}},
- 'country' : {{checkout.billing_address.country | json}},
- 'country_code' : {{checkout.billing_address.country_code | json}},
- 'phone' : {{checkout.billing_address.phone | json}},
- 'items':[{% for line_item in checkout.line_items %}{
- 'item_id' :{{line_item.product.id | json}},
- 'item_variant' : {{line_item.variant.title | json}},
- 'item_name' : {{line_item.product.title | json}},
- 'price' : {{line_item.product.price | money_without_currency | replace: ',', '.' | json}},
- 'item_brand' : {{line_item.product.vendor | json}},
- 'item_category' : {{line_item.product.type | json}},
- 'item_list_name' : {{line_item.collection.title | json}},
- 'quantity' : {{line_item.quantity | json}},
- 'discount' : {{discount.code | json}}
- },{% endfor %}],
- };
- (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-M5LTPDF’);
- window.dataLayer.push({
- 'pageType': 'purchase',
- 'event': 'purchase',
- ecommerce
- });
- </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-M5LTPDF');</script>
- <!-- End Google Tag Manager -->
- <!-- FIM SCRIPT PARA GERAR DATALAYER -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement