ovipreneur

shopify ecom datal

Jan 18th, 2021 (edited)
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {%- if first_time_accessed -%}  
  2.  
  3.    <!-- Google Tag Manager -->
  4. <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  5. new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  6. j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  7. 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  8. })(window,document,'script','dataLayer','GTM-KNSXM2X');</script>
  9. <!-- End Google Tag Manager -->
  10.  
  11. <!-- Global site tag (gtag.js) - Google Ads: 387260955 -->
  12. <script async src="https://www.googletagmanager.com/gtag/js?id=AW-387260955"></script>
  13. <script>
  14.   window.dataLayer = window.dataLayer || [];
  15.   function gtag(){dataLayer.push(arguments);}
  16.   gtag('js', new Date());
  17.  
  18.   gtag('config', 'AW-387260955');
  19. </script>
  20.  
  21. {% if first_time_accessed %}
  22. <!-- Event snippet for Test conversion page -->
  23. <script>
  24.   gtag('event', 'conversion', {
  25.     'send_to': 'AW-387260955/PBJHCJX45IACEJvE1LgB',
  26.     'value': {{ checkout.subtotal_price | divided_by: 100.0 }},
  27.     'currency': '{{ currency }}',
  28.     'transaction_id': '{{ order_number }}',
  29.   });
  30. </script>
  31. {% endif %}
  32.  
  33. <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>
  34.  
  35. <script>
  36. dataLayer.push({
  37. 'event':'purchase',
  38.   'ecommerce': {
  39.     'purchase': {
  40.       'actionField': {
  41.         'id': '{{ checkout.order.order_number }}',                         // Transaction ID.
  42.         'affiliation': 'Online Store',
  43.         'revenue': '{{ checkout.order.subtotal_price | money_without_currency}}',                    
  44.         'tax':'{{checkout.order.tax_price | money_without_currency}}',
  45.         'shipping': '{{checkout.order.shipping_price | money_without_currency}}',
  46.         'coupon': '{{ discount.code}}'
  47.       },
  48.       'products': [{%- for line_item in checkout.order.line_items -%} {'id': {{ line_item.variant_id }}, 'name': {{ line_item.title }}, 'price': {{ line_item.line_price | money_without_currency | json }}, 'quantity': {{ line_item.quantity }}, 'brand': ‘Neolastin’}, {%- endfor -%} ]
  49.     }
  50.   }
  51. });
  52. </script>
  53.  
  54. <script>
  55. window.dataLayer = window.dataLayer || [];
  56.  window.dataLayer.push({
  57.  'event': 'purchase'
  58.  });
  59. </script>
  60.  
  61.  
  62. {%- endif -%}
Add Comment
Please, Sign In to add comment