Apply a discount to an ecommerce event

  • Discounts can be applied to items in an ecommerce event by using the discount parameter.

  • Do not use percentage discounts with the discount parameter; instead, provide the value of the discount.

  • You can report on item-level discounts using the "Item coupon", "Order coupon", and "Item revenue" dimensions and metrics.

  • To report on event-level discounts, you will need to create a custom metric.

You can apply a discount to an item in an ecommerce event by adding the discount parameter with the value of the discount. Don't use a percentage for the discount parameter.


Example

A customer applies an $8 discount code ("SAVE20") to an order containing two units of one item and one unit of another item. The discount is allocated as $2 per unit for the first item and $4 per unit for the second. Here's the purchase event tag for this example:

// A user applies the coupon code "SAVE20" to their entire order.
// The order contains two items, each receiving a portion of the discount.
gtag("event", "purchase", {
  'transaction_id': "T_12345",
  'value': 32.00,        // Total value after all discounts
  'currency': "USD",
  'coupon': "SAVE20",    // Order-level coupon code
  'items': [
    {
      'item_id': "SKU_123",
      'item_name': "Blue Widget",
      'price': 8.00,       // Unit price after discount (original 10.00 - 2.00 discount)
      'discount': 2.00,    // Unit discount
      'quantity': 2,
      'coupon': "SAVE20"   // Optional: Item-level coupon can match order-level
    },
    {
      'item_id': "SKU_456",
      'item_name': "Red Widget",
      'price': 16.00,      // Unit price after discount (original 20.00 - 4.00 discount)
      'discount': 4.00,    // Unit discount
      'quantity': 1,
      'coupon': "SAVE20"
    }
  ]
});

Report on the discount

The following dimensions and metrics allow you to report on discount:

Dimension or metric Description
Item coupon The coupon used to purchase an item (e.g., a product you sell).
Order coupon The coupon name or code that you specify for discounted items.
Item discount amount The total discount value from items only. Item discount amount = quantity x discount.
Item revenue The total revenue from items only, excluding tax and shipping. Item revenue = quantity x price.

Handle event-level and item-level discounts

A coupon can be added to the entire order (event-level) or to a specific product (item-level).

  • Order-level: To apply a coupon to the entire transaction, add the coupon parameter at the event level (outside the items array).
  • Item-level: To apply a coupon to a specific item, add the coupon parameter within that specific object in the items array.

If a coupon applies a discount to the entire order (event-level), you should allocate that discount across the items in the event to ensure accurate item-level reporting. In each item object:

  1. Add the discount parameter with the allocated unit discount value for the item.
  2. Set the price to the unit price minus the allocated unit discount for the item.

You can also create a custom metric to report on event-level discounts.