Skip to main content

Intercom GTM Event Listener

Track Intercom chat widget interactions in Google Tag Manager. Fire GA4 events on intercomOpened and intercomClosed using Intercom's native onShow and onHide callbacks.

intercomchatgtmga4supportsaascustomer-success

Intercom

Overview

Intercom is a leading customer messaging platform used by SaaS companies. It exposes a native JavaScript API with onShow and onHide callbacks. This listener hooks into those callbacks to push intercomOpened and intercomClosed events to the GTM dataLayer.

Events fired:

  • intercomOpened, user opens the Intercom chat widget
  • intercomClosed, user closes the Intercom chat widget

Why Use This Listener

Chat engagement is a key signal of purchase intent. Knowing when users open Intercom lets you:

  • Build audiences of high-intent visitors for retargeting
  • Attribute chat interactions to conversion paths
  • Measure chat engagement's impact on trial sign-ups or purchases
  • Track support cost vs. revenue impact

Common Use Cases

  • Build GA4 audience: "Users who opened Intercom chat"
  • Use chat open as an engagement milestone in GA4 funnels
  • Fire Meta InitiateCheckout or Lead on Intercom open
  • Measure support deflection rate by correlating chat opens with page views
  • Track chat widget load impact on Core Web Vitals

How It Works

Intercom's JavaScript API is initialized after the page loads. The listener uses the onShow and onHide callbacks provided by Intercom's window.Intercom() function.

mermaid
sequenceDiagram
    participant U as User
    participant IC as Intercom Widget
    participant JS as Event Listener
    participant DL as dataLayer
    participant GTM as GTM

    U->>IC: Clicks Chat Widget
    IC->>JS: onShow callback
    JS->>DL: push {event: "intercomOpened"}
    DL->>GTM: Trigger fires
    GTM->>GA4: Logs engagement event
    
    U->>IC: Clicks Close
    IC->>JS: onHide callback
    JS->>DL: push {event: "intercomClosed"}

GTM Setup Guide

Step 1: Create Custom HTML Tag

Tag name: cHTML – Intercom Chat Listener Fire on: DOM Ready

Step 2: Create Custom Event Triggers

Trigger NameEvent Name
CE – Intercom OpenedintercomOpened
CE – Intercom ClosedintercomClosed

Installation

html
<!-- GTM Custom HTML Tag: Intercom Chat Listener -->
<script>
(function() {
  function initIntercomListeners() {
    if (typeof window.Intercom === 'undefined') return;
    
    window.Intercom('onShow', function() {
      window.dataLayer = window.dataLayer || [];
      window.dataLayer.push({
        'event': 'intercomOpened'
      });
    });
    
    window.Intercom('onHide', function() {
      window.dataLayer = window.dataLayer || [];
      window.dataLayer.push({
        'event': 'intercomClosed'
      });
    });
  }
  
  // Wait for Intercom to be ready
  if (window.Intercom) {
    initIntercomListeners();
  } else {
    window.addEventListener('load', initIntercomListeners);
  }
})();
</script>

Important: If Intercom loads via GTM, set this tag to fire after the Intercom initialization tag using tag sequencing.

Data Layer Output

Widget Opened

json
{
  "event": "intercomOpened"
}

Widget Closed

json
{
  "event": "intercomClosed"
}

Trigger Configuration

Trigger 1: Type: Custom Event Event Name: intercomOpened Use for: GA4 engagement events, Meta custom events Trigger 2: Type: Custom Event Event Name: intercomClosed Use for: Session duration tracking

Variables to Capture

The basic Intercom listener doesn't expose conversation data. For richer data, extend using Intercom's conversation API:

javascript
// Extended version with conversation data
window.Intercom('onConversationStarted', function(data) {
  window.dataLayer.push({
    'event': 'intercomConversationStarted',
    'conversationId': data.conversationId
  });
});

GA4 Mapping Recommendations

GA4 EventParameterValue
chat_widget_openchat_platform"intercom"
chat_widget_openpage_locationBuilt-in Page URL
engagementmethod"intercom_chat"

Debugging

GTM Preview Mode

  1. Open GTM Preview, load your site
  2. Click the Intercom chat widget
  3. Check for intercomOpened in the Events panel

Common Issues

ProblemCauseFix
Events not firingIntercom not loaded when listener runsSwitch to Window Loaded trigger
Intercom is not a functionIntercom loaded after listenerUse tag sequencing in GTM
Multiple fires on single openonShow fires multiple timesAdd debounce wrapper

Debounce Wrapper (if double-firing)

javascript
var intercomDebounce = false;
window.Intercom('onShow', function() {
  if (intercomDebounce) return;
  intercomDebounce = true;
  setTimeout(function() { intercomDebounce = false; }, 1000);
  
  window.dataLayer.push({ event: 'intercomOpened' });
});

Best Practices

  1. Use tag sequencing, Ensure the Intercom initialization tag fires before this listener
  2. Segment by page, Chat opens on pricing pages have different intent than chat opens on blog pages
  3. Combine with session data, Track chat opens alongside session source/medium for attribution
  4. Avoid PII in dataLayer, Don't capture user email or name from Intercom's user object without consent
  5. Test across user states, Logged-in users may experience Intercom differently than anonymous visitors

Performance Considerations

  • Zero performance impact, callbacks are registered once at page load
  • Intercom itself is the performance factor (typically 50-150KB)
  • Consider loading Intercom only on authenticated pages for better Core Web Vitals

Related Listeners

  • Drift Chat, Sales-focused chat with 18 trackable events
  • HubSpot Chat, Conversation tracking for HubSpot CRM users
  • HelpScout, Support-focused knowledge base + chat
  • Crisp Chat, Multi-channel chat with session data

Example Business Scenarios

Scenario 1: SaaS Trial Conversion

A SaaS company discovers through GA4 that 34% of users who open Intercom during their trial convert to paid, vs. 12% who don't. They then create a Google Ads RLSA audience targeting users who opened chat, bidding 50% higher for those visitors.

Scenario 2: E-commerce Support ROI

An eCommerce store tracks chat opens against purchase events. They find users who chatted with support before buying have a 2.3x higher AOV. They use this to justify Intercom's subscription cost.

FAQ

Q: Can I track what users say in the chat? A: Not with this basic listener. Intercom's onConversationStarted callback provides conversation IDs, but message content isn't accessible from the parent page for privacy reasons.

Q: Does this work with Intercom's product tours? A: No, product tours use different events. Add window.Intercom('onActivatorClick') to track tour interactions.

Q: Can I fire this on specific pages only? A: Yes, add a page path condition to the trigger, or use GTM's Exception trigger to exclude pages.