Tengo un código personalizado para activar mi instancia de bot de chat en vivo si un usuario visita una URL en particular.
if(location.hash.indexOf("#/financial-bills")>-1){ return true;El problema es que los chats se repiten si voy a las URL secundarias, por ejemplo, #/financial-bills/summary Mi código de chat está a continuación:
var initESW = function(gslbBaseURL) { embedded_svc.init( 'https://example.com', 'https://example/ChatBot', gslbBaseURL, '00D4C00000019Iy', 'Support_Only', { baseLiveAgentContentURL: 'https://c.la2-c1cs.com/content', deploymentId: '5721E', buttonId: '5731E', baseLiveAgentURL: 'https://d.la2-c1cs.com/chat', eswLiveAgentDevName: 'EmbeddedServiceLiveAgent_Parent0200EAA_1754b2de11b', isOfflineSupportEnabled: false } ); }; if (!window.embedded_svc) { var s = document.createElement('script'); s.setAttribute('src', 'https://example/embeddedservice/5.0/esw.min.js'); s.onload = function() { initESW(null); }; document.body.appendChild(s); } else { initESW('https://service.force.com'); }Mi problema es que quiero que la función de chat se inicialice solo una vez. Como creo, está causando que los chats se repitan. Intenté eliminar el script de chat en función del evento de cambio de URL, pero no me funciona.
script.id = "test"; window.addEventListener('popstate', function (event) { (elem=document.getElementById("test")).parentNode.removeChild(elem) });Puede utilizar una cookie de sesión temporal para comprobar si el chat se inició una vez o no. Si no, simplemente inicialice el chat y configure la cookie .
function setCookie(cname,cvalue) { document.cookie = cname+"="+cvalue; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } if(!getCookie('chatInitialized')){ initChat(); setCookie('chatInitialized', true); }