Share feedback, ideas and get community help

Home
Members
Lucas Otaviano
L
Lucas Otaviano
Offline, last seen last week
Joined January 9, 2025
Hey guys!

Im trying to add a js script that replace the user url with a new utm parameter after typebot starts and run some few questions.

Im using this code:

Plain Text
 <script>
        // Função para obter os parâmetros da URL
        function getUrlParams() {
            const params = new URLSearchParams(window.location.search);
            return params;
        }

        // Função para atualizar ou adicionar os parâmetros utm_term e src na URL
        function updateUtmAndSrc(newUtmTerm) {
            const params = getUrlParams();
            
            // Atualiza ou adiciona o parâmetro utm_term
            params.set('utm_term', newUtmTerm);
            
            // Atualiza ou adiciona o parâmetro src com o mesmo valor de utm_term
            params.set('src', newUtmTerm);

            // Monta a nova URL com base nos parâmetros
            const baseUrl = window.location.protocol + "//" + window.location.host + window.location.pathname;
            const queryString = params.toString();
            const newUrl = baseUrl + (queryString ? '?' + queryString : '');  // Garante que a URL será correta

            // Atualiza a URL no navegador sem recarregar a página
            window.history.replaceState({}, '', newUrl);
        }

        // Exemplo de uso
        window.onload = function() {
            const newUtmTerm = '676f065797f07b0cc3a11cdd';  // **Aqui você define o valor de utm_term e src**
            updateUtmAndSrc(newUtmTerm);
        }
    </script>


Its not working.

How can I change it?