Generate tracking code
generate_tracking_codeCreate a ready-to-paste GA4 event tracking JavaScript snippet. Add recommended parameters and check if the event already fires.
Instructions
Generate a GA4 event tracking JavaScript snippet.
Produces ready-to-paste gtag code for the specified event. Includes recommended parameters for well-known GA4 events (sign_up, purchase, etc.). Optionally checks GA4 to warn if the event already fires. Returns the javascript snippet, already_exists / existing_count from GA4, and notes (duplicates, marking it as a key event, GDPR consent).
Google Analytics Data API: https://developers.google.com/analytics/devguides/reporting/data/v1 and Google Ads API: https://developers.google.com/google-ads/api/docs/start
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| trigger | No | "form_submit", "button_click", or "page_load" — wraps the gtag call in an appropriate event listener (with a YOUR_SELECTOR placeholder for forms and buttons). Empty = bare gtag call. | |
| event_name | Yes | GA4 event name for the snippet, e.g. "sign_up" or "generate_lead". | |
| property_id | No | GA4 property as "properties/123456789" used for the existing-event check. If empty, uses the default from config. | |
| event_params | No | Event parameters as a name-to-value object, e.g. {"method": "email"}. Missing recommended parameters for well-known events are added as typed placeholders. | |
| check_existing | No | When true (default), looks up the last 28 days of GA4 events to report whether this event already fires. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||