Measure ecommerce

Ecommerce reporting provides insight into the shopping behavior of your users, enabling you to quantify your most popular products and see the influence of promotions and product placement on revenue. By setting up events correctly, you can measure common conversion paths and curate better customer experiences.

This article explains how to implement the recommended online sales events and report on the event data. You can see ecommerce event data using the following resources:

For details on implementing ecommerce mobile apps through Firebase, see Measure Ecommerce.

Before you begin

Make sure you've added the Google Analytics: GA4 Configuration tag to your website and can access Analytics and the website source code.

Recommendations

  • Enable debug mode so you can see events in realtime and more easily troubleshoot issues
  • Review the custom dimension and metric limits when sending custom parameters with ecommerce events
  • Set currency when sending value (revenue) data to ensure revenue metrics are calculated correctly
  • Set each ecommerce parameter you have data for, regardless of whether the parameter is optional
  • Use the sample ecommerce website to see an example of how to tag your website

Implementation

Associate products with an event by including an array of items. The items array can include up to 200 elements.

items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    },
    {
      item_id: "SKU_12346",
      item_name: "Google Grey Women's Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 3.33,
      index: 1,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "gray",
      location_id: "L_12345",
      price: 20.99,
      quantity: 1
    }
] 

The parameters above will populate the following dimensions in Google Analytics:

Dimension Value
Item ID SKU_12345
Item name Stan and Friends Tee
Item list position 0
Item brand Google Merchandise Store
Item category Apparel
Item category 2 Adult
Item category 3 Shirts
Item category 4 Crew
Item category 5 Short sleeve
Item list ID related_products
Item list name Related Products
Item location ID L_12345

Migration from legacy ecommerce data layer objects

For those who have previously implemented enhanced ecommerce for Google Analytics web properties and have data layer objects like 'impressions' and 'products', you may continue to use those in place of references to 'items' as shown in this document.

Clearing the ecommerce object

It's recommended that you use the following command to clear the ecommerce object prior to pushing an ecommerce event to the data layer. Clearing the object will prevent multiple ecommerce events on a page from affecting each other.

dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.

Product views and interactions

Measuring product views and interactions provides insight into how often products are shown, viewed, and selected by users. Combined with promotion data, these events can help you measure the effectiveness of campaigns.

View item list

Send the view_item_list event when a user is shown a list of items, along with an items array parameter that includes the displayed items. For details on the parameters to send, see the Events reference.

Example

A user is shown a small collection of shirts on a Related products list. On the page where a user is shown the shirts, you can add the following snippet to your JavaScript that triggers when a user visits the page.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: view_item_list
  • Event Parameter (name - value): 'items' - {{Ecommerce Items}}
  • Variable Type: data layer Variable - 'ecommerce.items'
  • Trigger: event equals view_item_list
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "view_item_list",
  ecommerce: {
    items: [
     {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    },
    {
      item_id: "SKU_12346",
      item_name: "Google Grey Women's Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 3.33,
      index: 1,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "gray",
      location_id: "L_12345",
      price: 20.99,
      promotion_id: "P_12345",
      promotion_name: "Summer Sale",
      quantity: 1
    }]
  }
});

Analytics increments the Item list views metric by 1 each time the event triggers.

View item

Send the view_item event when a user is shown a product, along with an items array parameter that includes the item shown. For details on the parameters to send, see the Events reference.

Example

