Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
How to use an if statement to only collect forms fields that contain an '@' symbol in?

I'm currently collecting form abandonments from my website using the javascript code below within the tag manager of analytics software (Piwik pro).

It currently works great, however, I'm now trying to make it so that only emails with an '@' collect and nothing else.

I'm thinking that an if statement that has .includes("@") will do the job, however as I'm a beginner and I did not write this code, I am struggling to make it work. The below shows what I've tried (amongst many other attempts) and it either continues to collect everything or doesn't collect anything...

(Also I'm unsure if _paq.push is used outside of the analytics software I use, but that line creates a custom event within Piwik pro.)

formFields = ['input_3_1','input_3_2','input_3_3','input_3_4']

  let formFieldText = document.getElementById('input_3_1').value
  let fieldHasAtSymbol = formFieldText.includes("@")
  
  if (fieldHasAtSymbol = 'true') {

        function trackUnsubmittedField(fieldId){
          let formField = document.getElementById(fieldId)
          if(formField.nodeName==="SELECT"){
            formField.addEventListener('change',()=>{
              _paq.push(['trackEvent','formAbandonment',fieldId,document.getElementById(fieldId).value])
            })
          }
          else{
            formField.addEventListener('focusout',()=>{
                _paq.push(['trackEvent','formAbandonment',fieldId,document.getElementById(fieldId).value])
            })
          }
        }
  }
        formFields.map(element=>trackUnsubmittedField(element))

I've also tried using the same form field variable that's declared within the function by placing a .includes() if statement within it, but no luck.

formFields = ['input_3_1','input_3_2','input_3_3','input_3_4']

        function trackUnsubmittedField(fieldId){
          let formField = document.getElementById(fieldId)
          
                if (formField.includes("@") = "true") {
          
          if(formField.nodeName==="SELECT"){
            formField.addEventListener('change',()=>{
              _paq.push(['trackEvent','formAbandonment',fieldId,document.getElementById(fieldId).value])
            })
          }
          else{
            formField.addEventListener('focusout',()=>{
                _paq.push(['trackEvent','formAbandonment',fieldId,document.getElementById(fieldId).value])
            })
                }
        }
  
        formFields.map(element=>trackUnsubmittedField(element))

There's probably a lot wrong with the code I added onto this but any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda