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
Know what the page pushes
When the simulated fetch resolves, the page runsdataLayer.push({ event: "content_loaded" }). On a real site your developer adds this line inside the fetch callback. GTM sees it as an event namedcontent_loaded.Create the Custom Event trigger
Go to Triggers → New and choose Custom Event. In Event name, typecontent_loaded, matching the pushed string exactly, including case and underscores.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 namedCustom HTML - Testcontaining<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.
- 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
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