GA4 Event Code Builder
Pick a recommended GA4 event or create a custom one, fill in parameters and ecommerce items, check names and limits, and copy gtag or dataLayer code for each event.
Runs in your browser. Your files never leave your device. See how to check
…
How to do it
- 1Add an event
Pick a recommended event from the list or add a custom event.
- 2Fill in parameters
Enter values for the suggested parameters and add or remove parameters.
- 3Add items
For ecommerce events, add each item with ID, name, price and quantity.
- 4Check validation
Read the validation box and fix any names, limits or missing currency.
- 5Choose the format
Switch between gtag.js and Google Tag Manager dataLayer output.
- 6Copy or download
Copy the code for this event or download all events as a .js file.
About this tool
Google Analytics 4 records everything as events, and the quality of your reports depends on sending the right event names, parameters and ecommerce items. Writing that code by hand is error-prone: a misspelled recommended event loses its built-in reports, a parameter name with a hyphen is rejected, and a purchase without currency shows no revenue. This builder helps developers, marketers and shop owners write correct code without memorising the documentation. Choose a recommended event such as purchase, add_to_cart, generate_lead, sign_up or search, and its usual parameters appear ready to fill; or create a custom event. Ecommerce events get an items editor with item ID, name, brand, category, variant, price, quantity and discount. The tool checks names, reserved prefixes and limits, warns when value and items do not match or currency is missing, and produces copy-ready code for gtag.js or a Google Tag Manager dataLayer push.
Recommended versus custom events
Google publishes recommended events with fixed names and parameters, such as purchase with transaction_id, value, currency and items. Using exactly these names unlocks standard ecommerce and lead reports. Custom events are for anything else, but their names must still follow the rules, and their parameters need custom dimensions in GA4 to appear in reports.
Naming rules and limits
Event and parameter names must start with a letter and contain only letters, numbers and underscores, up to 40 characters. Names starting with google_, ga_ or firebase_ are reserved, and some event names such as session_start or first_visit are collected automatically and cannot be sent. Parameter values are limited to 100 characters, an event can have up to 25 parameters and an ecommerce event up to 200 items. The builder checks all of these as you type.
Ecommerce items
Each item needs at least item_id or item_name. Value should be the sum of price × quantity for the items, excluding tax and shipping, and an ecommerce event with a value needs a currency code such as USD, EUR or INR. The builder can set value from the items total.
gtag.js or dataLayer
With gtag.js, events are sent with gtag("event", name, parameters). With Google Tag Manager, the page pushes an object to the dataLayer and a GA4 event tag reads it; Google recommends clearing the previous ecommerce object first with dataLayer.push({ ecommerce: null }). The output switch produces either form.
Worked example
A purchase of two T-shirts at $19.99 produces gtag("event", "purchase", { transaction_id: "T_1001", value: 39.98, currency: "USD", items: [ { item_id: "SKU_123", item_name: "Tee", price: 19.99, quantity: 2 } ] }). Switching to dataLayer gives the same data under an ecommerce key, preceded by the clearing push.
Limits
The builder writes code; it does not install tags, configure GA4 or test your site, and it is not legal advice on consent or privacy. Never send personal data such as names or e-mail addresses in event parameters. Verify every event in GA4 DebugView before relying on reports.
Worked example
Purchase of 2 × $19.99: value 39.98, currency USD, one item with quantity 2, as gtag or dataLayer code.
Quick facts
- Category: Developer & Data
- Works in your browser, no sign-up, no upload.
- Your input stays on your device.
- Available in English.
- Content last reviewed:
- Official source: Google Analytics 4 developer guides: recommended events, ecommerce and collection limits
Frequently asked questions
What is a GA4 recommended event?
An event name and parameter set defined by Google, such as purchase or sign_up, which GA4 understands and uses in standard reports.
Can I name events however I like?
Custom names are allowed if they start with a letter, use only letters, numbers and underscores, are at most 40 characters and avoid reserved names and prefixes.
Why does my purchase show no revenue?
Usually because currency is missing or value is not a number. The builder warns about both.
Should I use gtag or the dataLayer?
Use gtag.js if you added GA4 directly to your site, and the dataLayer if you manage tags with Google Tag Manager.
How many items can an event have?
Up to 200 items per ecommerce event, and up to 25 parameters per event.
Can I send customer e-mail addresses?
No. Google's policies forbid sending personally identifiable information to Analytics.
