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

80
Visualizações
Deleting Google Analytics cookies on server

We have been trying to remove the Cookies that GTM creates when we specify that the user don't want them enabled.

We load GTM the first thing of the header, then the JS Cookies library and finally our following code.

// Loaded page
window.dataLayer = window.dataLayer || [];
function gtag(){
    dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'XX-XXXXXXXX-X');

if (cookiesEnabled) { // a variable that shows if they are enabled
  // Cookies accepted
  window['ga-disable-XX-XXXXXXXX-X'] = false
} else {
  window['ga-disable-XX-XXXXXXXX-X'] = true
}

// Function to set the cookies
function setCookies (accepted) {
if (!accepted) {
  Cookies.set('_ga', undefined, {
    expires: -1,
    path: '', // Also tested with /
    domain: `.${document.domain}`
  })
  Cookies.set('_gid', undefined, {
    expires: -1,
    path: '', // Also tested with /
    domain: `.${document.domain}`
  })
  Cookies.set('_gat_gtag_XX_XXXXXXXX_X', undefined, {
    expires: -1,
    path: '', // Also tested with /
    domain: `.${document.domain}`
  })
  
  // This was also tested
  Cookies.remove('_ga', {
    path: '', // Also tested with /
    domain: `.${document.domain}`
  })
  Cookies.remove('_gid', {
    path: '', // Also tested with /
    domain: `.${document.domain}`
  })
  Cookies.remove('_gat_gtag_XX_XXXXXXXX_X', {
    path: '', // Also tested with /
    domain: `.${document.domain}`
  })
}
}

We have tried this on both ways, with set and remove. The code running on our local machine works perfectly, the cookies are being removed without any problem, but then, when we pass the exact same code to our test server, those cookies will not be removed.

There is something that maybe we are missing? We were unable to find what.

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