how to correctly write a function

Viewed 29

how to correctly write a function for a variable (custom javascript) in google tag manager? from this:

function() {
  'items': eshop.product.options.length === 0 ? [{
     'id': eshop.product.id,
     'google_business_vertical': 'retail'
      }] : eshop.product.options.map(function (option) {
        return {
          'id': eshop.product.id.toString() + '_' + option.id,
           'google_business_vertical': 'retail'
         };
      }) 
}

still have some error. Thanks for help.

Petiman

1 Answers

ok I got it..

function () {
var prods = eshop.product;
return  eshop.product.options.length === 0 ? [{
            'id': eshop.product.id,
            'google_business_vertical': 'retail'
        }] : eshop.product.options.map(function (option) {
            return {
                'id': eshop.product.id.toString() + '_' + option.id,
                'google_business_vertical': 'retail'
            };
        }) 
}
Related