Ecommerce setup Q&A

How do I create an ecommerce event?

There are many ecommerce events that you can send to GA4. A few examples are add_to_cart, begin_checkout, and purchase. For a complete list of ecommerce events and their parameters, along with instructions on how to send these events to GA4, go to developers.google.com and search for "ecommerce events GA4". Click on the "Measure ecommerce" article in the search results

How do I set up ecommerce?

You can set up ecommerce events to collect information about the shopping behavior of your users. The events enable you to quantify your most popular products and see the influence of promotions and product placement on revenue. A few examples are add_to_cart, begin_checkout, and purchase. For a complete list of ecommerce events and their parameters, along with instructions on how to send these events to GA4, go to developers.google.com and search for "ecommerce events GA4". Click on the "Measure ecommerce" article in the search results.

How do I set up a purchase?

You can set up the purchase event so it triggers when someone clicks a "Purchase" button in a few ways. One way is to add an ID to the "Purchase" button and then place the event code in an event listener. In the following example, the event is only sent when someone clicks a button with the ID purchase.

<!--
  Note: In the following code sample, make sure to
  replace "TAG_ID" with your tag ID.
  Learn more: https://support.google.com/tagmanager/answer/12326985
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', 'TAG_ID');
    </script>
</head>
<body>
    <div>This is where the purchase form would go</div>
    <button id="purchase">Purchase</button>
    <script>
    document.getElementById("purchase").addEventListener("click", function () {
        gtag("event", "purchase", {
                // This purchase event uses a different transaction ID
                // from the previous purchase event so Analytics
                // doesn't deduplicate the events.
                // Learn more: https://support.google.com/analytics/answer/12313109
                transaction_id: "T_12345_2",
                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",
                  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: "ChIJIQBpAG2ahYAR_6128GcTUEo",
                  price: 9.99,
                  quantity: 1
                }]
          });
      });
    </script>
</body>
</html>

How do I set up a purchase event?

You can set up the purchase event so it triggers when someone clicks a "Purchase" button in a few ways. One way is to add an ID to the "Purchase" button and then place the event code in an event listener. In the following example, the event is only sent when someone clicks a button with the ID purchase.

<!--
  Note: In the following code sample, make sure to
  replace "TAG_ID" with your tag ID.
  Learn more: https://support.google.com/tagmanager/answer/12326985
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', 'TAG_ID');
    </script>
</head>
<body>
    <div>This is where the purchase form would go</div>
    <button id="purchase">Purchase</button>
    <script>
    document.getElementById("purchase").addEventListener("click", function () {
        gtag("event", "purchase", {
                // This purchase event uses a different transaction ID
                // from the previous purchase event so Analytics
                // doesn't deduplicate the events.
                // Learn more: https://support.google.com/analytics/answer/12313109
                transaction_id: "T_12345_2",
                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",
                  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: "ChIJIQBpAG2ahYAR_6128GcTUEo",
                  price: 9.99,
                  quantity: 1
                }]
          });
      });
    </script>
</body>
</html>

What are the purchase event parameters?

There is a reference table on developers.google.com that lists all the purchase event parameters. Here is a link to that table: https://developers.google.com/analytics/devguides/collection/ga4/reference/events#purchase.

How do I set up a purchase funnel?

Send the following events to measure a purchase funnel in GA4: begin_checkout, add_shipping_info, add_payment_info, and purchase. You might also consider sending view_item, select_item, and add_to_cart.

For a complete list of ecommerce events and their parameters, along with instructions on how to send these events to GA4, go to developers.google.com and search for "ecommerce events GA4". Click on the "Measure ecommerce" article in the search results.

How do I set up an ecommerce funnel?

Send the following events to measure a purchase funnel in GA4: begin_checkout, add_shipping_info, add_payment_info, and purchase. You might also consider sending view_item, select_item, and add_to_cart.

For a complete list of ecommerce events and their parameters, along with instructions on how to send these events to GA4, go to developers.google.com and search for "ecommerce events GA4". Click on the "Measure ecommerce" article in the search results.

How do I set up a refund?

Measure refunds by sending a refund event with the relevant transaction_id specified and one or more items defined with item_id and quantity. It's recommended that you include item information in your refund event to see item-level refund metrics in Analytics.

For details on the parameters to send, go to developers.google.com, search for "GA4 events reference", and click on the "Recommended events" search result.

Was this helpful?

How can we improve it?
false
Search
Clear search
Close search
Google apps
Main menu
5058113632847104469
true
Search Help Center
false
true
true
true
true
true
69256
false
false
false
false
false