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

160
Vistas
how to clear variable in google tag manager through tag

i am trying to reset values of variable in google tag manager when particular tag fires

example:

action : add-to-cart

when 'add to cart' button is clicked then via datalayer i am pushing product data to gtm. this data i am storing in different variable such as - productid, productname ,productprice.

now when add to cart button hits then this variables will fill with data.

after that i have created one tag which sends this variable to 3rd party site via tag.

tag name : send-data-to-3rd-partysite
tag type : custom html
tag trigger - productprice does not contain undefined.

it means when productprice does not contains undefined then this tag should fire. (at start it contains undefined ) but problem is that when one 'add to cart' button is hits then the variable contains those product data for entire session and when another add to cart button hits then the data is replaced by new one. problem is here that 'send-data-to-3rd-partysite' fired when productprice contains some value. it does not fires becuase of productprice is not undefined.

so what i want is when 'send-data-to-3rd-partysite' tag fires then 'productprice' variable should be reset or clear. i tries below code in send-data-to-3rd-partysite tag but did not work

<script>
...
window.google_tag_manager[{{productprice}}].dataLayer.reset();
<script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try not to reset the dL. It leads to complete flush and that's not a very good thing to do, considering how DL is supposed to be used.

What I saw people doing and it works pretty well, however flimsy looks, is making a custom HTML tag where they push undefines into the DL, effectively overwriting the old values.

In your case, it would be something like dataLayer.push({productprice : undefined})

Now you use timing rules to always fire this tag after the tag that uses productprice has fired and there you go, your cleaning logic is in place.

I just want to mention that if you have to clean up DL like this, then your tracking architecture is a wreck. This must be viewed as a hack and not an elegant one.

about 4 years ago · Juan Pablo Isaza Denunciar
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