Facebook 像素购买 body 事件

Facebook pixel purchase body event

我正在尝试购买 facebookEvent,它需要一个 objects "Products" 数组,其中包含此数组中每个产品的 ID 和数量,我在这里问的是我尝试分配到事件有效负载内的产品数组中循环,但编译器抱怨说,有人可以通过如何使内容数组响应整个产品数组来提供帮助吗?

  //fbp
  (<any>window).fbq("track", "Purchase", {
    value: this.totalPrice,
    currency: "EGP",
    contents: [
      {
        // this should be applicable for every single item on the arrayOfProducts
        id: arrayOfProducts[0].id,
        quantity: arrayOfProducts[0].quantity
      }
    ],
    content_type: "product"
  });

What i mean by my questions is, how to push the whole arrayOfProducts instead of passing only the first item on the array ?

使用map

//fbp
  (<any>window).fbq("track", "Purchase", {
    value: this.totalPrice,
    currency: "EGP",
    contents: arrayOfProducts.map(function(item) {
        return {
           id: item.id,
           quantity: item.quantity
        }
    }),
    content_type: "product"
  });