Google Analytics4:如何使用GTM五分钟部署增强版电子商务基础代码+事件代码?
Google Analytics4:如何使用GTM五分钟部署增强版电子商务基础代码+事件代码?
Last edited 2022-9-9
type
Post
status
Published
date
Jan 23, 2022
slug
summary
使用GA4五分钟部署增强电子商务事件代码。
tags
数据
category
外贸
icon
password

1.使用GTM部署基础GA4代码。

创建GA4账号,添加网站,然后创建GTM账号,在代码中。英文界面是tags新建GA代码。下图中1,比如按照我的名称命名:GA4 – Pageview – All pages 否则之后的事件倒入会报错。下图2中,要把你的GA4所属的ID填对了,第一步结束。
notion image

2.开启基础事件收集;

这个设置在GA4后台,网站→数据流→增强型衡量功能→点螺母(设置进入)把基础监测事件全打开。
notion image

3.批量导入电子商务通用事件代码;

在GTM后台,点管理就可以看到我截图中的导入页面了。导入空间导入到已有的默认空间即可。导入内容把我下面代码框里的代码找个编辑器另存为json文件就行。
notion image
要导入的JSON事件代码如下:
{ "exportFormatVersion": 2, "exportTime": "2022-04-19 11:19:17", "containerVersion": { "path": "accounts/000000/containers/000000/versions/0", "accountId": "000000", "containerId": "000000", "containerVersionId": "0", "container": { "path": "accounts/000000/containers/000000", "accountId": "000000", "containerId": "000000", "name": "Sandbox", "publicId": "GTM-ABCDEFG", "usageContext": [ "WEB" ], "fingerprint": "1576569098586", "tagManagerUrl": "https://tagmanager.google.com/#/container/accounts/000000/containers/000000/workspaces?apiLink=container" }, "tag": [ { "accountId": "000000", "containerId": "000000", "tagId": "49", "name": "GA4 - Event - Ecommerce events", "type": "gaawe", "parameter": [ { "type": "TEMPLATE", "key": "eventName", "value": "{{Event}}" }, { "type": "LIST", "key": "eventParameters", "list": [ { "type": "MAP", "map": [ { "type": "TEMPLATE", "key": "name", "value": "items" }, { "type": "TEMPLATE", "key": "value", "value": "{{Ecommerce Items}}" } ] }, { "type": "MAP", "map": [ { "type": "TEMPLATE", "key": "name", "value": "transaction_id" }, { "type": "TEMPLATE", "key": "value", "value": "{{Ecommerce Transaction ID}}" } ] }, { "type": "MAP", "map": [ { "type": "TEMPLATE", "key": "name", "value": "affiliation" }, { "type": "TEMPLATE", "key": "value", "value": "{{Ecommerce Affiliation}}" } ] }, { "type": "MAP", "map": [ { "type": "TEMPLATE", "key": "name", "value": "value" }, { "type": "TEMPLATE", "key": "value", "value": "{{Ecommerce Value}}" } ] }, { "type": "MAP", "map": [ { "type": "TEMPLATE", "key": "name", "value": "tax" }, { "type": "TEMPLATE", "key": "value", "value": "{{Ecommerce Tax}}" } ] }, { "type": "MAP", "map": [ { "type": "TEMPLATE", "key": "name", "value": "shipping" }, { "type": "TEMPLATE", "key": "value", "value": "{{Ecommerce Shipping}}" } ] }, { "type": "MAP", "map": [ { "type": "TEMPLATE", "key": "name", "value": "currency" }, { "type": "TEMPLATE", "key": "value", "value": "{{Ecommerce Currency}}" } ] }, { "type": "MAP", "map": [ { "type": "TEMPLATE", "key": "name", "value": "coupon" }, { "type": "TEMPLATE", "key": "value", "value": "{{Ecommerce Coupon}}" } ] } ] }, { "type": "TAG_REFERENCE", "key": "measurementId", "value": "GA4 - Pageview - All pages" } ], "fingerprint": "1616577384388", "firingTriggerId": [ "48" ], "tagFiringOption": "ONCE_PER_EVENT", "monitoringMetadata": { "type": "MAP" } } ], "trigger": [ { "accountId": "000000", "containerId": "000000", "triggerId": "48", "name": "Event - Ecommerce Events GA4", "type": "CUSTOM_EVENT", "customEventFilter": [ { "type": "MATCH_REGEX", "parameter": [ { "type": "TEMPLATE", "key": "arg0", "value": "{{_event}}" }, { "type": "TEMPLATE", "key": "arg1", "value": "view_item|view_item_list|select_item|add_to_cart|remove_from_cart|view_cart|begin_checkout|add_payment_info|add_shipping_info|purchase" } ] } ], "fingerprint": "1618830267653" } ], "variable": [ { "accountId": "000000", "containerId": "000000", "variableId": "47", "name": "Ecommerce", "type": "v", "parameter": [ { "type": "INTEGER", "key": "dataLayerVersion", "value": "1" }, { "type": "BOOLEAN", "key": "setDefaultValue", "value": "false" }, { "type": "TEMPLATE", "key": "name", "value": "ecommerce" } ], "fingerprint": "1616577307324", "formatValue": {} }, { "accountId": "000000", "containerId": "000000", "variableId": "50", "name": "Ecommerce Transaction ID", "type": "v", "parameter": [ { "type": "INTEGER", "key": "dataLayerVersion", "value": "2" }, { "type": "BOOLEAN", "key": "setDefaultValue", "value": "false" }, { "type": "TEMPLATE", "key": "name", "value": "ecommerce.transaction_id" } ], "fingerprint": "1616574945268", "formatValue": {} }, { "accountId": "000000", "containerId": "000000", "variableId": "51", "name": "Ecommerce Affiliation", "type": "v", "parameter": [ { "type": "INTEGER", "key": "dataLayerVersion", "value": "2" }, { "type": "BOOLEAN", "key": "setDefaultValue", "value": "false" }, { "type": "TEMPLATE", "key": "name", "value": "ecommerce.affiliation" } ], "fingerprint": "1616574959867", "formatValue": {} }, { "accountId": "000000", "containerId": "000000", "variableId": "52", "name": "Ecommerce Value", "type": "v", "parameter": [ { "type": "INTEGER", "key": "dataLayerVersion", "value": "2" }, { "type": "BOOLEAN", "key": "setDefaultValue", "value": "false" }, { "type": "TEMPLATE", "key": "name", "value": "ecommerce.value" } ], "fingerprint": "1616574975594", "formatValue": {} }, { "accountId": "000000", "containerId": "000000", "variableId": "53", "name": "Ecommerce Tax", "type": "v", "parameter": [ { "type": "INTEGER", "key": "dataLayerVersion", "value": "2" }, { "type": "BOOLEAN", "key": "setDefaultValue", "value": "false" }, { "type": "TEMPLATE", "key": "name", "value": "ecommerce.tax" } ], "fingerprint": "1616574992994", "formatValue": {} }, { "accountId": "000000", "containerId": "000000", "variableId": "54", "name": "Ecommerce Shipping", "type": "v", "parameter": [ { "type": "INTEGER", "key": "dataLayerVersion", "value": "2" }, { "type": "BOOLEAN", "key": "setDefaultValue", "value": "false" }, { "type": "TEMPLATE", "key": "name", "value": "ecommerce.shipping" } ], "fingerprint": "1616575006484", "formatValue": {} }, { "accountId": "000000", "containerId": "000000", "variableId": "55", "name": "Ecommerce Currency", "type": "v", "parameter": [ { "type": "INTEGER", "key": "dataLayerVersion", "value": "2" }, { "type": "BOOLEAN", "key": "setDefaultValue", "value": "false" }, { "type": "TEMPLATE", "key": "name", "value": "ecommerce.currency" } ], "fingerprint": "1616575020448", "formatValue": {} }, { "accountId": "000000", "containerId": "000000", "variableId": "56", "name": "Ecommerce Coupon", "type": "v", "parameter": [ { "type": "INTEGER", "key": "dataLayerVersion", "value": "2" }, { "type": "BOOLEAN", "key": "setDefaultValue", "value": "false" }, { "type": "TEMPLATE", "key": "name", "value": "ecommerce.coupon" } ], "fingerprint": "1616575036302", "formatValue": {} }, { "accountId": "000000", "containerId": "000000", "variableId": "57", "name": "Ecommerce Items", "type": "jsm", "parameter": [ { "type": "TEMPLATE", "key": "javascript", "value": "function() {\n var ecom = {{Ecommerce}};\n if ( ecom && ecom.items ) {\n return ecom.items;\n } else {\n return undefined;\n }\n}" } ], "fingerprint": "1616577368052", "formatValue": {} } ], "fingerprint": "1618831157840", "tagManagerUrl": "https://tagmanager.google.com/#/versions/accounts/000000/containers/000000/versions/0?apiLink=version" } }
notion image

4.在GTM变量中开启下图中的内置变量;

notion image

5.发布GTM代码,别忘了用Tag assistant验证。

 
Done.^_^
  • 数据
  • TouchStone3-6学习笔记:Managing life.TouchStone3-5学习笔记:Food Choices.