E-commerce

The analytics events an ecommerce site actually needs

Five events cover a shop: product view, add to cart, checkout start, purchase and empty search. The rest is noise you maintain every month.

Key points

  • Five events are enough: view_item, add_to_cart, begin_checkout, purchase, an empty search.
  • Count the purchase once, guarded by transaction_id.
  • The GA4 loader measured on 1 November 2026 weighs 157,500 compressed bytes, 446,036 raw.
  • Consent and script blockers reduce what you collect: the absolute number is not the revenue figure.

Five events cover an ecommerce site: product view, add to cart, checkout start, purchase and an empty search. The rest is noise that costs bytes and upkeep.

The five events

EventWhen it firesMinimum parameters
view_itemThe product page becomes visibleitem_id, item_name, value, currency
add_to_cartClick on the add buttonitem_id, quantity, value, currency
begin_checkoutThe first checkout field takes focusvalue, currency, items
purchaseThe order confirmation is showntransaction_id, value, currency, items
search_no_resultsThe search returns nothingsearch_term

Five events give the whole funnel: who looks, who adds, who starts paying, who buys, and what they search for without finding. Every extra event has to be maintained, renamed and reconciled with revenue: ten undocumented events are worth less than five verified ones.

The code: one place to send from

const sent = new Set();

export function track(name, params) {
  if (name === "purchase") {
    const id = params.transaction_id;
    if (!id || sent.has(id)) return;
    sent.add(id);
  }
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({ event: name, ...params });
}

The check on transaction_id prevents double counting when the customer reloads the confirmation page or navigates back. The same guard belongs on the server side if the purchase is also sent from there: a unique identifier is the only defence against two identical purchases on the same day.

How much the tag weighs

# peso del loader GA4, compresso e non compresso
curl -s --compressed -o /dev/null -w "%{size_download}\n" \
  "https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"

curl -s -o /dev/null -w "%{size_download}\n" \
  "https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"

The measured weight is the loader, not the whole instrument: further requests start afterwards. If the loader loads on every page, you pay it on every visit; load it only where it is needed and the rest of the site stays light.

The limitation to name

Absolute numbers are not revenue. Script blockers and consent choices remove part of the visits, and the missing part is not evenly spread: people who block scripts are not a random sample of your customers. Read the events as direction and reconcile them with the orders in the back office.

Where to continue

The send points live in real pages: product-detail-01 for the product view, checkout-01 for the payment start, both inside the commerCN library. For the comparison between hosted and in-house analytics read Vercel Analytics and self-hosted, for browser-side measurement PerformanceObserver and for responsiveness INP in practice.

Frequently asked questions

Which GA4 events does an ecommerce site need?

Five: view_item, add_to_cart, begin_checkout, purchase and one empty search. They describe the funnel and the catalogue gap; add others only when a question needs them.

Client-side or server-side events?

Purchase on the server, the rest in the browser. The server sees the real order and does not depend on the browser; views and clicks are measured better where they happen.

How do I avoid counting a purchase twice?

With one identifier per order and a check before sending. If the same transaction_id arrives twice, the second send is dropped: without that guard a confirmation page reload produces a duplicate.

Does the cookie banner block the events?

It reduces the data, it does not zero it. With consent refused, most setups skip marketing events while events needed to deliver the service remain possible. Compare against orders, not against last year's numbers.

How much does Google Analytics weigh on the page?

The gtag/js loader alone, measured on 1 November 2026, weighs 157,500 compressed bytes and 446,036 raw. Total weight depends on the requests that follow and on how many other integrations load the same tool.