Skip to main content
Answered

Is there an on ready callback for the Javascript API

  • September 15, 2021
  • 4 replies
  • 630 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.

View original
Did this topic help you find an answer to your question?

4 replies

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

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


  • Author
  • New Participant
  • 4 replies
  • 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
  • 1630 replies
  • 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
  • 4 replies
  • Answer
  • September 20, 2021

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings