I want to assign a function to a button in Elementor that says Chat with us and when clicked, an intercom chat pops up
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.
You can follow this guide to setup intercom chat to your wordpress website
Reply
Join the Intercom Community 🎉
Already have an account? Login
Login to the community
No account yet? Create an account
Intercom Customers and Employees
Log in with SSOEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.