So i have created a custom Pixel based on the checkout_completed. I want to get the product value without tax but I cannot find the right variable i need to use. Currently i am using finalLinePrice variable but this is including tax. Any Ideas if it is possible?
Hello Richard,
The checkout_completed
event payload offers multiple different money amounts for the different part of the cart.
event.data.checkout.lineItems[0].variant.price
gives the price of a product variant before taxes and discounts.event.data.checkout.subtotalPrice
gives the total for the cart after discounts but before taxes.
If you’d like to figure out the total price for a single line item, before taxes (and discounts), you can compute it using:
const lineItem = event.data.checkout.lineItems[0];
const price = lineItem.variant.price * lineItem.quantity;
Hope this helps!
Hi Emileber,
I have tried this but appears that it is still including the tax.
const price = lineItem.variant.price
const price = lineItem.finalLinePrice.amount
these are both producing the same values, Not sure if there is a way in checkout_completed
to get the tax rate or something so it can be calculated on the fly as not all products will have the same tax rate.
Hmmm?! That’s odd!
While it’s not impossible to figure out the tax amount using event.data.checkout.totalTax.amount
, I would not recommend trying to use it to compute the tax rate since it might differ from item to item. It’s fine to compute the average tax rate for the whole cart, but that’s about it.
Would you mind sharing the store on which you’re testing your pixel? If you do mind, you could also contact support officially, which would open a ticket and eventually reach our team.
What details do you need? The name is royalfinessdev
So I looked into that store and it is configured to use tax-inclusive pricing. This means that tax amount is included into the line item price, and right now, there are no ways to track the tax amount in this situation inside web pixels.
We’re planning on adding the tax amount per line item, but no ETA unfortunately.
added to my feeble attempt to get a list going for Shopify What is the roadmap for Custom/Web Pixels - #5 by zamartz
Sorry for hijacking this thread. It’s somewhat related as we also deal with lineitem tax logic in our web pixel and webservice (since some merchants use different product categories which can have different tax lines or don’t include tax). Piggybacking onto what we have already shared on the Slack channel and after some investigations of handling lineitem level tax logic by using GraphQL order API look-ups:
The current inconsistencies between the web pixel checkout_completed
event data and the order API response make it difficult to perform correct calculations.
We do this to get line-item level tax information to be able to properly calculate and track item prices before tax in non-US countries.
- A client uses the Bundles app (Shopify Bundles - Offer fixed bundles and multipacks to drive more sales | Shopify App Store). In the
checkout_completed
event the product ID of the bundle is returned in thelineItems
array (e.g."7792157392996"
). When we look up the order via GraphQL, the ID of the individual product in the bundle is returned (e.g."gid://shopify/Product/6607721398372"
) instead. We noticed that because the merchant hasn’t defined a SKU for the bundle, but for the product in the bundle. And we use the SKU to match the item from the extension with the item from the API look-up. But in this case they are different. Also the variant id:"44020553318500"
vs."gid://shopify/ProductVariant/43017171501156"
. So we don’t have a match and can’t determine tax information for this lineitem. - The same client, this time they added a free product to the order (buy one, get the same free, who knows). On the order it’s the same product twice.
The first one is free and therefore doesn’t have any tax and the second is not free and includes tax. When we look up the first item in the API response (the free one) we get the free one, no tax, great. When we look up the 2nd product (the one for 9.59) our filter matches it with the first (free) product because it has the same SKU, same variant ID. Therefore we don’t deduct tax though that product is taxable. We thought about using the lineItems
id but they are totally different between checkout_completed
event ("703a9256db7d42b92c89d4f3ef18f669"
) and order API ("gid://shopify/LineItem/13354082205796"
).
So there are some annoying inconsistencies I would say. Any reasons why it was done this way? Any way to match lineItems
ids between web pixel and API data? Happy to provide more order details if helpful.