javascript loop google tag manager

I'm trying to lop through the items of an order to push the data to a third party. The order data is going through (tid, tval) but the loop through the items of the order doesn't seem to be working.

<!-- RetentionScience start -->
<script type='text/javascript'>
  var _rsq = _rsq || [];
    _rsq.push(['_setSiteId', '1130']);
    _rsq.push(['_enableOnsite']); 

  if ({{dlv - visitorLoginState}} === "logged-in") { 
    _rsq.push(['_setUserId', {{dlv - visitorId}}]);
    //_rsq.push(['_setUserEmail','user_email']); 
  }
  
  /*** EVENT SPECIFIC CODE ***/
  var items = {{dlv - ecommerce.items}};
  var prods = {{dlv - ecommerce.purchase.products}};
  var tid = {{dlv_transaction_id}};
  var tval = {{dlv_revenue}};
  _rsq.push(['_addOrder', {'id': tid, 'total': tval}]);
  
//  for (var i = 0; i < items.length; i++) {
  _rsq.push(['_addItem', {
 'id': {{dlv - ecommerce.add.products.0.id}},
 'name': {{dlv - ecommerce.add.products.0.name}},
 'price': {{dlv - ecommerce.add.products.0.price}}
}]); 
  
_rsq.push(['_setAction', 'checkout_success']);

  /*** END EVENT SPECIFIC CODE ***/

_rsq.push(['_track']);

(function() {
  var rScix = document.createElement('script');
    rScix.type = 'text/javascript';
    rScix.async = true;
    rScix.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + '.cloudfront.net/waves/v3/w.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(rScix);
  })();
</script>
<!-- RetentionScience end -->

I've also tried with a foreach loop without much luck:

  /*** EVENT SPECIFIC CODE ***/

  var prods = {{dlv - ecommerce.purchase.products}};
  var tid = {{dlv_transaction_id}};
  var tval = {{dlv_revenue}};
  _rsq.push(['_addOrder', {'id': tid, 'total': tval}]);
  items.forEach(function(el){
  rsq.push(['_addItem', {
 'id': el.id,
 'name': el.name,
 'price': el.price
}]);
  }) 
_rsq.push(['_setAction', 'checkout_success']);

  /*** END EVENT SPECIFIC CODE ***/