Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

81
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda