Don't have one? Create one ↗
← All courses

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

  1. Create the Auto-Event Variable

    Go to Variables → New, choose Auto-Event Variable.
  2. Read the data-action attribute

    Set Variable Type to Element Attribute, then in Attribute Name type data-action, the attribute's name, not a value. Name it AEV - data-action and Save.
  3. Give it a click to read from

    Create a Click → All Elements trigger (Some Clicks, e.g. Click Classes contains your button class) so there's a clicked element to inspect.
  4. 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 parameter action). 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.

  1. In your GTM, click Preview.
  2. Paste the live URL above and click Connect.
  3. Interact with the live page and watch your tag fire in Tag Assistant.

What you should expect to see

Click a button on the live page and open the Variables tab: {{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

0 of 6 lessons complete