tracking glossary

Data layer

A data layer is a JavaScript object, usually an array called dataLayer, that your site pushes structured events into so tags can read them consistently.

What is a data layer?

A data layer is a structured place on the page where your site describes what's happening, separate from the HTML. In Google Tag Manager it's a JavaScript array named window.dataLayer. Your code pushes objects into it, such as an event name and its details, and tags read from it.

The point is decoupling. Developers describe the event once, in a stable format, and marketing tags pick out what they need without scraping the page or depending on CSS selectors that change with every redesign.

What goes into it

A typical e-commerce data layer covers events like page_view, view_item, add_to_cart, begin_checkout and purchase. A purchase push carries the transaction id, value, currency and the items bought. Some sites also push user details, such as a logged-in user's id or hashed email.

Google's GA4 e-commerce event names have become a de facto standard, so many tools understand them out of the box.

Common data layer problems

Order of operations is the biggest one. A tag that reads the data layer before the purchase is pushed sees nothing, or sees a value of zero, which quietly corrupts revenue reporting. Inconsistent naming across pages, values sent as strings instead of numbers, and pushes that only happen on full page loads in single-page apps are also common.

These bugs rarely throw errors. The tag fires, the platform accepts the event, and the data is wrong.

How TracerKit handles it

TracerKit uses window.tracerkitLayer, a plain array with GTM-dataLayer-compatible push semantics and a typed e-commerce spec. Pushes made before the loader boots are processed on boot. TracerKit uses these events for triggers, verification and server-side forwarding.

See how TracerKit handles this: Data layer spec

Take a look →

questions

Asked and answered.

Do I need Google Tag Manager to use a data layer?+

No. A data layer is just a convention for structured events on the page. GTM popularized window.dataLayer, but other tag managers and analytics tools read their own or the same format.

Where should the data layer be defined?+

Initialize it before any tag that reads it, typically at the top of the page, with something like window.dataLayer = window.dataLayer || [].

Should I put personal data in the data layer?+

Be careful. Anything in the data layer is readable by every script on the page. If you include email or phone for matching, consider hashing it and limit which tags can use it.

related terms

Find out what your tags are really doing.

The free sweep shows every tracking script on a page, plus dead pixels, render-blocking tags and double-counting risks.