Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Chris Beardsley
Added: Jan 22, 2019 3:50 PM
Views: 17
Tags: no tags
It basically runs through the products object and pulls all variables out and let us rename them to match the Facebook pixel naming. Feel free to copy it, and let me know if you have any improvements or comments
  1. function createFacebookData(){
  2. var contents = [];
  3. for(var i = 0; i < {{dlv - ecommerce.purchase.products}}.length; i++) {
  4.   var product = {{dlv - ecommerce.purchase.products}}[i];
  5.   var content = {"id": product["id"], "quantity": product["quantity"], "item_price": product["price"] };
  6.   contents.push(content);
  7. }
  8. return contents}