Possibility to open the chat window by using custom button/js

Status: Delivered

Status history

+1

+1. Really surprised this isn’t a possibility…but then again…probably better to work on the ability to send images/attachments over chat first
16x16_smiley-surprised.png.png

100% need this.

Drift is making a BIG deal out of this feature and all of the up coming chatbot providers also provide this.

I am surprised that HS didn’t consider it yet

+1 I really need this. All set to integrate, but cannot without this basic requirement.

Definitely, +1, would be cool to see if there is a betta for it!

So I found an undocumented API:

window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen()

This triggers the chat window to open, which might be useful to some of you.

That is the only piece of the ‘experimental API’ that exists. There is no way to close the window and there are no callbacks to notify you if the chat window is opened, closed, resized etc. or to toggle targeted messages. I had to implement a resize observer to achieve those.

@markpetty

-

--------------------------------------------------------------------------------------------

window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen()

-------------------------------------------------------------------------------------------

Thanks for the share. For the non-developers among us, how would you use it?

How do we get it to work? Would it just be a case of adding this code as a submit action to the button?

We just solved it!

For anyone that would like a solution to this, get your developers to look at our implementation on Commino.co.uk

@Onur it is just native javascript, so you can paste that into an onclick function. Something like:

<button onclick="window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen()">Click me</button>

should work for native HTML.

+1 for sure.
It is so simple to implement this from HubSpot side, I don’t understand why it is not implemented yet. :disappointed_face:

Hi all, I’m very pleased to announce that we now have the ability to open the chat launcher by appending #hs-chat-open to your URLs, or by adding that as an anchor link tag on any buttons/links/etc. on your page. The team is also working on some more sophisticated solutions to enable the same behavior with custom CSS elements. I will update here when that goes live as well, but please enjoy the new functionality if you’ve been waiting for it! Details here: https://knowledge.hubspot.com/articles/kcs_article/conversations/how-to-use-conversations#automatically-open.

@hroberts Any plans to support javascript? Because I believe sophisticated solutions are easier with Javascript than CSS.

Hello everyone!

We have found a very easy solution. Watch the video to see the solution.

You can use the Javascript code below:

// logo-btn is ID for the element assigned with click event to show Hubspot chat window

// jQuery (ES6)
$('#logo-btn').on('click', () => {
	// check if Hubspot chat is installed
	if (window.hubspot_live_messages_running && window.hubspot && window.hubspot.messages) {
		window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen();
	} else {
		console.log('Please install HubSpot WordPress plugin');
	}
});

// VanillaJs (ES5)
document.getElementById('logo-btn').addEventListener('click', function(event) {
	// removef if it is no need to prevent default event such as url redirect in the <a> element
	event.preventDefault(true);
	// check if Hubspot chat is installed
	if (window.hubspot_live_messages_running && window.hubspot && window.hubspot.messages) {
		window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen();
	} else {
		console.log('Please install HubSpot WordPress plugin');
	}
});

<button onclick="window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen()">Click me</button>

This will work

this seems necessary in order to track chat clicks in GA or GTM. upvote!