GA4 Event Code Generator — gtag, dataLayer and Measurement Protocol

Pick a recommended GA4 event — generate_lead, sign_up, purchase, add_to_cart and more — or name your own, fill in the parameters and items, and copy the code as gtag(), a Tag Manager dataLayer.push() or a server-side Measurement Protocol request. Names and values are checked against GA4’s limits as you type.

Runs in your browserUpdated

Items

Your data never leaves your computer. All processing happens 100% locally in your browser.

How to use the GA4 Event Code Generator

  1. Pick a recommended event to get its standard parameters, or choose Custom event and type a name like newsletter_signup.
  2. Fill in or add parameters; ecommerce events also get an Items list with add and remove buttons.
  3. Choose the format: gtag() for sites with the Google tag, dataLayer for Tag Manager, or Measurement Protocol for server-side events.
  4. 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: value needs a currency, purchase needs a unique transaction_id, and each item needs an item_id or item_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.

Frequently asked questions

How do I send a custom event to GA4?
Call gtag('event', 'your_event_name', { param: 'value' }) after the Google tag has loaded. Choose Custom event here, type the name and parameters, and copy the code.
Why don’t my event parameters show in reports?
Custom parameters only appear in standard reports after you register them in Admin → Custom definitions. Data from before registration is not filled in.
What is the difference between gtag and dataLayer.push?
gtag() is a small wrapper that pushes to the dataLayer for the Google tag. With Tag Manager you push plain objects with an event key, and triggers in the container decide what happens.
Do Measurement Protocol events need a client ID?
Yes. Use the client_id from the visitor’s _ga cookie to join server events to their web session, or your own stable ID for events with no web visit.
Can I install GA4 Event Code Generator as a web app and use it offline?
Yes. GA4 Event Code Generator is an installable web app (PWA) — installed from your browser, not downloaded from an app store. Click Install app at the top of this page in Chrome or Edge (Windows, macOS, Linux, ChromeOS) or on Android, use Share → Add to Home Screen on iPhone and iPad, or File → Add to Dock in Safari 17+ on a Mac. It then opens in its own window with its own icon, and because it runs entirely in your browser it keeps working offline. Firefox on desktop can’t install web apps. How installing works.

Related tools