Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Após essa configuração inicial, no Google Tag Manager modifique o script de ativação para capturar os eventos enviados pelo componente Evento WebChat:

Code Block
languagenone
<script type="text/javascript">
    (function(s, z, c, h, a, t) {
        s.webchat = s.webchat || function() {
            (s.webchat.q = s.webchat.q || []).push(arguments);
        };
        t = z.createElement(c),
        a = z.getElementsByTagName(c)[0]; t.async = 1;
        t.src = 'https://domainhub.conecta.szcom.chatvc/webchat/v2/webchat.js'; 
        a.parentNode.insertBefore(t, a);
        s.webchat('cid', '615daaae7a90be00117c5930');
        s.webchat('host', h);
    })(window, document, 'script', 'https://domainhub.conecta.szcom.chatvc');
    
    window.dataLayer = window.dataLayer || [];
    
    window.addEventListener("message", function(event) {
        if(event.origin !== 'https://domainhub.conecta.szcom.chatvc') return;
        
        if(event.data.action === 'chat-event'){
            window.dataLayer.push({
                event: event.data.action,
                message: event.data.message
            });
        }
    }, false);
    
    window.webchat('afterOpen', function(event) {
        window.dataLayer.push({ chat_status: 'aberto' });
    });
</script>

...

  1. Obrigatório: declaração da lista de objetos, contendo variáveis e eventos do Tag Manager.

    Code Block
    window.dataLayer = window.dataLayer || [];
  2. Capturar os eventos do fluxo e enviá-los para o Google Tag Manager.

    Code Block
    window.addEventListener("message", function(event) {
        if(event.origin !== 'https://hub.conecta.com.vc') return;//origem
    
        if(event.data.action === 'chat-event'){//ação do componente
            window.dataLayer.push({//envio dos eventos
                event: event.data.action,
                message: event.data.message
            });
        }
    }, false);

...