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

Lesson 11 of 17

AJAX / Async Events

① Connect your GTM container

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

Advanced: use a specific environment

Plenty of content never exists when the page first loads. An infinite feed, a "Load more" button or a filtered list all fetch their data in the background and inject it later. Tags bound to gtm.js or DOM Ready run once, at the start, so they miss everything that arrives after the fetch resolves.

The fix is the same pattern you use everywhere else: the page pushes a named event the moment the async response lands, and you catch it with a Custom Event trigger. Here the feed pushes content_loaded when each batch arrives.

Goal

Fire a tag when async content arrives by listening for the content_loaded event.

Build it in GTM

  1. Know what the page pushes

    When the simulated fetch resolves, the page runs dataLayer.push({ event: "content_loaded" }). On a real site your developer adds this line inside the fetch callback. GTM sees it as an event named content_loaded.
  2. Create the Custom Event trigger

    Go to Triggers → New and choose Custom Event. In Event name, type content_loaded, matching the pushed string exactly, including case and underscores.
  3. Fire a tag on it

    Set this trigger as your tag's firing trigger. On a real site that is a GA4 Event tag; here a Custom HTML tag named Custom HTML - Test containing <script></script> works the same way.

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 Load more and wait for the batch to land. In Tag Assistant a content_loaded event appears in the left rail after the short delay, and your tag shows under Tags Fired for it.

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