Integrating Zoho with Turbolinks

Integrating Zoho with Turbolinks

Hi there, I'm trying to integrate Zoho SalesIQ with TurboLinks and could do with some help. 

Turbolinks means that instead of loading a new page, sections of the html are just update, giving you a SPA looks and feel. The problem is that means the zoho script doesn't reload.

Theoretically, you should be able to move the code snippet to inside an event listener which is triggered when someone follows a link. But that doesn't work (it think due to the fact that the script needs access to the DOM). Any advice?

  1. document.addEventListener('turbolinks:load', event => {
  2. var $zoho=$zoho || {};$zoho.salesiq = $zoho.salesiq ||{widgetcode:"e4e911729aeb93f576887a38a60bcc164dca5ecaeac3183849696e8dfe94206d62d20b68642a16c6f30a825097b333c1", values:{},ready:function(){}};
  3. var d=document;s=d.createElement("script");s.type="text/javascript";s.id="zsiqscript";s.defer=true;
  4. s.src="https://salesiq.zoho.com/widget";t=d.getElementsByTagName("script")[0];t.parentNode.insertBefore(s,t);d.write("<div id='zsiqwidget'></div>");
  5. });


Gives the error ReferenceError: $zoho is not defined at widget:1