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

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

  1. 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>
  2. Create a Custom Event trigger on intercom_open

    Go to Triggers → New → Custom Event, set the event name to intercom_open, name it for the widget and Save.
  3. Fire a tag on it

    Add a GA4 Event tag (or the Custom HTML - Test stand-in) firing on that trigger, so the captured event reaches your analytics.
  4. 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.

  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

Opening the simulated messenger pushes 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

0 of 4 lessons complete