Is there an on ready callback for the Javascript API | Community
Skip to main content
Answer

Is there an on ready callback for the Javascript API

  • September 15, 2021
  • 4 replies
  • 719 views

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

Best answer by Preston H

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

4 replies

Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • September 17, 2021

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


  • Author
  • New Participant
  • September 17, 2021

@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.

 


Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • September 20, 2021

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


  • Author
  • New Participant
  • Answer
  • September 20, 2021

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