Shopify安装Google Tag Manager并推送purchase购买事件

Posted by: Fengjiajun Comments: 0

Shopify安装Google Tag Manager并推送purchase购买事件

本节教程介绍了Shopify如何安装Google Tag Manager,并推送purchase购买事件到Google Tag Manager。

一、Shopify如何安装Google Tag Manager:

首先需要创建Google Tag Manager账户,并获取一段Google Tag Manager的安装代码,将代码复制并粘贴到下面的路径文件:
Online Store – Themes – theme.liquid文件;

二、推送Shopify的purchase购买事件到Google Tag Manager:
找到左下角的Settings – Checkout – Additional Scripts,添加如下代码:

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null });
{% if first_time_accessed %}
dataLayer.push({
  event: "purchase",
  ecommerce: {
      transaction_id: "{{ order.order_number }}",
      value: {{ total_price | times: 0.01 }},
      tax: {{ tax_price | times: 0.01 }},
      shipping: {{ shipping_price | times: 0.01 }},
      currency: "{{ order.currency }}",
      items: [
       {% for line_item in line_items %}{
        item_id: "{{ line_item.product_id }}",
        item_name: "{{ line_item.title | remove: "'" | remove: '"' }}",
        currency: "{{ order.currency }}",
        price: {{ line_item.final_price | times: 0.01 }},
        quantity: {{ line_item.quantity }}
      },{% endfor %}
 ]
  }
});
{% endif %}
</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-EXAMPLE');</script>
  <!-- End Google Tag Manager -->

注意:上面的代码中,请替换GTM-EXAMPLE的ID为自己的实际ID;

三、在Google Tag Manager中为purchase购买事件添加电子商务参数,首先我们需要创建一些变量:

其他对应的变量:
Ecommerce Items:ecommerce.items
Ecommerce Transaction ID:ecommerce.transaction_id
Ecommerce Value:ecommerce.value
Ecommerce Tax:ecommerce.tax
Ecommerce Shipping:ecommerce.shipping
Ecommerce Currency:ecommerce.currency

四、为购买事件创建触发器,便于Google ads转化跟踪调用: