APIs & Integrations

HLarsen
Member

Can't get SPA to select chat flow

SOLVE

I've set up a chatflow where I check whether WebSite URL contains a specific word. This works if I load the browser with a URL with the specified word in it. But I can't get this to work in my single page application. On navigation I do the following:

 

history.pushState({ state: <state>, title: <title> }, <title>, <url>);

_hsq.push(['setPath', <relative url>]);
_hsq.push(['trackPageView']);

window.HubSpotConversations.widget.refresh();

 

As I read the documentation, widget.refresh() should activate the chatflow based on the URL set in pushState, but this does not work for me.

0 Upvotes
1 Accepted solution
sylvain_tirreau
Solution
Top Contributor

Can't get SPA to select chat flow

SOLVE

I think you should do something like that:

function handleUrlChange(path){
  window._hsq = window._hsq || [];
  window._hsq.push(['setPath', path]);
  window._hsq.push(['trackPageView']);
  window.HubSpotConversations?.widget?.refresh();
}

View solution in original post

0 Upvotes
6 Replies 6
sylvain_tirreau
Top Contributor

Can't get SPA to select chat flow

SOLVE

Hi,

What framework (route manager) are you using in your application?

HLarsen
Member

Can't get SPA to select chat flow

SOLVE

I don't know what you mean. It's a browser based application using jQuery.

0 Upvotes
sylvain_tirreau
Top Contributor

Can't get SPA to select chat flow

SOLVE

Without more code, it's hard to answer you. But basically, you need to force the Hubspot widget to reevaluate the chatflow rules every time the URL changes.

HLarsen
Member

Can't get SPA to select chat flow

SOLVE

That's what I'm trying to do with this code:

 

window.HubSpotConversations.widget.refresh();

0 Upvotes
sylvain_tirreau
Solution
Top Contributor

Can't get SPA to select chat flow

SOLVE

I think you should do something like that:

function handleUrlChange(path){
  window._hsq = window._hsq || [];
  window._hsq.push(['setPath', path]);
  window._hsq.push(['trackPageView']);
  window.HubSpotConversations?.widget?.refresh();
}
0 Upvotes
BérangèreL
Community Manager
Community Manager

Can't get SPA to select chat flow

SOLVE

Hi @HLarsen, I hope that you are well!
 

Thanks for asking the HubSpot Community!

First, for information, I'd like to share the documentation about the topic: "Conversations SDK".

I'd love to put you in touch with our Top Experts: Hi @MatthewShepherd, @Anton and @sylvain_tirreau do you have suggestions to help @HLarsen, please?

Have a lovely day and thanks so much in advance for your help!
Bérangère


HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates.
Learn More.


Saviez vous que la Communauté est disponible en français?
Rejoignez les discussions francophones en changeant votre langue dans les paramètres! !
0 Upvotes