Hey,
We're having two issues with the transaction values that are added to the dataLayer on the order success page. On this page, we've set a 'Universal Analytics' trigger in our Google Tag Manager with the track type 'Transaction'. Without any further configuration, this trigger successfully sends some variables to analytics. However, there seem to be some inconsistencies between the values of the variables: some are including tax, some are not. The transactionTax
variable also seems to have a complete incorrect value.
My first question is: in our previous Magento 1.x setups with another module that generated the dataLayer, the value that was sent to analytics which is shown in the "Revenue" column when viewing conversions, was the revenue on the order excluding tax but also excluding shipping costs, since these are sent to and shown in analytics separately. The transactionTotal
variable in this module is the grand total of the order including tax and shipping costs, and this is the value that shows up in our "Revenue" column. I could be wrong, but shouldn't this value be the total revenue on products in the order, excluding shipping, excluding tax? Or is there a way to use the transactionSubtotal
variable to fill the "Revenue" column in stead? How should we set up our trigger? Or are we seeing things wrong and is there some documentation or resource that suggests the revenue column should actually include shipping and tax, meaning there's nothing wrong with this module's implementation ๐?
Second, I believe the transactionTax
value is calculated incorrectly. Let's take an example order to illustrate:
1 x Product โฌ25,50 (incl. 21% TAX)
Subtotal โฌ25,50 (incl. 21% TAX)
Shipping โฌ4,95 (incl. 21% TAX)
TAX โฌ5,28 (โฌ4,42 product, โฌ0,86 shipping)
Total โฌ30,45 (incl. 21% TAX)
The values that are added to the dataLayer for this order are:
transactionTotal: 30.45, //Order total incl. shipping and tax
transactionSubtotal: 21.07, //Order total excl. shipping and tax
transactionTax: 9.38, //TAX + shipping excl. tax
transactionShipping: 4.1 //Shipping costs excl. tax
In order.phtml
the transactionTax
value is calculated as follows: $order->getGrandTotal() - $order->getSubtotal());
, but what this essentially does is it subtracts the subtotal of the products (21,07) from the grand total of the order, including shipping costs (25,50 + 4,95), leaving us with a value (9,38) that is built up of our TAX (5,28) and the shipping costs excluding TAX (4,10).
Isn't there something like $order->getTaxAmount()
that can give us the correct amount without having to calculate it ourselves?
Sorry for the wall of text, hope it's clear enough!
Thanks :)