How to use the GA4 Event Code Generator
- Pick a recommended event to get its standard parameters, or choose Custom event and type a name like
newsletter_signup. - Fill in or add parameters; ecommerce events also get an Items list with add and remove buttons.
- Choose the format: gtag() for sites with the Google tag, dataLayer for Tag Manager, or Measurement Protocol for server-side events.
- Optionally wrap it in a click or form-submit listener, copy it, and check the event in GA4 DebugView.
Recommended events vs custom events
GA4 understands recommended events — such as generate_lead, sign_up, login, search and the ecommerce set from view_item to purchase — and fills its built-in reports with them. Use them whenever one fits. For anything else, a custom event works the same way; register its parameters as custom dimensions in Admin → Custom definitions to see them in reports.
The checks it runs
- Event and parameter names: start with a letter, only letters, numbers and underscores, at most 40 characters, and no reserved prefixes (
google_,ga_,firebase_) or reserved event names. - At most 25 parameters per event, and parameter values up to 100 characters.
- Ecommerce:
valueneeds acurrency,purchaseneeds a uniquetransaction_id, and each item needs anitem_idoritem_name.
Three ways to send it
gtag() sends straight to GA4. With Tag Manager, dataLayer.push() hands the event to the container, where a Custom Event trigger and a GA4 event tag forward it — ecommerce pushes are preceded by { ecommerce: null } so old items don’t leak into the next event. The Measurement Protocol sends events from your server, for things that happen off the page, like a renewed subscription or an offline sale. To track clicks without writing code per button, use the Event Tracking Script Generator.
Also searched as: ga4 event generator, gtag event code, ga4 event code, ga4 custom event, ga4 recommended events, ga4 ecommerce code, gtag purchase event, ga4 generate_lead.
Tools that pair well with the GA4 Event Code Generator
- Google Tag Snippet Generator — Enter your GA4 measurement ID, Google Ads ID or Tag Manager container ID and get install code that is ready to paste — with Consent Mode v2 defaults, cross-domain linking, debug mode, manual page views and cookie settings switched on only when you need them.
- dataLayer Push Generator — Build dataLayer.push() code for Google Tag Manager: choose a GA4 recommended event or your own, add parameters and ecommerce items, and optionally wrap it in a click or form submit listener — ready to paste.
- GA4 Request Decoder — Debug Google Analytics 4 without guesswork.
- UTM Builder — Add utm_source, utm_medium, utm_campaign and friends to any link, see which GA4 channel the visit will land in, and tag a whole list of URLs at once.