Lessons in this module
Lesson 14 of 15
Exit Intent
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
When the cursor darts toward the very top of the window, the visitor is usually reaching for the tab bar or the back button. That moment is called exit intent, and it's the classic cue for a save-offer modal, a survey, or an exit coupon.
GTM has no built-in trigger for it, so this lesson introduces a pattern you'll reuse constantly: a small Custom HTML listener watches the browser, pushes its own event to the dataLayer, and a Custom Event trigger picks it up. Here the listener watches mousemove and pushes exit_intent once when the cursor hits the top edge.
Goal
Add an exit-intent listener, catch its exit_intent push with a Custom Event trigger, and fire a tag on it.
Build it in GTM
Add the exit-intent listener
There's no built-in exit-intent trigger, so a small Custom HTML tag watches the cursor and pushes its own event.
- Go to Tags → New and choose Custom HTML.
- Paste the script below into the HTML field, it adds a
mousemovelistener and pushesexit_intentwhene.clientY <= 10, firing only once. - Set its firing trigger to All Pages, name it
Listener - Exit intent, and Save.
<script> (function () { var fired = false; document.addEventListener('mousemove', function (e) { if (!fired && e.clientY <= 10) { fired = true; window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: 'exit_intent' }); } }); })(); </script>Create the Custom Event trigger
- Go to Triggers → New and choose Custom Event.
- Set Event name to
exit_intent(it must match theeventyou pushed). - Name it
Event - exit_intentand Save.
Attach a tag
- Go to Tags → New and choose your save-offer modal tag, or a Custom HTML test tag with
<script></script>. - Under Triggering, add
Event - exit_intent, then Save.
- Go to Tags → New and choose your save-offer modal tag, or a Custom HTML test tag with
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
exit_intent event in the timeline and dataLayer, firing your tag once.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