Agent skill
ga4-event-tracking
Add, review, or update GA4 event tracking on HTML websites using data attributes and a reusable JavaScript tracker. Use when wiring gtag or GTM dataLayer events, choosing event names/parameters, or extending a base GA4 tracking snippet for clicks and simple interactions.
Install this agent skill to your Project
npx add-skill https://github.com/eryet/codex-skill-collection/tree/main/skills/ga4-event-tracking
SKILL.md
GA4 Event Tracking
Overview
Use this skill to instrument GA4 events in static HTML or simple web apps by attaching data attributes and a base JS tracker.
Quick Start
- Copy
assets/ga4-event-tracker.jsinto the site (for example,js/ga4-event-tracker.js). - Load it after gtag or GTM (or at the end of
body). - Add data attributes to elements you want to track.
- Validate in GA4 DebugView.
Example HTML
<button
data-ga4-event="button_click"
data-ga4-label="hero_signup"
data-ga4-category="CTA"
data-ga4-params='{"link_text":"Start free trial","value":1,"currency":"USD"}'
>
Start free trial
</button>
Common Tasks
Add a tracked element
- Add
data-ga4-eventwith a stable, action-based event name. - Use
data-ga4-labelfor human-readable context (button text or placement). - Use
data-ga4-paramsfor extra GA4 parameters (JSON string).
Extend the base tracker
- Add more event types (e.g.,
submit,change,input). - Switch to event delegation for dynamic content.
- Add defaults (category, labels) based on element classes or containers.
- Add guardrails for invalid JSON in
data-ga4-params.
Apply naming conventions
- Use
references/ga4-event-naming.mdfor event naming and parameter guidance. - Prefer stable, language-agnostic event names and use labels for display text.
Troubleshooting
- If
gtagis not available, the tracker falls back todataLayerfor GTM. - If neither gtag nor GTM is installed, events will not reach GA4.
- Add temporary console logs to confirm event payloads.
Resources
references/
references/ga4-event-naming.md: Common GA4 event naming and parameters.
assets/
assets/ga4-event-tracker.js: Base GA4 tracking script to copy and extend.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
waifu2x
Use when the user wants to upscale one image or a folder of images with waifu2x-ncnn-vulkan, including default or custom scale, noise reduction, model, format, tile size, and batch processing.
handoff
Compact the current conversation into a handoff document for another agent to pick up.
edit-article
Edit and improve articles by restructuring sections, improving clarity, and tightening prose. Use when user wants to edit, revise, or improve an article draft.
scaffold-exercises
Create exercise directory structures with sections, problems, solutions, and explainers that pass linting. Use when user wants to scaffold exercises, create exercise stubs, or set up a new course section.
obsidian-vault
Search, create, and manage notes in the Obsidian vault with wikilinks and index notes. Use when user wants to find, create, or organize notes in Obsidian.
setup-pre-commit
Set up Husky pre-commit hooks with lint-staged (Prettier), type checking, and tests in the current repo. Use when user wants to add pre-commit hooks, set up Husky, configure lint-staged, or add commit-time formatting/typechecking/testing.
Didn't find tool you were looking for?