Is there a way to detect if Intercom Messenger is available?

Feature-Request

#1

We have a handful of “Send us a Message” or “Contact Us” buttons around our web application that open Intercom to showNewMessage, but the Intercom Messenger isn’t always available. In some cases, Intercom isn’t fully loaded when the click the button or they just have Intercom blocked (eg. adblocker type extensions). This affects at least 5% of our users, though rarely comes up…

Ideally, I would like these buttons/links to attempt to open Intercom and fallback to opening an email in a new tab instead. The issue is just detecting when to fallback if Intercom is unavailable.

The first thought was to use Intercom('getVisitorId'), but that appears to always return undefined nowadays (on all environments), though this did work months ago. Bit confused why this has broken and this previous post doesn’t answer that.

The only other approach I could see was to hack together a timeout with Intercom('onShow', …) if the callback doesn’t fire, open a new tab. The user experience with this isn’t great, but if that’s the only option, it might just do.

Is there any approach I’m missing to detect this?


#2

Hey kylorhall :wave:

Currently there is no built-in way to detect if the Intercom Messenger is available. Though, it’s something we’ll possibly tackle in future iterations of our Messenger JS API.

For now, you could run some custom Javascript code to detect if the Intercom frame element exists on the page within a setInterval function.

You can view an example on our Messenger demo CodePen here: https://codepen.io/intercom/pen/QGqWxw

You’ll see the following code in the JS section on that CodePen:

//Code to check that launcher is loading
var retries = 0;
var launcherExist = setInterval(function() {
  if ($('.intercom-launcher-frame').length) {
    $('.checkmark').css({'display':'inline-block'});
    $('.still-no-messenger').hide();
    clearInterval(launcherExist);
  }
  retries += 1;
  if (retries >= 120) {
    clearInterval(launcherExist);
  }
}, 500);

Here we’re using a setInterval function to determine if the element with the intercom-launcher-frame class exists to load the green checkmark next to the “Install Intercom to get started” headline. That principle could be used to load your email workaround until the element exists, i.e. meaning there is no ad-blocker and Intercom has completed loading.

Please note, while this class currently exists for the Messenger, future versions of the Messenger might have different class names, so I can’t guarantee this will work forever.

Hopefully we’ll get a more intuitive method of checking for the Messenger availability before making any changes to the class names :crossed_fingers: I’ll add the feature request label to your topic here so we can keep track of it internally.

Regarding the Intercom('getVisitorId') issue you mentioned, would you mind reaching out to our support team via the messenger inside the Intercom app so we can take a look into your case please? It might require us to exchange some internal logs/details - I believe it’s best to discuss that in private first. We can always come back to this thread once we uncovered the problem :+1:


#3

Found there is a way to know if Intercom Javascript has been blocked: use Intercom('onUnreadCountChange') as part of the JavaScript API

It will trigger for pages that have Intercom loaded

var intercomLoaded = false;
Intercom('onUnreadCountChange', function(unreadCount) {
  intercomLoaded = true;
});

Then the intercomLoaded variable could be used for any custom actions if needed :+1:

This still won’t capture all instances of the messenger being available (e.g. if Intercom is loaded but there is no initialisation or if there is an issue with the initialisation) but it is an alternative if needed


#4


Let me try…