Answered

How to trigger intercom chat when a link or button is clicked on WordPress.

  • 11 July 2022
  • 3 replies
  • 5492 views

I want to assign a function to a button in Elementor that says Chat with us and when clicked, an intercom chat pops up

icon

Best answer by User677 11 July 2022, 21:25

View original

3 replies

Behold; the Javascript API: https://developers.intercom.com/installing-intercom/docs/intercom-javascript#intercomshownewmessage/p>

 

These methods are pretty easy to implement and set up. On "Intercom('showNewMessage')" note there is a Pre-Population of message option, so the chat window can open, with a new message. This can help if you want to prompt people with a specific starting message for the new chat.

Thanks @user677​ for your swift response.

 

<script>

  document.querySelector("#my_custom_link").addEventListener("click", ()=>{

  Intercom("show")

})

</script>

 

So I added this script using Insert Headers and Footers but it didn't work unfortunately

 

 

Hey there - I'm unable to troubleshoot your Javascript. You're best working with a developer to get into your site and handle that. I'm also unsure what CMS/platform you're using referencing "Insert Headers and Footers"

 

But as some general advice — assuming you have the selector of the button correct (#my_custom_link), my guess is that the Javascript is loading before the button on your site loads. So the "addEventListener" isn't getting attached to the button. The button has to be loaded in the DOM first by the time the Javascript is in the page code.

 

I'd recommend looking into Javascript code to add here that waits for your entire page DOM to load, THEN does the code you already have. You could also just make your button link 'javascript:Intercom("show")' assuming your CMS allows that.

Reply