我需要通过 Google 跟踪代码管理器将我的产品范围自定义维度传递到 Google Analytics(分析)。我能够读取产品对象数组中的第一个变量。在我的 Analytics 中,根本没有显示任何自定义维度(甚至是所有维度中的第一个值)。
在尺寸值中,我使用了进入结构并找到变量productSize的变量。
这是我的代码:
<script>
dataLayer.push({
'event': 'productImpression',
'ecommerce': {
'impressions': [
{
'name': 'Android tričko',
'id': '12345',
'price': '299',
'brand': 'Google',
'category': 'Pánská trička',
'variant': 'bílá',
'list': 'Search Results',
'productSize': 'L', // product scoped custom dimension
'position': 1
},
{
'name': 'Donut Friday Scented T-Shirt',
'id': '67890',
'price': '33.75',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Black',
'list': 'Search Results',
'productSize': 'XL', // product scoped custom dimension
'position': 2
}]
}
});
</script>
正如我所说,问题是我只能读取自定义维度(“L”)的第一个值(显然)。我应该写什么而不是变量点表示法中的零符号来获取所有值(“L”,“XL”)?
我需要将每个产品的所有值传递到 Analytics 中。我是否必须将每个产品推送到单独的 dataLayer.push() 中?我在 Analytics 中根本看不到任何内容的问题出在哪里?请帮忙。
最佳答案
您不能使用通过界面为维度指定的名称。您必须使用 "dimension" keyword plus the numeric index (创建顺序),因此在您的示例中,报告中称为“productSize”的维度将在代码中被寻址为“dimension1”:
...
'list': 'Search Results',
'dimension1': 'L', // product scoped custom dimension
'position': 1
...
之后,GA 会自动从数据层中选择您的维度。
关于javascript - Google Analytics 和 Google 跟踪代码管理器中的产品范围维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40450926/