Home / Guides

One click, three pushes: picking the right dataLayer event

Adding to cart rarely fires one event. What a real storefront pushes, which of them a trigger should use, and the four kinds of push that are never the answer.

· By hsynkvlc

The instruction sounds simple: click add to cart, see what the page pushes, build a trigger on it. Then you do it on a real storefront and three things arrive within half a second, and only one of them is the one you want.

One action is not one push

A themed storefront usually fires its own button event first, then the analytics one a moment later. A product card can push select_item and then view_item. A cart widget adds its own cart_updated afterwards.

Taking the first push is the honest answer to "what did that click do" and the wrong answer to "what should my trigger listen for". So the useful thing is not to pick one — it is to keep the ones that arrive in the seconds after and let you choose. A twelve-second window and a handful of candidates covers a click; longer and you start catching the next thing you did.

Tag Master after one add-to-cart click: it caught add_to_cart, lists the other two pushes the same click produced — theme_add_to_cart and cart_updated — and shows the event parameters with currency and value already ticked.
One click, three pushes. The theme fired first, so a tool that simply took the next push would have built a trigger on theme_add_to_cart. The money is ticked by default; the item-level fields are not, because they describe one line rather than the order.

Tag Master's Pick Event does exactly this: arm it, do the thing on the page, and it shows what was caught alongside the other pushes the same action produced — then turns your choice into a Custom Event trigger name and the Data Layer Variables to create.

Four kinds of push that are never the answer

Anything watching the dataLayer has to ignore these, or it will confidently catch the wrong thing:

  1. Container lifecycle events. gtm.js, gtm.dom, gtm.load and friends arrive on every page load. They are the container talking to itself, and they win any race against a real interaction.
  2. Pushes with no event name. A push that only carries data is staging values for a later event. It happened, but it is not something that happened to the visitor.
  3. The ecommerce reset. The recommended pattern is to push { ecommerce: null } immediately before every commerce event, to clear the previous one. It therefore precedes every single purchase and add-to-cart — so anything picking the next push after your click catches the clearing rather than the thing itself.
  4. gtag setup calls. gtag('js', new Date()), gtag('config', 'G-…') and gtag('set', …) all land in the dataLayer. Treat them as events and you end up offering a Custom Event trigger named js — one that will never fire on purpose.

The naming trap in gtag

A site using gtag('event', 'add_to_cart', {…}) puts the string event in the dataLayer's event field, because that is the gtag command. The name you actually want — add_to_cart — is the second argument.

Read the raw field and every gtag-based site looks like it fires one event called "event". This is worth knowing even by hand: when the dataLayer in your console shows event: "event", look at the arguments, not the key.

Which parameters to take

Once you have the right push, the question is which of its fields become variables. Two rules save most of the thinking:

And if you switch to a different candidate, drop the ticks. They described the shape of the other event; carried across, they name paths the new one does not have.

Keep them, then export once

Picking one event is rarely the whole job. A funnel is four or five of them, and walking it once while keeping each catch beats going back for them one at a time — the kept set survives while you move to the next page.

What comes out at the end is a single JSON file, and it is worth being exact about what kind. It is a GTM container export, not a dump of your events: a Data Layer Variable per path, a Custom Event trigger per event, and a tag wired to each. You import it into GTM, not back into the extension — there is no loading that file to restore a session. What that file has to contain is a guide of its own, including the two fields that make GTM refuse the whole import.

A routine

  1. Arm the picker before you interact, not after. The push you want has already happened otherwise.
  2. Do one thing. One click, then stop, so the candidate list describes that click and not three.
  3. Read the alternatives before accepting the catch. If the first one is the theme's own event, the one you want is usually the next.
  4. Check the event name against what the tag will listen for — including capitalisation, which is a different event to GTM.
  5. Repeat through the funnel, keeping each one, before you go near the container.

Related guides

Try it on your own site

Tag Master is free, needs no account, and collects no data.

Add to Chrome — Free