Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!