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

Lesson 6 of 15

Element Visibility

① Connect your GTM container

Paste your container ID to load it into this page. It only ever runs here.

Advanced: use a specific environment

A click or pageview isn't the only thing worth measuring, sometimes you want to know an element was actually seen. GTM's Element Visibility trigger watches an element and fires when enough of it scrolls into the viewport.

Here a promo banner sits below the fold. You'll build a visibility trigger on #promo that fires once it's at least 50% on screen.

On a real page nobody hands you that identifier, here's how to find your own. The promo lives on this lesson's live page rather than here, so open that page (or any site) to follow along:

  1. Right-click the element you want to track and choose Inspect. Your browser's DevTools open with that element highlighted in the HTML panel.
  2. Look at its opening tag for an id attribute, e.g. <div id="promo">. If it has one, that's your identifier: set Selection Method to ID and enter just promo, with no #.
  3. No id? Switch Selection Method to CSS Selector and build one from a stable class instead, like .promo-banner. (With the CSS method you keep the # for ids, so #promo works there too.)
  4. Test it before you trust it. On a page that has the element, open the Console tab and run document.querySelector('#promo'), if it returns the element instead of null, GTM will find it too.

The most common mistake here is the #: the ID method wants the bare id (promo), while the CSS Selector method wants the hash (#promo). Prefer a stable id or class over an auto-generated selector, it survives redesigns far better.

Goal

Fire a tag when an element scrolls into view, using the Element Visibility trigger.

Build it in GTM

  1. Create the Element Visibility trigger

    1. Go to Triggers in the left sidebar and click New.
    2. Click the trigger-type box and choose Element Visibility.
    3. Set Selection Method to ID and enter the Element ID promo. (Or switch the method to CSS Selector and use #promo.)
    4. Set Minimum Percent Visible to 50.
    5. Under When to fire this trigger, choose Once per page.
    6. Name it Visibility - Promo and Save.
  2. Tag: Custom HTML - Test

    1. Go to Tags → New and choose Custom HTML.
    2. Paste <script></script> (fires but does nothing) and name it Custom HTML - Test.
    3. Under Triggering, add Visibility - Promo, then Save.

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

When the promo reaches 50% on screen, the timeline adds an Element Visibility event (gtm.elementVisibility) and your tag fires once under Tags Fired.

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 15 lessons complete