Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

All docs

GA4 WooCommerce events Pro

Pro · This feature is part of Snipfire Pro, and needs WooCommerce. Plans

Google Analytics 4's ecommerce reports (which products are seen, added to the cart, bought) need events from your shop. The Google Analytics 4: WooCommerce events generator makes one JavaScript snippet that sends them all, with the item data GA4 expects, for the classic and the block cart and checkout.

The events

Event When
view_item_list A list of products is shown: the shop, a category or tag, product search
view_item A product page is shown
add_to_cart A product is added to the cart, from a product page, a list's button, a link or the cart block
remove_from_cart A product is removed, or its quantity lowered
view_cart The cart page is shown
begin_checkout The checkout page is shown
add_payment_info The order is placed, with the payment method (can be switched off)
purchase The order-received page is shown for the first time for an order, so a reload or a visit from the order email doesn't count twice

Each event has currency, value and items, and each item has item_id (the SKU, or the product ID without one), item_name, item_variant, item_category to item_category5, price and quantity. Purchases add the transaction ID, tax, shipping and coupon.

Set it up

  1. Make sure the Google tag is on your pages, for example from the Google Analytics 4 generator, or that Google Tag Manager is (the Google Tag Manager generator).
  2. Click + New → From a generator… and Use on Google Analytics 4: WooCommerce events (in Tracking).
  3. Fill in the form:
    • Send the events to: The Google tag (gtag.js) or Google Tag Manager (dataLayer).
    • Measurement ID (optional): with the Google tag only, if the page has more than one GA4 property and the events should go to one of them.
    • Send add_payment_info when the order is placed: on by default.
  4. Switch it on and save.

With Google Tag Manager, the events are pushed to the dataLayer in GA4's ecommerce format ({ event: "add_to_cart", ecommerce: { … } }, after clearing the previous ecommerce object). In Tag Manager, add a GA4 event tag that fires on these events and sends the ecommerce data.

Check it in Google Analytics under Admin → DebugView, or with Tag Assistant.

Don't use it together with the GA4 purchase event generator (or the library's Google Analytics 4 purchase event snippet): purchases would count twice. This one already sends them.

The snippet waits for Statistics consent (its Cookie consent setting), so nothing is sent until the visitor accepts. Change the category in its settings if your consent tool files analytics differently.

Cart changes happen on the server (an add-to-cart button, the cart block), so Snipfire records them in the visitor's own WooCommerce session and the script sends them afterwards. It records them:

  • only while a switched-on snippet uses them,
  • not for a visitor whose consent tool tells the server they refused the snippet's category.

With Google Consent Mode alone (no answer on the server), they're recorded and only sent once the script runs, that is, after consent. No cookies are added, and no customer details are recorded: products and orders only. Up to 30 cart changes wait per visitor.

The {woocommerce_data} smart tag

The generator's snippet reads the shop's data through the {woocommerce_data} smart tag, which you can use in your own JavaScript snippets too (with smart tags switched on, and Snipfire Pro and WooCommerce active). It's this page's shop data as JSON:

  • the currency, and which kind of shop page this is,
  • the product (on a product page), the products listed (on the shop, category, tag and search pages),
  • the cart (on the cart and checkout pages) and the payment methods (at the checkout),
  • the order, the first time the order-received page is shown for it,
  • whether cart changes are waiting, and where the script fetches them.

Products come with the same item fields as the events above. Use it to feed another analytics or ads tool:

var shop = {woocommerce_data};
if ( shop && shop.product ) {
    console.log( 'Viewing', shop.product.item_name, shop.product.price, shop.currency );
}

Without Snipfire Pro or WooCommerce, a snippet that uses the tag isn't printed at all, and saving it warns you.

Good to know

  • Classic and block themes, classic and block checkout. Add to cart is caught wherever WooCommerce handles it: product forms, ?add-to-cart= links, the AJAX buttons in lists and the Store API used by the cart and checkout blocks.
  • Who can use it: it makes a JavaScript snippet, so people with CSS, JS and HTML team access can use the generator too.
  • Without Snipfire Pro the generator is locked (Needs Snipfire Pro.).

Something unclear or missing? Tell us