# New datalayer variable in TMS for the ID of the reservation

**URL:** <https://community.piwik.pro/t/new-datalayer-variable-in-tms-for-the-id-of-the-reservation/445>\
**Category:** Data collection and tags\
**Created:** [January 31, 2022, 2:57pm UTC](https://community.piwik.pro/t/new-datalayer-variable-in-tms-for-the-id-of-the-reservation/445 "2022-01-31T14:57:13Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![pslonina](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/pslonina/32/1711_2.png) [@pslonina](https://community.piwik.pro/u/pslonina)\
**Post date:** [February 1, 2022, 10:59am UTC](https://community.piwik.pro/t/new-datalayer-variable-in-tms-for-the-id-of-the-reservation/445/2 "2022-02-01T10:59:31Z")

</div>

Hi Cédric, thanks for reaching out!

The recommended approach for both - datalayer events structure and for the e-commerce tracking PPTM tags is described [In this thread](https://community.piwik.pro/t/how-to-set-up-ecommerce-tracking/79/2).

That said - it’s obviously not the only way. You could use a PPTM datalayer variable, but you would need to fetch the whole `ecommerce` object and then iterate through on the custom HTML tag level. Unfortunately, it’s not possible to refer to nested attributes of a datalayer object directly. It would look roughly like this:

**For cart update:**

```auto
<script>
    var _paq = _paq || [];
    var orderDetails = {{ ecommerce object }};
    var products = orderDetails.purchase.products;
    var cart_amount = orderDetails.purchase.actionField.revenue;

    products.forEach(function (product) {
        _paq.push(["addEcommerceItem", product.id, product.name, product.category, product.price, product.quantity])
    });
    _paq.push(["trackEcommerceCartUpdate", cart_amount]);
</script>

```

**For order confirmation**

```auto
<script>
    var _paq = _paq || [];
    var orderDetails = {{ ecommerce object }};
    var products = orderDetails.purchase.products;
    var order_id = orderDetails.purchase.actionField.id;
    var grand_total = orderDetails.purchase.actionField.revenue;

    products.forEach(function(product){
      _paq.push(["addEcommerceItem",product.id, product.name, product.category, product.price, product.quantity])
  });
    _paq.push(["trackEcommerceOrder",order_id, grand_total]);
  </script>

```

`{{ ecommerce object }}` is a PPTM datalayer variable `ecommerce`.

I hope the above helps!  
Thanks,  
Piotr

---

_[View the full topic](https://community.piwik.pro/t/new-datalayer-variable-in-tms-for-the-id-of-the-reservation/445)._
