Lesson 3 of 6
Auto-Event Variables
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
The three buttons below differ only by a data-action attribute. The naive approach is three triggers and three tags. The tidy approach is an Auto-Event Variable: a variable that reads a property of whatever element triggered the current event.
Point one at the data-action attribute and it returns "share", "save" or "print" depending on which button was clicked. One click trigger, one tag, one variable, the value changes with the click. Auto-Event Variables only resolve inside an auto-event context (a click, form or link trigger), so they pair with a trigger rather than standing alone.
Goal
Build an Auto-Event Variable that reads the data-action attribute, and send it with one click tag.
Build it in GTM
Create the Auto-Event Variable
Go to Variables → New, choose Auto-Event Variable.Read the data-action attribute
Set Variable Type to Element Attribute, then in Attribute Name typedata-action, the attribute's name, not a value. Name itAEV - data-actionand Save.Give it a click to read from
Create a Click → All Elements trigger (Some Clicks, e.g.Click Classescontains your button class) so there's a clicked element to inspect.Fire one tag and send the value
On a single tag firing on that trigger, send{{AEV - data-action}}as the value (for example a GA4 event parameteraction). The one tag now reports share, save or print correctly per click.
Debug in Tag Assistant
Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
{{AEV - data-action}} shows share, save or print for that exact click, and your single tag fires with the matching value.Verify your container
Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.
Drop your container .json here
or browse · checked in your browser, nothing is uploaded