Can't get SPA to select chat flow

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.

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

Hi,

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

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

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.

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

window.HubSpotConversations.widget.refresh();

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