# How to limit duplicate tag firing based on dataLayer variables, but with same event name?

**URL:** <https://community.piwik.pro/t/how-to-limit-duplicate-tag-firing-based-on-datalayer-variables-but-with-same-event-name/4715>\
**Category:** Data collection and tags\
**Created:** [December 11, 2024, 2:29pm UTC](https://community.piwik.pro/t/how-to-limit-duplicate-tag-firing-based-on-datalayer-variables-but-with-same-event-name/4715 "2024-12-11T14:29:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Bethlen](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/david_bethlen/32/3965_2.png) [@David\_Bethlen](https://community.piwik.pro/u/David_Bethlen)\
**Post date:** [December 11, 2024, 2:29pm UTC](https://community.piwik.pro/t/how-to-limit-duplicate-tag-firing-based-on-datalayer-variables-but-with-same-event-name/4715/1 "2024-12-11T14:29:31Z")

</div>

Dear Piwik Community,

I am running into a strange issue when trying to implement the Piwik Pro Tag Manager into an ecommerce site. The dataLayer is set in stone, I cannot change it. Whenever someone checks an item or adds something to the cart, two events fire on the site with different contents in the dataLayer.

Event 1:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/2/251ecd068c6d20013ec1e63b16b061449adf8eee.png)

Event 2:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/e/e8ac094d178a7efec9dd27243f92f2a4e03f162a.png)

As you can see, the event name is the same, but the dataLayer content differs. Now the problem is that a tag set to fire on the “arguments.add\_to\_cart” event fires on both of these (as expected). I would like to make sure it only fires once. My method was adding an additional parameter to the trigger that fires the tag. I tried with two separate solutions.

Solution 1:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/1/168c849a543674ae611dc0d4a9a58af35bf4af1f.png)

This resulted in the tag not firing at all.

Solution 2:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/3/3e60a4b4a71032ecc28edff41620d70f219a461e.png)

This resulted in the tag firing twice.

Looking further into the problem, I noticed that while the dataLayer pushes had different content in the two “arguments.add\_to\_cart” events, while looking at the variables the moment they fired, **there were no differences** in the value of the variables.  
My assumption is that the variables are being looked at globally by Piwik and not on an event-by-event basis. Do you have any recommendations on limiting the firing of the tag to only “Event 2” in my case?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Toon\_iO](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Toon\_iO](https://community.piwik.pro/u/Toon_iO)\
**Post date:** [December 11, 2024, 3:46pm UTC](https://community.piwik.pro/t/how-to-limit-duplicate-tag-firing-based-on-datalayer-variables-but-with-same-event-name/4715/2 "2024-12-11T15:46:16Z")

</div>

Variable values are kept until overwritten or until the page is refreshed. So unless the variables are already set from a different event on that page, the variables from the 2nd event shouldn’t be set yet with your first datalayer event. So your second solution should work I think. Maybe try “doesn’t equal undefined” instead of “is not set”?

---

<div class="post-metadata">

**Author:** ![David\_Bethlen](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/david_bethlen/32/3965_2.png) [@David\_Bethlen](https://community.piwik.pro/u/David_Bethlen)\
**Post date:** [December 12, 2024, 8:46am UTC](https://community.piwik.pro/t/how-to-limit-duplicate-tag-firing-based-on-datalayer-variables-but-with-same-event-name/4715/3 "2024-12-12T08:46:56Z")

</div>

What you are saying seems logical, but that’s not the case. That’s why I am stumped. When I am looking at a product page and press the add\_to\_cart button, I can see the following in the developer console (with an addon that shows the dataLayer and the Piwik \_paq pushes. Also note that I modified the trigger to what you suggested):

Event 1:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/e/e2cfeebcd42c04d5888d3efe03634b253d2d9f7d.png)

Event 2:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/9/98e7f2a49b32b522c826778a5ec4327fffaf2628.png)

Trigger in the debugger:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/b/b50ca10e64b105cb7a6ed9b6a338ba84b4e7d48e.png)

Event log in the Piwik debugger:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/c/ce90e30652de7f6e50a88bd28a31b97ccd95492f.png)

Event 28. and 29. contain the same variables.

While typing out my answer, I just realized that the view\_item event that happens when the page loads, and contains an “items” array. This is what is being read by the following two add\_to\_carts. The code is missing the nullification of the dataLayer before each push. With that, I was able to solve the problem.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/db7013c4fd6a24443b339309db52f14995207737.png) [@system](https://community.piwik.pro/u/system)\
**Post date:** [February 12, 2025, 11:33am UTC](https://community.piwik.pro/t/how-to-limit-duplicate-tag-firing-based-on-datalayer-variables-but-with-same-event-name/4715/4 "2025-02-12T11:33:39Z")

</div>

Closed on February 12, 2025, 11:33am UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
