javascript - Google Analytics 和 Google 跟踪代码管理器中的产品范围维度

标签 javascript google-analytics google-tag-manager universal-analytics data-layer

我需要通过 Google 跟踪代码管理器将我的产品范围自定义维度传递到 Google Analytics(分析)。我能够读取产品对象数组中的第一个变量。在我的 Analytics 中,根本没有显示任何自定义维度(甚至是所有维度中的第一个值)。

我已在 Analytics 中将自定义维度设置为产品范围: enter image description here

然后在 GTM 中,我在标签中设置了自定义维度。 enter image description here

在尺寸值中,我使用了进入结构并找到变量productSize的变量。

enter image description here

这是我的代码:

<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/

相关文章:

javascript - 保护图像不被复制

javascript - Node/Express/Angular 服务器端外部 API 请求

javascript - webpack 加载 AMD 模块而不捆绑

wordpress - Google Analytics(分析)中的着陆页分析和所有页面分析有什么区别

google-analytics - Google Analytic 帐号的所有者离开了公司,如何找回?

javascript - 从 GTM 数据层中的数组中提取数据

google-analytics - 如何使用Google跟踪代码管理在所有其他分析代码之前触发综合浏览量代码?

javascript - 如何在 Javascript 中选择第 N 个 PreviousSibling?

JavaScript setInterval 不适用于 asp net

oracle - 谷歌标签管理器和甲骨文 APEX : Track close dialog