Only the purchase event will include discounts if available, since only the method get_formatted_order() will include the "price after coupon discounts" for each order line item.
Checks:
[x] Does your code follow the WordPress coding standards?
[ ] Have you written new tests for your changes, as applicable?
[x] Have you successfully run tests with your changes locally?
[x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?
Screenshots:
Detailed test instructions:
Checkout the branch of this PR and run npm ci and npm run build
Open Network tab from browser dev console, add google-analytics as the filter
Add some products into the cart, for example, two products.
Go to checkout page
Apply a coupon
Complete the purchase, see the order received page
From the Network tab, find the request with dt: Order Confirmation and en: purchase, which is the purchase event
From this event you should see there are two product parameters starts with pr1 and pr2, e.g.
pr1: id28~nmSingle~caMusic~qt1~pr12~ds12
pr2: id36~nmBeanie with Logo~caAccessories~qt1~pr10~ds8
The pr in the value is the price after coupon discounts, and ds is the amount of coupon discounts.
Add another two products into the carts, complete the order WITHOUT applying any coupons.
You should see there is no ds in the event parameters, and the price is just the regular price.
Additional details:
Changelog entry
Fix - Apply discounts to the ecommerce event if available
Changes proposed in this Pull Request:
Closes #417. This PR fixes a bug that the price in purchase events does not take coupon discounts into account by getting the price after discount using the method
get_total()
inWC_Order_Item_Product
class, and add thediscount
parameter to the ecommerce event.Only the
purchase
event will include discounts if available, since only the methodget_formatted_order()
will include the "price after coupon discounts" for each order line item.Checks:
Screenshots:
Detailed test instructions:
npm ci
andnpm run build
google-analytics
as the filterdt: Order Confirmation
anden: purchase
, which is the purchase eventpr1
andpr2
, e.g.id28~nmSingle~caMusic~qt1~pr12~ds12
id36~nmBeanie with Logo~caAccessories~qt1~pr10~ds8
pr
in the value is the price after coupon discounts, andds
is the amount of coupon discounts.ds
in the event parameters, and the price is just the regular price.Additional details:
Changelog entry