Don't have one? Create one ↗
How web tracking really works

Lesson 4 of 7

The DataLayer As The Bridge

Tags should not have to dig through the page's HTML to find values. The dataLayer is the clean bridge: your site announces what happened, and GTM picks it up.

Your sitepushdataLayerqueueGTMlistens

Order is what trips people up. The dataLayer is a queue: anything pushed before GTM loads is still processed, but a Data Layer Variable only sees values that were present at the moment its tag fired. That is why page context is pushed early and why a value pushed after a tag fires will read as undefined.

// available to the very first event
dataLayer = [{ user_type: "member" }];

// announced as it happens
dataLayer.push({ event: "add_to_cart", value: 29 });

Key takeaway

The dataLayer decouples your site from your tags. Push context early, and remember a variable only sees what existed when its tag fired.