Developer and Text Tools

Writing Correct GA4 Event Code: Recommended Events, Parameters and Limits

How to send Google Analytics 4 events correctly with gtag.js or Google Tag Manager, use recommended names, build ecommerce items and stay within limits.

Saizul Amin
Saizul Amin3 Nov 2026 · 3 min read
Writing Correct GA4 Event Code: Recommended Events, Parameters and Limits

Google Analytics 4 measures everything as events, and it is unforgiving about how they are written. A purchase event with a typo in its name will not appear in ecommerce reports, a parameter with a hyphen is dropped, and revenue without a currency is ignored. Most tracking problems in GA4 come down to small mistakes in event code. This guide explains the rules and how to avoid them with the free GA4 event code builder.

Google defines a set of recommended events with fixed names and parameters. For online shops these include view_item, add_to_cart, begin_checkout, add_payment_info and purchase; for lead generation, generate_lead and sign_up; for content, search, share and select_content. When you use these exact names and parameters, GA4 fills its built-in reports automatically. The builder offers the full list and pre-fills the usual parameters for each one.

Custom events and their rules

When no recommended event fits, create a custom one. Names must start with a letter and use only letters, numbers and underscores, with a maximum of 40 characters. Names beginning with google_, ga_ or firebase_ are reserved, and some names such as session_start, first_visit and user_engagement are collected automatically and cannot be sent by you. Parameter names follow the same rules; parameter values are limited to 100 characters, and each event can carry up to 25 parameters. Custom parameters also need a custom dimension or metric in GA4 before they appear in standard reports.

Ecommerce items

Ecommerce events carry an items array. Each item should have item_id or item_name, and usually price and quantity, with optional brand, category, variant, coupon and discount. Up to 200 items fit in one event. The event's value should equal the sum of price × quantity, excluding tax and shipping, and an event with a value needs a currency in ISO 4217 format, such as USD, EUR or INR. The builder adds up the items and can set the value for you.

gtag.js versus Tag Manager

If GA4 is installed directly on your site with gtag.js, events are sent with gtag("event", "name", { parameters }). If you use Google Tag Manager, your site pushes data into the dataLayer and a GA4 event tag in Tag Manager sends it. For ecommerce, Google recommends clearing the previous ecommerce object with dataLayer.push({ ecommerce: null }) before pushing a new one, so items from one event do not leak into the next. The builder writes both forms from the same input.

Test before trusting reports

Use GA4 DebugView or Tag Assistant to watch events arrive in real time. Check the event name, every parameter and the items. Only then publish the change. A short tracking plan, a list of events with their parameters and where they fire, makes testing and later changes much easier; you can keep it alongside the downloaded code file.

Respect privacy

Google Analytics policies forbid sending personally identifiable information such as names, e-mail addresses or phone numbers. Many sites also need consent before analytics runs. Keep parameters about products and actions, not people.

A small tracking plan

For a typical online shop, a starting plan might be: view_item on product pages, add_to_cart when the button is clicked, begin_checkout on the first checkout step, add_shipping_info and add_payment_info on the next steps, and purchase on the confirmation page with the transaction ID. A lead-generation site might use generate_lead on form submission and sign_up for accounts. Build each event in the builder, download the file and keep it with your site code as documentation.

Limits

The builder generates code; it does not install it, configure GA4 or guarantee data quality, and it is not legal advice on consent. Always test in DebugView.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages