在使用gtag中的功能之前,您总是需要调用gtag.js。在HTML文档中,您始终放置以下代码:
<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-XXXXXXXXX'); gtag('config', 'AW-XXXXXXXXX', {'send_page_view': false}); </script>
启动后,您可以将数据发送到GA和您的案例广告。在大多数情况下,电子商务数据在页面加载之前就已经可用。所以你应该能够在以下位置发送这些信息:
<script> gtag('event', 'purchase', { "send_to": "AW-XXXXXXXX/<Conversion Label>", "transaction_id": "24.031608523954162", "affiliation": "Google online store", "value": 23.07, "currency": "USD", "tax": 1.24, "shipping": 0, "items": [ { "id": "P12345", "name": "Android Warhol T-Shirt", "list_name": "Search Results", "brand": "Google", "category": "Apparel/T-Shirts", "variant": "Black", "list_position": 1, "quantity": 2, "price": '2.0' }, { "id": "P67890", "name": "Flame challenge TShirt", "list_name": "Search Results", "brand": "MyBrand", "category": "Apparel/T-Shirts", "variant": "Red", "list_position": 2, "quantity": 1, "price": '3.0' } ] }); </script>
资源: https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#2_track_checkout_options https://developers.google.com/adwords-remarketing-tag/
我的建议是使用Google跟踪代码管理器来启用数字营销工具,而不是代码中。您将在使用的工具中获得更多自由,但当然,仍然需要进行一些代码更改。
希望,这澄清了一些东西。
干杯, 拉乌尔