What Is a GA4 Event Code Generator?
Everything Google Analytics 4 records is an event. Page views and scrolls are collected for you, but leads, sign ups, purchases and button clicks usually need a few lines of code. This generator writes that code for you, either as a gtag() call for sites using the Google tag, or as a dataLayer.push() for sites using Google Tag Manager.
Small mistakes break events quietly. A space in a name, a value sent as text with a currency symbol, or a missing currency can mean GA4 drops the data or shows zero revenue. The checker flags these problems as you type, using Google's event naming rules and event collection limits.
How to Use the Generator
- Pick a recommended event such as
generate_leadorpurchase, or choose Custom event and type your own name. - Edit the parameters, one per line, as
name = value. Numbers are sent as numbers, and IDs stay as text. - Add items for ecommerce events, one product per line, as
id | name | price | quantity. - Choose gtag.js or dataLayer and when the event should fire: right away, on a click, or on a form submit.
- Copy the code into your page, then confirm the event arrives in GA4 DebugView.
GA4 Event Rules and Limits
| Rule | Limit |
|---|---|
| Event name length | 40 characters |
| Parameter name length | 40 characters |
| Parameter value length | 100 characters (page_title 300, page_referrer 420, page_location 1,000) |
| Parameters per event | 25 |
| Allowed characters | Letters, numbers and underscores, starting with a letter |
| Reserved prefixes | _, firebase_, ga_, google_, gtag. |
| Value and currency | If you send value, also send a three letter currency |
| Items | Each item needs item_id or item_name |
Tips for Reliable Event Tracking
- Use recommended events first. Names like
generate_leadandpurchaseunlock built in reports. See the full list in Google's recommended events reference. - Keep names lowercase. Names are case sensitive, so
Sign_Upandsign_upare two separate events. - Register custom parameters. To see a custom parameter in reports, create a custom dimension for it in GA4 Admin.
- Mark key events. Sending an event does not make it a conversion. Mark it as a key event in GA4 once it shows up.
- Clear old ecommerce data in GTM. The
ecommerce: nullpush stops items from one event leaking into the next.
Go Further With GA4 Events
Follow our step by step guide to GA4 custom event tracking in Google Tag Manager, copy full examples from GA4 ecommerce events examples, and learn the difference between events and conversions. Testing a filter on your new event names? Try the GA4 regex tester.
Frequently Asked Questions
1Should I use gtag.js or dataLayer code?
Use gtag.js code if your site loads the Google tag directly. Use dataLayer.push code if you manage tags in Google Tag Manager, then create a GA4 Event tag with a Custom Event trigger that matches the event name.
2Why is my event not showing in GA4 reports?
Standard reports can take up to a day to update. Check DebugView or the Realtime report first. If the event is missing there, look for a name with spaces or capitals, a reserved name, or code that runs before the Google tag loads.
3Do I need to send currency with value?
Yes. Google's reference says currency is required whenever you set value. Without it, revenue and value metrics are not calculated correctly.
4Is my event data uploaded?
No. The code is generated in your browser and nothing you type is sent to a server.