Setting custom dimension value for trackEcommerceOrder

Hi,

I added custom dimensions in trackEcommerceOrder but purchase tracking no longer works :
(Google Tag Manager)

<script>
var subTotal = {{ecommerce.purchase.actionField.revenue}} - {{ecommerce.purchase.actionField.shipping}};

_paq.push(["addEcommerceItem",
    "{{ecommerce.purchase.products.0.id}}",                     // SKU
    "{{ecommerce.purchase.products.0.name}}",               	// name
    "{{ecommerce.purchase.products.0.category}}",               // category
     {{ecommerce.purchase.products.0.price}},                 	// price
     parseFloat({{ecommerce.checkout.products.0.quantity}})   	// quantity
]);

// custom
_paq.push(['setCustomDimensionValue', 7, '{{ecommerce.checkout.products.0.dimension9}}']); //custom-9
_paq.push(['setCustomDimensionValue', 8, '{{ecommerce.checkout.products.0.dimension10}}']); //custom-10
  
// track order
_paq.push(["trackEcommerceOrder",
    "{{ecommerce.purchase.actionField.id}}",            // ID
     {{ecommerce.purchase.actionField.revenue}},        // grand total (value + tax + discount + shipping)
     subTotal,        					// sub total (value + tax + discount)
    0,                                                  // tax
    {{ecommerce.purchase.actionField.shipping}},        // shipping
    0                                                   // discount
]);
</script>

This method however seems to work for trackEcommerceCartUpdate and addEcommerceItem.

Thanks

Hi,

I would guess that this error has not only something to do with your custom dimensions but rather your attempt to access an undefined value and parse it to a float. There should be an error message in the console.

You are accessing {{ecommerce.checkout.products.0.quantity}} which will most likely be unset in a purchase. And even in a purchase it might be unset anyway and so you should use a fallback value. Try changing the line

parseFloat({{ecommerce.checkout.products.0.quantity}})

to

parseFloat({{ecommerce.purchase.products.0.quantity}}||“1”)

and see if data appears in the debugger again.

The custom dimensions will be unset as well because you will need to access the purchase instead of a checkout object here, too (I guess). Looks like a copy & paste classic (?)

best,
Markus