Definition
A data layer is a structured object (often on the page) that exposes events and attributes for analytics and tag managers.
Example
window.dataLayer.push({ event: "purchase", value: 120, currency: "USD" })
How to use it
- Define an event schema (event name + required fields) and keep it versioned.
- Use the data layer to avoid fragile DOM scraping in tags.
- Validate the data layer on key flows (checkout, signup, lead form).
Common mistakes
- Changing event names without updating tag rules.
- Sending personally identifiable data without consent or hashing.
Measured as
Measure Data Layer with a fixed attribution window, conversion event, and spend basis before comparing campaigns or creative tests.
Misused when
- Changing event names without updating tag rules.
- Sending personally identifiable data without consent or hashing.
Operator takeaway
- Define an event schema (event name + required fields) and keep it versioned.
- Use the data layer to avoid fragile DOM scraping in tags.
- Validate the data layer on key flows (checkout, signup, lead form).
- Use Data Layer only inside a stable attribution rule, conversion definition, and time window so campaign comparisons stay honest.
- If performance changes, check whether the metric moved for a real business reason or because the measurement setup changed underneath you.
Next decision
- Read UTM + GA4 attribution: practical tracking for paid ads (without lying to yourself) if the decision depends on interpretation, policy, or trade-offs beyond the raw formula.
- Decide which report owns Data Layer before comparing campaigns, channels, or creative tests.
Where to use this on MetricKit
Guides
- UTM + GA4 attribution: practical tracking for paid ads (without lying to yourself): A practical guide to UTMs and GA4: consistent source/medium/campaign tagging, conversion deduplication, and common attribution traps.