Share feedback, ideas and get community help

Updated last week

Help with utm script

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?
Add a reply
Sign up and join the conversation on Discord
Its not working.How can I change it?","answerCount":0,"upvoteCount":0,"datePublished":"2025-01-09T14:01:20.981Z","author":{"@type":"Person","url":"https://community.typebot.io/members/190a28f2-aa6b-426b-973e-4b2f62309d01","name":"Lucas Otaviano","identifier":"190a28f2-aa6b-426b-973e-4b2f62309d01","image":"https://cdn.discordapp.com/avatars/590972340708442131/1562344b35326914598428e29934c40f.webp?size=256"},"suggestedAnswer":[]}}