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

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:

Event 2:

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:

This resulted in the tag not firing at all.

Solution 2:

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!

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”?

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:

Event 2:

Trigger in the debugger:

Event log in the Piwik debugger:

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.

1 Like