I have a (new [not Beta anymore]) CTA on my website whose Hubspot-provided embed code looks like this: (though I swapped out some numbers to “anonymize” it)
<div class="hs-cta-embed hs-cta-embed-123456789123456789" style="max-width:100%; max-height:100%; width:315px;height:300px" data-hubspot-wrapper-cta-id="123456789123456789">
<link rel="stylesheet" href="https://js.hscta.com/embeddable_cta_placeholder_v1.css">
<div class="hs-cta-loading-dot__container">
<div class="hs-cta-loading-dot"></div>
<div class="hs-cta-loading-dot"></div>
<div class="hs-cta-loading-dot"></div>
</div>
<div class="hs-cta-embed__skeleton"></div>
<picture>
<source srcset="data:image/gif;base64,R0lGODlhAQABAAAABAAEAAAICTAEAOw==" media="(max-width: 480px)" />
<img alt="Some alt text" loading="lazy" src="https://no-cache.hubspot.com/cta/default/0000000/interactive-123456789123456789.png" style="height: 100%; width: 100%; object-fit: fill" onerror="this.style.display='none'" />
</picture>
</div>
When I embed the CTA on a page, it loads perfectly no problem on the first page load. BUT if I click through via my single-page application to go to the location of the embed (ie. I do a browser history change instead of a full pageview), the “CTA initializer” scripts fail to run, and the CTA does not “become” its true interactive self — it just sits as the png referenced above. The scripts must be set to execute only once (probably when the DOM is ready or when the window is loaded?).
I’ve tried re-injecting the script into the page via the below; this doesn’t work as I get the error “duplicate instance of web interactives app exists”.
var script = document.createElement('script');
script.src='https://js.hubspot.com/web-interactives-embed.js';
document.body.appendChild(script);
I’m looking for a clean way to re-run the CTA initializers (I guess the web-interactives-embed.js script? Or maybe https://js.hscta.net/cta/current.js ?), without forcing my users to refresh the page. There are precedents for this in other Hubspot tools, for example:
- The chat app has the function HubSpotConversations.widget.refresh()
- The analytics tools can use the function _hsq.push([‘refreshPageHandlers’])
I have tried exploring the relevant JS objects that exist on the page via the browser console, but most of them are poorly documented (if at all), and I haven’t been able to find a way to do a sort of “CTA force refresh”. Some potentially relevant “keywords”:
- hsCtasOnReady
- __PRIVATE__HubspotCtaClient
- hubspot_web_interactives_running
- __hsWebInteractiveInstance
- _hsp, _hsq, _hspb variations, _hstc variations
- hubspot.form.api
- window.hbspt.cta
Any help or ideas for alternate approaches are greatly appreciated. Ideally, I don’t need to do anything different on my back-end; There should be a client-side solution for this, I think? It doesn’t feel like it should be as hard as it is.