【发布时间】:2020-10-04 09:05:21
【问题描述】:
决定使用谷歌推荐的安装谷歌分析的新方法:“gtag.js”
我已按照说明衡量“增强型电子商务”,作为该构建的一部分,这是我衡量产品点击的代码:
gtag('event', 'select_content', {
"content_type": "product",
"items": [
{
"id": "TEST-SKU-1",
"name": "Test Product",
"list_name": "Home Page",
"category": "For Testing",
"list_position": 1,
"price": 8.76
}
]
});
然后我将该代码添加到产品的链接上,如下所示:
<a href="/for-testing/test-product-1" onclick="gtag('event', 'select_content', { 'content_type': 'product', 'items': [{ 'id': 'TEST-SKU-1', 'name': 'Test Product', 'list_name': 'Home Page', 'category': 'For Testing', 'list_position': 1, 'price': 8.76 }] });">
它显示在 Google Analytics 事件中(它有效),但它显示为“参与”/“选择内容”/“产品”的事件类别/操作/标签。在做了一些研究之后,看起来谷歌正在自动为我构建事件,基于他们想要做的一些新的“标准方式”:-(
问题: 当我发送“产品点击”时,如何覆盖它使用的事件类别/操作/标签的 gtag.js 默认值?
注意: 我意识到我可以将 gtag.js 换成 analytics.js 或我可以使用 jQuery's post() method 并直接通过 Google Analytics' Measurement Protocol 发送,但这不是我的问题......我需要弄清楚“新的正确的非hacky方式”......最好。
【问题讨论】: