Don't have one? Create one ↗
Measurement planning & the dataLayer

Lesson 5 of 7

Designing The DataLayer Schema

The dataLayer is the contract between your website and your tags. Design it deliberately so tags can read clean, predictable values rather than scraping the page.

Two kinds of push

Page context is set on load and describes the page or user (page type, login state, plan). Push it before the GTM snippet so it is ready for the first event. Interaction events are pushed as things happen, each with an event name and its own parameters.

// page context, before the GTM snippet
dataLayer = [{ page_type: "product", logged_in: false }];

// interaction event, pushed later
dataLayer.push({
  event: "add_to_cart",
  ecommerce: { currency: "USD", value: 29, items: [/* ... */] }
});

Keep names consistent with your plan, group related values into objects (like ecommerce), and avoid pushing raw, presentation-formatted strings when a clean number or id would do.

Key takeaway

Separate page context from interaction events, push context early, and keep the structure predictable so tags never have to guess.