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.
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 widgetintercomClosed, 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
InitiateCheckoutorLeadon 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.
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 Name | Event Name |
|---|---|
| CE – Intercom Opened | intercomOpened |
| CE – Intercom Closed | intercomClosed |
Installation
<!-- 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
{
"event": "intercomOpened"
}Widget Closed
{
"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:
// Extended version with conversation data
window.Intercom('onConversationStarted', function(data) {
window.dataLayer.push({
'event': 'intercomConversationStarted',
'conversationId': data.conversationId
});
});GA4 Mapping Recommendations
| GA4 Event | Parameter | Value |
|---|---|---|
chat_widget_open | chat_platform | "intercom" |
chat_widget_open | page_location | Built-in Page URL |
engagement | method | "intercom_chat" |
Debugging
GTM Preview Mode
- Open GTM Preview, load your site
- Click the Intercom chat widget
- Check for
intercomOpenedin the Events panel
Common Issues
| Problem | Cause | Fix |
|---|---|---|
| Events not firing | Intercom not loaded when listener runs | Switch to Window Loaded trigger |
Intercom is not a function | Intercom loaded after listener | Use tag sequencing in GTM |
| Multiple fires on single open | onShow fires multiple times | Add debounce wrapper |
Debounce Wrapper (if double-firing)
var intercomDebounce = false;
window.Intercom('onShow', function() {
if (intercomDebounce) return;
intercomDebounce = true;
setTimeout(function() { intercomDebounce = false; }, 1000);
window.dataLayer.push({ event: 'intercomOpened' });
});Best Practices
- Use tag sequencing, Ensure the Intercom initialization tag fires before this listener
- Segment by page, Chat opens on pricing pages have different intent than chat opens on blog pages
- Combine with session data, Track chat opens alongside session source/medium for attribution
- Avoid PII in dataLayer, Don't capture user email or name from Intercom's user object without consent
- 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.