Open Intercom chat on click

Hi,
I have Intercom installed on my website through the “third-party trackers” settings with the HTML script in the .

However, following their Javascript API to open the chat using the following command:

Intercom ( ‘show’ );

I always get the following error:

Intercom is not defined

How can I import the Intercom library or so? Because this method used to work on other website builders.
Many many thanks

You cannot use Intercom in your Velo code.

Try to use wixWindow.postMessage() to tel your custom code added to the wix settting to receive the event, then the event will call Intercom(‘show’)

Wix Velo and intercom embed code is under different scope, so you cannot share the code without a bridge (event listener)

Thanks for your fast reply!

Is this something that could work?

window.addEventListener('intercom', (event) => {
console.log(event.data);
});

Added in the code like this:

<script>
// We pre-filled your app ID in the widget URL: 'https://widget .intercom 
 .io/widget/XXX'
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget .intercom .io/widget/XXX';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();
wixWindow.addEventListener('intercom', (event) => {
console.log(event.data);
});
</script>

And on my home page :

$w.onReady(function () {
    wixWindow.postMessage("intercom", "certifio .io");
});

But nothing seems to happen and I don’t know how to debug it.
Many thanks

Post message should be in object, like {intercom: “open”}

Then on the HTML code

If the event.data.intercom === “open”

Then call intercom open

No need fill in the target in the postMessage

@certified-code

With both these code snippets, it seems like nothing trigger the event

$w.onReady(function () {
    wixWindow.postMessage({intercom:'open'})
});
$w.onReady(function () {
    wixWindow.postMessage("intercom");
});

I’ve added a console.log in the HTML code to be sure but nothing happening:

window.addEventListener('intercom', (event) => {
console.log('xx');
});

Anyone to help on this one ?

Hi!
I have the same problem.
Any chances you have found a solution? :sweat_smile: