<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/631282#M53124</link>
    <description>&lt;P&gt;Huh, that's interesting. I actually haven't changed anything since I originally posted this, so HubSpot may have done something on their end to fix it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My implementation is done through Google Tag Manager, so it's a little bit more round about, but it ultimately boils down to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;document.addEventListener('turbo:load', function(event) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;var _hsq = window._hsq = window._hsq || [];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;_hsq.push(["identify", {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; email: {{user_email}},&lt;BR /&gt;&amp;nbsp; &amp;nbsp; firstname: {{user_first_name}},&lt;BR /&gt;&amp;nbsp; &amp;nbsp; lastname: {{user_last_name}} }&lt;BR /&gt;&amp;nbsp; ]);&lt;BR /&gt;&amp;nbsp; _hsq.push(['setPath', window.location.pathname]);&lt;BR /&gt;&amp;nbsp; _hsq.push(['trackPageView']);&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other than that, I unfortunately don't have much insight as to why it's working.&lt;/P&gt;</description>
    <pubDate>Wed, 11 May 2022 19:48:05 GMT</pubDate>
    <dc:creator>tddrmllrWL</dc:creator>
    <dc:date>2022-05-11T19:48:05Z</dc:date>
    <item>
      <title>Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/228955#M7851</link>
      <description>&lt;P&gt;I have a rails 4 application with Turbolinks in it and I have configured Turbolinks for hubspots which will load in each page load event (note that, I have add a debugging code which is firing in each page load, so GTM is working). And I can see the hubspots script tag in my body as well as, in network tab it is doing a proper network call.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;PROBLEM&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When I refresh a page manually (hard refresh/reload) hubspot client interface (chat bubble window) shows up&lt;/LI&gt;
&lt;LI&gt;when I visit page with Turbolinks, those network call in network tab and hubspot script tag in document  tag persists, but that chat bubble window don't show up.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;How to solve this problem?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;UPDATE&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Any solution for Single Page Applications (like react, angular, vuejs) are also helpful.&lt;/LI&gt;
&lt;LI&gt;Turbolinks is making my application act like SinglePageApplication and I think that is the problem here.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 04 Jul 2018 08:16:19 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/228955#M7851</guid>
      <dc:creator>Shivraj_Badu</dc:creator>
      <dc:date>2018-07-04T08:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/228956#M7852</link>
      <description>&lt;P&gt;Hi &lt;A class="mention" href="https://community.hubspot.com/u/shivraj_badu"&gt;@Shivraj_Badu&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;Can you give me a link to an example page so that I can test this out?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 14:13:54 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/228956#M7852</guid>
      <dc:creator>Derek_Gervais</dc:creator>
      <dc:date>2018-07-17T14:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/335194#M32568</link>
      <description>&lt;P&gt;Was there ever a solution to this problem? 2 years later this still seems to be happening&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 22:01:45 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/335194#M32568</guid>
      <dc:creator>Tunch</dc:creator>
      <dc:date>2020-04-28T22:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/550886#M49860</link>
      <description>&lt;P&gt;I'm having the same issue. I use &lt;A href="https://turbo.hotwired.dev/handbook/introduction" target="_blank" rel="noopener"&gt;Turbo&lt;/A&gt;, which is the newer offshoot of Turbolinks, but it uses many of the same strategies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is that Turbo intercepts clicks and form sumissions, transmits data over the wire, and strategically replaces elements in the &amp;lt;body&amp;gt; tag. In most cases, it simply wipes out the all the contents of the body and replaces them with the contents of the requested page.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So with HubSpot, everything loads and works as expected on the intial page load. But as soon as you navigate to a new page, anything that HubSpot added to the body gets replaced, while everything else added client side remains (&amp;lt;head&amp;gt; tags, JS variables, etc.).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Turbo gives you some handy events to hook into, the main one being the turbo:load event, which fires whenever Turbo simulates a page change. So we can hook into this and do stuff, like re-insert the HubSpot tracking code, on every page change (though this sorta seems unnecessary since most of the HubSpot code remains).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if you visit &lt;A href="http://app.worklyfe.io/users/sessions/new" target="_blank" rel="noopener"&gt;app.worklyfe.io/users/sessions/new&lt;/A&gt;, you'll see that the HubSpot chat widget appears on initial page load (it might take a bit to load as it's currently hosted on a Heroku hobby dyno). But if you click the forgot password link, the widget does not appear on the next page.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I open up the JS console, I can access the&amp;nbsp;HubSpotConversations variable. But none of the methods on&amp;nbsp;HubSpotConversations.widget&amp;nbsp;(refresh, load, open, etc.) have any effect (presumably because the widget's &amp;lt;iframe&amp;gt; is no longer there).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can call&amp;nbsp;HubSpotConversations.resetAndReloadWidget(), which does make the widget re-appear and functional. However, previous conversations and cookie consent is lost, so it is not a seamless experience from page to page.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would hope that you guys have implemented strategies to deal with this, because it's not that different from SPA behavior. But I have not been able to figure out a reasonable solution.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 22:01:47 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/550886#M49860</guid>
      <dc:creator>tddrmllrWL</dc:creator>
      <dc:date>2022-01-05T22:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/630035#M53069</link>
      <description>&lt;P&gt;Hey, I visited the link you posted and it looks like everything is working now.&lt;BR /&gt;&lt;BR /&gt;We're facing the same issue as OP (again, Turbolinks, not Turbo), and we've followed your post and found the same issue with chat and cookie persistence.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you mind sharing how you fixed it, please?&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 10:40:10 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/630035#M53069</guid>
      <dc:creator>StefanMM</dc:creator>
      <dc:date>2022-05-10T10:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/630400#M53091</link>
      <description>&lt;P&gt;Hey,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/382982"&gt;@StefanMM&lt;/a&gt;&amp;nbsp;thanks for the follow-up question. Let's see if&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/305025"&gt;@tddrmllrWL&lt;/a&gt;&amp;nbsp;has any insight for us on how they worked this out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you! – Jaycee&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 18:27:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/630400#M53091</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2022-05-10T18:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/631282#M53124</link>
      <description>&lt;P&gt;Huh, that's interesting. I actually haven't changed anything since I originally posted this, so HubSpot may have done something on their end to fix it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My implementation is done through Google Tag Manager, so it's a little bit more round about, but it ultimately boils down to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;document.addEventListener('turbo:load', function(event) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;var _hsq = window._hsq = window._hsq || [];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;_hsq.push(["identify", {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; email: {{user_email}},&lt;BR /&gt;&amp;nbsp; &amp;nbsp; firstname: {{user_first_name}},&lt;BR /&gt;&amp;nbsp; &amp;nbsp; lastname: {{user_last_name}} }&lt;BR /&gt;&amp;nbsp; ]);&lt;BR /&gt;&amp;nbsp; _hsq.push(['setPath', window.location.pathname]);&lt;BR /&gt;&amp;nbsp; _hsq.push(['trackPageView']);&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other than that, I unfortunately don't have much insight as to why it's working.&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 19:48:05 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/631282#M53124</guid>
      <dc:creator>tddrmllrWL</dc:creator>
      <dc:date>2022-05-11T19:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/631633#M53137</link>
      <description>&lt;P&gt;Hi there. This is acutally very helpful. Having the same issue too!&lt;BR /&gt;&lt;BR /&gt;I've implemented hubspot through google tag manager too. I'm interested to know about your setup. Does your hubspot tag in gtm just contain the recommended snippet?&lt;BR /&gt;&lt;BR /&gt;&amp;lt;!-- Start of HubSpot Embed Code --&amp;gt;&lt;BR /&gt;&amp;lt;script type="text/javascript" id="hs-script-loader" async defer src="//js-eu1.hs-scripts.com/{id}.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;BR /&gt;&amp;lt;!-- End of HubSpot Embed Code --&amp;gt;&lt;BR /&gt;&lt;BR /&gt;Is the event listener implemented on all pages across your site?&lt;BR /&gt;&lt;SPAN&gt;document.addEventListener('turbo:load', function(event) {&lt;BR /&gt;&lt;/SPAN&gt;...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 10:06:41 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/631633#M53137</guid>
      <dc:creator>ZStone1</dc:creator>
      <dc:date>2022-05-12T10:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/632657#M53187</link>
      <description>&lt;P&gt;For the GTM code that goes in the head of my site, I added turbo:load event listener that pushes a custom event to the GTM data layer:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;document.addEventListener('turbo:load', function(event) {&lt;BR /&gt;&amp;nbsp; dataLayer.push({ 'event':'turbo_load' });&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then within GTM I created a custom trigger that hooks into the dataLayer event from above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tddrmllrWL_0-1652461264645.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/66314iAD77DE3045CCC2F9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tddrmllrWL_0-1652461264645.png" alt="tddrmllrWL_0-1652461264645.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And my HubSpot tag in GTM looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tddrmllrWL_1-1652461353762.png" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/66315i0D295D198359A97F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tddrmllrWL_1-1652461353762.png" alt="tddrmllrWL_1-1652461353762.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 17:05:25 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/632657#M53187</guid>
      <dc:creator>tddrmllrWL</dc:creator>
      <dc:date>2022-05-13T17:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Rails 4 + Turbolinks app don't load hubspots client interface, but hard refresh is working</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/648601#M54095</link>
      <description>&lt;P&gt;For anyone who is still struggling with this, I have found a workaround:&lt;BR /&gt;In the rails app,&lt;BR /&gt;&lt;BR /&gt;In head,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script type="text/javascript"&amp;gt;
    (function () {
        document.addEventListener('turbo:before-fetch-request', function (e) {
            e.detail.fetchOptions.headers['Turbo'] = true;
        });
    })();
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;At the end of the body tag,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    &amp;lt;script data-turbo-permanent id="hs-preservation-script"&amp;gt;
        function preserveHubspotChat() {
            const element = document.querySelector('#hubspot-messages-iframe-container')

            if(element) {
                // console.log('HubSpot Conversations: loaded')
                const styleTags = document.body.querySelectorAll("style[type='text/css']");
                for (const tag of styleTags) {
                if(tag.innerHTML.indexOf('hs-messages') != -1) {
                    tag.id = "hs-messages-styles"
                    tag.setAttribute('data-turbo-permanent', '')
                }
                }
                element.setAttribute('data-turbo-permanent', '')
            } else {
                // console.log('HubSpot Conversations: nope')
                setTimeout(() =&amp;gt; {
                preserveHubspotChat();
                }, 100);
            }
        }

        function onConversationsAPIReady() {
            preserveHubspotChat()
        }
        
        if (window.HubSpotConversations) {
            onConversationsAPIReady();
        } else {
            /*
                Otherwise, callbacks can be added to the hsConversationsOnReady on the window object.
                These callbacks will be called once the external API has been initialized.
            */
            window.hsConversationsOnReady = [onConversationsAPIReady];
        }
    &amp;lt;/script&amp;gt;
    &amp;lt;%if request.headers['Turbo']%&amp;gt;
        &amp;lt;style data-turbo-permanent id="hs-messages-styles"&amp;gt;
        &amp;lt;/style&amp;gt;
    &amp;lt;div data-turbo-permanent id="hubspot-messages-iframe-container"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;%end%&amp;gt;
    &amp;lt;script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/[[id]].js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 12:10:42 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Rails-4-Turbolinks-app-don-t-load-hubspots-client-interface-but/m-p/648601#M54095</guid>
      <dc:creator>k4rth1k</dc:creator>
      <dc:date>2022-06-13T12:10:42Z</dc:date>
    </item>
  </channel>
</rss>

