动态产品列表GTM标签删除了无效产品

时间:2019-06-05 14:13:28

标签: google-tag-manager facebook-pixel

GTM FB PIXEL购买数据与空白项目一起返回。 当前,我有一个“硬编码”变量,它期望项目位于所述索引中。当购物车装满时,效果很好,但我想知道是否有一种方法可以动态确定所述变量的值是否为空。

所以我也想在Google标记管理器上完成所有这些工作,可以很容易地用javascript完成,但是我正在为数据层使用通用模型函数。试图保持我的代码库精简。

fbq('track', 'Purchase', {
    value: {{DLV - ecommerce.purchase.actionField.revenue}},
    currency: 'USD',
    content_type: 'product',
    content_ids: ['{{DLV - ecommerce.purchase.products.0.id}}','{{DLV - ecommerce.purchase.products.1.id}}','{{DLV - ecommerce.purchase.products.2.id}}','{{DLV - ecommerce.purchase.products.3.id}}','{{DLV - ecommerce.purchase.products.4.id}}','{{DLV - ecommerce.purchase.products.5.id}}'],
    products:['{{DLV - ecommerce.purchase.products.0.name}}','{{DLV - ecommerce.purchase.products.1.name}}','{{DLV - ecommerce.purchase.products.2.name}}','{{DLV - ecommerce.purchase.products.3.name}}','{{DLV - ecommerce.purchase.products.4.name}}','{{DLV - ecommerce.purchase.products.5.name}}'],
    price:['{{DLV - ecommerce.purchase.products.0.price}}','{{DLV - ecommerce.purchase.products.1.price}}','{{DLV - ecommerce.purchase.products.2.price}}','{{DLV - ecommerce.purchase.products.3.price}}','{{DLV - ecommerce.purchase.products.4.price}}','{{DLV - ecommerce.purchase.products.5.price}}',] 
    });

1 个答案:

答案 0 :(得分:0)

将此添加到标签中

function() {
  var products = {{DLV - ecommerce.purchase.products}};
  return products.map(function(prod) { return prod.id; });
}