There isn't an easy way to add an onclick attribute to your CTA. If you need to use a HubSpot CTA then you can try adding #hs-chat-open to the URL of the current page within a CTA, but that reloads the page and isn't a great experience. The best approach is to add the hyperlink code to your rich text content module using Advanced->Source code. The code above just displays a link, so if you want this to look like a CTA button you'll need to use some CSS styling. HubSpot has some CSS classes already built into their default stylesheets so you could try adding a class to your link as follows and see what that looks like:
<a href="#" onclick="window.HubSpotConversations.widget.open();" class="hs-button primary">Open Live Chat</a>
Ahhh I see. I wound up implementing mine a little differently with the URL applied in the source code of a rich text module. That "return false;" component was the missing piece for me.
There isn't an easy way to add an onclick attribute to your CTA. If you need to use a HubSpot CTA then you can try adding #hs-chat-open to the URL of the current page within a CTA, but that reloads the page and isn't a great experience. The best approach is to add the hyperlink code to your rich text content module using Advanced->Source code. The code above just displays a link, so if you want this to look like a CTA button you'll need to use some CSS styling. HubSpot has some CSS classes already built into their default stylesheets so you could try adding a class to your link as follows and see what that looks like:
<a href="#" onclick="window.HubSpotConversations.widget.open();" class="hs-button primary">Open Live Chat</a>
Hi JWharton, could you clarify what you mean? I think I'm trying to do the same thing as you with a button on a landing page, and having the same issue where the chat pops open the way I want it to, but it jumps the browser back up to the top of the page.
You can append #hs-chat-open to a URL to make the chat widget open on that page. If you are trying to open the chat widget on the page the user is already on, I find the best way is to use some JavaScript in the onclick attribute of your button link as follows
<a href="#" onclick="window.HubSpotConversations.widget.open();">Open Live Chat</a>
Matthew Shepherd
Freelance HubSpot Consultant CRM Consultant | SEO Specialist