Lesson 3 of 4
Intercom Chat
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
Intercom's messenger exposes lifecycle callbacks through its JS API: onShow, onHide, onUnreadCountChange. They're how you measure whether visitors actually engage with chat, which a pageview-based setup completely misses.
You'll hook onShow and onHide and push dataLayer events, starting with intercom_open, then tag them. onUnreadCountChange lets you catch proactive messages a visitor received but hasn't opened.
One catch: the callbacks only attach once Intercom has booted, so fire the listener on DOM Ready (or queue it) rather than racing the widget's own script.
Goal
Hook Intercom's onShow / onHide callbacks and fire a tag on intercom_open.
Build it in GTM
Add the listener as a Custom HTML tag
Paste this into a Custom HTML tag firing on All Pages (or Initialization). It turns Intercom's signals into dataLayer events:
<script> if (window.Intercom) { Intercom('onShow', function(){ window.dataLayer = window.dataLayer || []; dataLayer.push({ event: 'intercom_open' }); }); Intercom('onHide', function(){ dataLayer.push({ event: 'intercom_close' }); }); Intercom('onUnreadCountChange', function(n){ dataLayer.push({ event: 'intercom_unread', unread_count: n }); }); } </script>Create a Custom Event trigger on
intercom_openGo to Triggers → New → Custom Event, set the event name tointercom_open, name it for the widget and Save.Fire a tag on it
Add a GA4 Event tag (or theCustom HTML - Teststand-in) firing on that trigger, so the captured event reaches your analytics.Go deeper
Want the full production script, a walkthrough video and a downloadable GTM recipe? DumbData: Intercom listener script, video + GTM recipe.
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
intercom_open, and your tag fires on it in Tag Assistant.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