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

It could be nice to have a possibility to open/expand the chat window by clicking on a custom button. Plenty of people would like to have (and need) this option.

 

You can also see this topic: https://community.hubspot.com/t5/Content-Design-Questions/Chat-Messages-custom-button-open-chat-wind...

34 Replies
yaroinfo
New Contributor

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');
	}
});

 

HubSpot Product Team
HubSpot Product Team
updated to: Delivered

Hi all, I missed that there was a duplicate idea filed here. Please check out the update over on https://community.hubspot.com/t5/HubSpot-Ideas/Possibility-to-open-the-chat-window-by-using-custom-b.... If you have additional requests of a similar nature (I see some about a dedicated bot page, etc.) feel free to file new ideas posts for us to track community interest!

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

This will work 

lukerunnells
Occasional Contributor

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