Answered

Is there an on ready callback for the Javascript API

  • 15 September 2021
  • 4 replies
  • 417 views

Looking to call a function only when the Intercom ( window.Intercom ) object is made available.

icon

Best answer by Preston H 20 September 2021, 16:30

View original

4 replies

Userlevel 1

Hey @preston h​, can you explain a bit more about your use case here?

@eric f11​ of course! We've deferred the loading of the intercom widget until the user's first interaction with the page (click, scroll, mousemove) to help with FCP. With that being said there could be a small chance that when we run an update (Intercom('update', { .. })), or some other command, that the Intercom object is not yet available and would throw exceptions.

 

Some of the other third party libraries we're integrating with have callback functions that trigger when the lib is available to help ensure you're not attempting to use an undefined object.

 

Userlevel 1

@roy s11​, as someone who knows a lot about custom JS setups for Intercom, would you be able to advise here?

I ended up adding an onload event to the generated script tag Intercom adds to the DOM.

Reply