GA4 E-commerce Tracking with gtag.js

Google Analytics BCS 4 years ago (2022-02-27) 2635 Views 0 Comments
文章目录[隐藏]

Updated: March 16, 2026

Google Analytics 4 (GA4) includes a built-in e-commerce measurement model that lets you track the full user journey — from product discovery to purchase and refund.

This guide explains how to implement GA4 e-commerce tracking using gtag.js, including all recommended events and parameters.

If you haven’t installed GA4 yet, start here: Installing Google Analytics 4 with gtag.js

Product Views

These events track how users browse and interact with products on your website.

  • view_item_list:Triggered when a list of products is displayed to users.
  • view_item:Triggered when a user views a product detail page.
  • select_item:Triggered when a user clicks on a product from a list.

 

view_item_list

Send the view_item_list event when users see a product list such as category pages, search results, or recommended products.

gtag("event", "view_item", {
  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
    }
  ]
});

 

 

view_item

The view_item event should be triggered when a user opens a product detail page.

gtag("event", "select_item", {
  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
    }
  ]
});

 

 

select_item

The select_item event tracks when a user selects a product from a list.

gtag("event", "select_item", {
  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 Promotion

These events track internal marketing promotions displayed on your website.

  • view_promotion:Triggered when a promotion is displayed.
  • select_promotion:Triggered when a user clicks a promotion.

view_promotion

gtag("event", "view_promotion", {
  creative_name: "Summer Banner",
  creative_slot: "featured_app_1",
  location_id: "L_12345",
  promotion_id: "P_12345",
  promotion_name: "Summer Sale"
});

select_promotion

gtag("event", "select_promotion", {
  creative_name: "Summer Banner",
  creative_slot: "featured_app_1",
  location_id: "L_12345",
  promotion_id: "P_12345",
  promotion_name: "Summer Sale"
});

 

 

Shopping Cart

These events track interactions with the shopping cart.

  • add_to_cart:When a product is added to the cart
  • remove_from_cart:When a product is removed from the cart

add_to_cart

gtag("event", "add_to_cart", {
  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

gtag("event", "remove_from_cart", {
  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
    }
  ]
});

 

These events track the checkout process.

  • begin_checkout
  • add_payment_info
  • add_shipping_info
  • purchase
  • refund

Important: When sending revenue-related data (value), always include the currency parameter to ensure GA4 calculates revenue metrics correctly.

 

begin_checkout

gtag("event", "begin_checkout", {
  currency: "USD",
  value: 7.77,
  coupon: "SUMMER_FUN",
  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_payment_info

gtag("event", "add_payment_info", {
  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_info

gtag("event", "add_shipping_info", {
  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
    }
  ]
});

 

purchase

gtag("event", "purchase", {
    transaction_id: "T_12345",
    affiliation: "Google Merchandise Store",
    value: 36.32,
    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
    },
    {
      Product2
    }]
});

 

refund

The refund event is used to send refund data to GA4.

Partial refund

gtag("event", "refund", {
  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

gtag("event", "refund", {
  currency: "USD",
  transaction_id: "T_12345",
  value: 12.21,
  affiliation: "Google Merchandise Store",
  coupon: "SUMMER_FUN",
  shipping: 3.33,
  tax: 1.11
});

 

 

Like (2)
Post my comment
Cancel comment
Expression Bold Strikethrough Center Italic

Hi, you need to fill in your nickname and email!

  • Nickname (required)
  • Email (required)
  • Website