A user visits a page for a Stan and Friends Tee from the Google Merchandise Store. On the page where a user is shown the shirt, you can add the following snippet to your JavaScript that triggers when a user opens the page.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: view_item
  • Event Parameter (name - value): 'items' - {{Ecommerce Items}}
  • Variable Type: data layer Variable - 'ecommerce.items'
  • Trigger: event equals view_item
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "view_item",
  ecommerce: {
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Analytics increments the Item views metric by 1 each time the event triggers.

Select item

Send the select_item event when a user selects an item from a list, along with an items array parameter that includes the selected item. For details on the parameters to send, see the Events reference.

Example

A user clicks a link from a Related products list that goes to a page for a Stan and Friends Tee. On the page where a user selects the product, you can add the following snippet to an event listener in your JavaScript that triggers when a user clicks to open the product page.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: select_item
  • Event Parameter (name - value): 'items' - {{Ecommerce Items}}
  • Variable Type: data layer Variable - 'ecommerce.items'
  • Trigger: event equals select_item
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "select_item",
  ecommerce: {
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Internal promotions

Internal promotions are a way of advertising one part of your site from another part of your site. For example, you can place a banner on your home page that advertises a 5% discount on shirts. You can use promotion views and clicks to attribute credit to purchases that started with a promotion.

View promotion

Send the view_promotion event when a user is shown a promotion, along with an items array parameter that includes the promoted item. For details on the parameters to send, see the Events reference.

Example

A user views a banner that advertises a promotion for Stan and Friends Tee from the Google Merchandise Store. On the page where a user sees the promotion, you can add the following snippet to your JavaScript that triggers when a user visits the page.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: view_promotion
  • Event Parameter (name - value): 'items' - {{Ecommerce Items}}
  • Variable Type: data layer Variable - 'ecommerce.items'
  • Trigger: event equals view_promotion
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "view_promotion",
  ecommerce: {
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Analytics increments the Item promotion views metric by 1 each time the event triggers.

Select promotion

Send the select_promotion event when a user clicks a promotion, along with an items array parameter that includes the selected item associated with the promotion. For details on the parameters to send, see the Events reference.

Example

A user clicks a promotion for a Stan and Friends Tee from the Google Merchandise Store. On the page where a user is shown the promotion, you can add the following snippet to an event listener in your JavaScript that triggers when a user clicks the promotion.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: select_promotion
  • Event Parameter (name - value): 'items' - {{Ecommerce Items}}
  • Variable Type: data layer Variable - 'ecommerce.items'
  • Trigger: event equals select_promotion
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "select_promotion",
  ecommerce: {
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Analytics increments the Item promotion clicks metric by 1 each time the event triggers.

Shopping cart interactions

These events enable you to measure how often users show an interest in purchasing the products you sell.

Add to cart

Send the add_to_cart event when a user adds an item to their shopping cart, along with an items array parameter that includes the items they added to their cart. For details on the parameters to send, see the Events reference.

Example

A user clicks an "Add to cart" button for a Stan and Friends Tee from the Google Merchandise Store. On the product page, you can add the following snippet to an event listener in your JavaScript that triggers when a user clicks the button.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: add_to_cart
  • Event Parameter (name - value): 'items' - {{Ecommerce Items}}
  • Variable Type: data layer Variable - 'ecommerce.items'
  • Trigger: event equals add_to_cart
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "add_to_cart",
  ecommerce: {
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Analytics updates the following metrics each time the event triggers:

  • The Add-to-carts metric increments by 1
  • The numerator of the Cart-to-view rate metric increments by 1

Add to wishlist

Send the add_to_wishlist event when a user adds an item to their wishlist, along with an items array parameter that includes the item they added to their wishlist. For details on the parameters to send, see the Events reference.

Example

A user clicks an "Add to wishlist" button for a Stan and Friends Tee from the Google Merchandise Store. On the product page, you can add the following snippet to an event listener to your JavaScript that triggers when users click the button:

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: add_to_wishlist
  • Data Layer Variables (Name - Data Layer Variable Name) :
    • Ecommerce Items - ecommerce.items
    • Ecommerce Value - ecommerce.value
    • Ecommerce Currency - ecommerce.currency
  • Event Parameters (Parameter Name - Value):
    • items - {{Ecommerce Items}}
    • value - {{Ecommerce Value}}
    • currency - {{Ecommerce Currency}}
  • Trigger: event equals add_to_wishlist
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "add_to_wishlist",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Remove from cart

Send the remove_from_cart event when a user removes an item from their shopping cart, along with an items array parameter that includes the item they removed. For details on the parameters to send, see the Events reference.

Example

A user clicks a "Remove from cart" button for a Stan and Friends Tee from the Google Merchandise Store. On the shopping cart page, you can add the following snippet to an event listener in your JavaScript that triggers when a user clicks the button.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: remove_from_cart
  • Event Parameter (name - value): 'items' - {{Ecommerce Items}}
  • Variable Type: data layer Variable - 'ecommerce.items'
  • Trigger: event equals remove_from_cart
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "remove_from_cart",
  ecommerce: {
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

View cart

Send the view_cart event when a user views their shopping cart, along with an items array parameter that includes the items in their cart. For details on the parameters to send, see the Events reference.

Example

A user views their shopping cart, where their cart includes a Stan and Friends Tee. On the shopping cart page, you can add the following snippet to your JavaScript that triggers when a user lands on the page.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: view_cart
  • Data Layer Variables (Name - Data Layer Variable Name) :
    • Ecommerce Items - ecommerce.items
    • Ecommerce Value - ecommerce.value
    • Ecommerce Currency - ecommerce.currency
  • Event Parameters (Parameter Name - Value):
    • items - {{Ecommerce Items}}
    • value - {{Ecommerce Value}}
    • currency - {{Ecommerce Currency}}
  • Trigger: event equals view_cart
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "view_cart",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Analytics increments the denominator of the Cart-to-view rate metric by 1 each time the event triggers.

Checkout funnel

The checkout funnel includes the steps from beginning the checkout process to purchasing products. You can visualize each step in the checkout funnel and the number of users who complete each step by creating a funnel exploration.

Begin checkout

Send the begin_checkout event when a user begins the checkout process, along with an items array parameter that includes the items in their cart. For details on the parameters to send, see the Events reference.

Example

A user starts the checkout process (such as clicking a "Checkout" button) to purchase a Stan and Friends Tee from the Google Merchandise Store. On the page where a user begins checkout (for example, on the shopping cart page), you can add the following snippet to an event listener in your JavaScript that triggers when a user clicks a button to begin checkout.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: begin_checkout
  • Event Parameter (name - value): 'items' - {{Ecommerce Items}}
  • Variable Type: data layer Variable - 'ecommerce.items'
  • Trigger: event equals begin_checkout
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "begin_checkout",
  ecommerce: {
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Analytics increments the Checkouts metric by 1 each time the event triggers.

Add payment information

Send the add_payment_info event when a user adds their payment information during checkout, along with an items array parameter that includes the items that the user wants to purchase. For details on the parameters to send, see the Events reference.

Example

A user adds their credit card information to purchase a Stan and Friends Tee from the Google Merchandise Store. On the page where a user adds their payment information, you can add the following snippet to an event listener in your JavaScript that triggers when a user clicks a button to add their payment information.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: add_payment_info
  • Data Layer Variables (Name - Data Layer Variable Name) :
    • Ecommerce Items - ecommerce.items
    • Ecommerce Value - ecommerce.value
    • Ecommerce Currency - ecommerce.currency
    • Ecommerce Coupon - ecommerce.coupon
    • Ecommerce Payment Type - ecommerce.payment_type
  • Event Parameters (Parameter Name - Value):
    • items - {{Ecommerce Items}}
    • value - {{Ecommerce Value}}
    • currency - {{Ecommerce Currency}}
    • coupon - {{Ecommerce Coupon}}
    • payment_type - {{Ecommerce Payment Type}}
  • Trigger: event equals add_payment_info
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "add_payment_info",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    coupon: "SUMMER_FUN",
    payment_type: "Credit Card",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Add shipping information

Send the add_shipping_info event when a user adds their shipping information during checkout, along with an items array parameter that includes the items that the user wants to purchase. For details on the parameters to send, see the Events reference.

Example

A user adds their shipping information to purchase a Stan and Friends Tee from the Google Merchandise Store. On the page where a user adds their shipping information, you can add the following snippet to an event listener in your JavaScript that triggers when a user clicks a button to add their shipping information.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: add_shipping_info
  • Data Layer Variables (Name - Data Layer Variable Name) :
    • Ecommerce Items - ecommerce.items
    • Ecommerce Value - ecommerce.value
    • Ecommerce Currency - ecommerce.currency
    • Ecommerce Coupon - ecommerce.coupon
    • Ecommerce Shipping Tier - ecommerce.shipping_tier
  • Event Parameters (Parameter Name - Value):
    • items - {{Ecommerce Items}}
    • value - {{Ecommerce Value}}
    • currency - {{Ecommerce Currency}}
    • coupon - {{Ecommerce Coupon}}
    • shipping_tier - {{Ecommerce Shipping Tier}}
  • Trigger: event equals add_shipping_info
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "add_shipping_info",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    coupon: "SUMMER_FUN",
    shipping_tier: "Ground",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

You need to create a custom dimension using the shipping_tier event parameter to see Ground.

Purchase

Send the purchase event when a user completes the checkout process (either by clicking a button or landing on a confirmation page), along with an items array parameter that includes the items that the user purchases. For details on the parameters to send, see the Events reference.

Example

A user purchases a Stan and Friends Tee from the Google Merchandise Store. On the page where a user clicks to purchase, you can add the following snippet to an event listener in your JavaScript that triggers when a user clicks the button.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: purchase
  • Data Layer Variables (Name - Data Layer Variable Name) :
    • Ecommerce Items - ecommerce.items
    • Ecommerce Transaction ID - ecommerce.transaction_id
    • Ecommerce Affiliation - ecommerce.affiliation
    • Ecommerce Value - ecommerce.value
    • Ecommerce Tax - ecommerce.tax
    • Ecommerce Shipping - ecommerce.shipping
    • Ecommerce Currency - ecommerce.currency
    • Ecommerce Coupon - ecommerce.coupon
  • Event Parameters (Parameter Name - Value):
    • items - {{Ecommerce Items}}
    • transaction_id - {{Ecommerce Transaction ID}}
    • affiliation - {{Ecommerce Affiliation}}
    • value - {{Ecommerce Value}}
    • tax - {{Ecommerce Tax}}
    • shipping - {{Ecommerce Shipping}}
    • currency - {{Ecommerce Currency}}
    • coupon - {{Ecommerce Coupon}}
  • Trigger: event equals purchase
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "purchase",
  ecommerce: {
      transaction_id: "T_12345",
      affiliation: "Google Merchandise Store",
      value: 25.42,
      tax: 4.90,
      shipping: 5.99,
      currency: "USD",
      coupon: "SUMMER_SALE",
      items: [
       {
        item_id: "SKU_12345",
        item_name: "Stan and Friends Tee",
        affiliation: "Google Merchandise Store",
        coupon: "SUMMER_FUN",
        currency: "USD",
        discount: 2.22,
        index: 0,
        item_brand: "Google",
        item_category: "Apparel",
        item_category2: "Adult",
        item_category3: "Shirts",
        item_category4: "Crew",
        item_category5: "Short sleeve",
        item_list_id: "related_products",
        item_list_name: "Related Products",
        item_variant: "green",
        location_id: "L_12345",
        price: 9.99,
        quantity: 1
      },
      {
        item_id: "SKU_12346",
        item_name: "Google Grey Women's Tee",
        affiliation: "Google Merchandise Store",
        coupon: "SUMMER_FUN",
        currency: "USD",
        discount: 3.33,
        index: 1,
        item_brand: "Google",
        item_category: "Apparel",
        item_category2: "Adult",
        item_category3: "Shirts",
        item_category4: "Crew",
        item_category5: "Short sleeve",
        item_list_id: "related_products",
        item_list_name: "Related Products",
        item_variant: "gray",
        location_id: "L_12345",
        price: 20.99,
        promotion_id: "P_12345",
        promotion_name: "Summer Sale",
        quantity: 1
      }]
  }
});

Analytics updates the following metrics each time the event triggers:

  • The Purchase revenue and Total revenue metrics increase by $25.42 USD
  • The numerator of the Purchase-to-view rate metric increases by 1
  • The Quantity and Ecommerce purchases metrics increase by 1

Refund

Send the refund event when a user is issued a refund, along with an items array parameter that includes the items that the user was refunded. You can issue a partial refund when some of the purchased items are refunded or a full refund when all the purchased items are refunded. To issue a full refund, exclude the items array. For details on the parameters to send, see the Events reference.

Partial refund example

You want to measure when you issue a refund on a Google Navy Polo. On the page where you issue the refund, you can add the following snippet to an event listener in your JavaScript that triggers when you click a button to issue a refund.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: refund
  • Data Layer Variables (Name - Data Layer Variable Name) :
    • Ecommerce Items - ecommerce.items
    • Ecommerce Transaction ID - ecommerce.transaction_id
    • Ecommerce Affiliation - ecommerce.affiliation
    • Ecommerce Value - ecommerce.value
    • Ecommerce Tax - ecommerce.tax
    • Ecommerce Shipping - ecommerce.shipping
    • Ecommerce Currency - ecommerce.currency
    • Ecommerce Coupon - ecommerce.coupon
  • Event Parameters (Parameter Name - Value):
    • items - {{Ecommerce Items}}
    • transaction_id - {{Ecommerce Transaction ID}}
    • affiliation - {{Ecommerce Affiliation}}
    • value - {{Ecommerce Value}}
    • tax - {{Ecommerce Tax}}
    • shipping - {{Ecommerce Shipping}}
    • currency - {{Ecommerce Currency}}
    • coupon - {{Ecommerce Coupon}}
  • Trigger: event equals refund
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "refund",
  ecommerce: {
    currency: "USD",
    transaction_id: "T_12345",
    value: 12.21,
    affiliation: "Google Merchandise Store",
    coupon: "SUMMER_FUN",
    shipping: 3.33,
    tax: 1.11,
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      currency: "USD",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "L_12345",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

Full refund example

You want to measure when you issue a refund on all of a user's recent purchases. On the page where you issue the refund, you can add the following snippet to an event listener in your JavaScript that triggers when you click a button to issue a refund.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: refund
  • Data Layer Variables (Name - Data Layer Variable Name) :
    • Ecommerce Transaction ID - ecommerce.transaction_id
  • Event Parameters (Parameter Name - Value):
    • transaction_id - {{Ecommerce Transaction ID}}
  • Trigger: event equals refund
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "refund",
  ecommerce: {
    transaction_id: "T12345" // Transaction ID. Required for purchases and refunds.
  }
});

Use a Custom JavaScript Variable

If your website does not support a data layer, you can use a Custom JavaScript Variable to call a function that returns the ecommerce data object. This object should use the data layer syntax shown earlier in this guide, for example:

// A Custom JavaScript Variable that returns an ecommerceData object
// that follows the data layer syntax.
function getEcommerceData() {
  var ecommerceProductData = [
    {
      item_name: "Stan and Friends Tee",
      item_id: "SKU_12345",  // ID is required.
      // Rest of the product data should follow the data layer syntax.
    },
    // Multiple products may be included.
  ];
  return ecommerceProductData;
}

If you choose to use the Custom JavaScript Variable instead then you can use it in the same manner as you would the data layer - you can supply the value from the 'items' parameter as an event parameter in your tag configuration.

Tag configuration for this example:

  • Tag type: GA4 Event
  • Event Name: any
  • Read data from Variable: {{gaEcommerceData}}
  • Trigger: event equals gtm.dom

gaEcommerceData Variable Settings

  • Variable type: Custom JavaScript
  • Function body: Use the above example