Skip to content
Tracking and technical

What is a data layer?

3 min read · Updated · By the Reveata team

Short answerA data layer is a JavaScript object on your web pages, most often Google Tag Manager's window.dataLayer array, that holds structured details about the page and what the visitor does, so tags can read clean values instead of scraping them from the page.

A stack of colorful handmade paper sheets with rough edges on a light surface
Photo by Pierre Bamin on Unsplash

Tags need information: which plan someone chose, what the order was worth, whether the person is signed in. Without a data layer, each tag digs that information out of the page itself, reading a price from a heading or a product name from a button. When the design changes, those tags break. A data layer separates the two: your site writes the facts into one agreed place, and every tag reads them from there.

How Google Tag Manager's data layer works

Google's data layer documentation (opens in a new tab) describes it as an object that Tag Manager and gtag.js use to pass information to tags. It is created once, as high on the page as possible, without overwriting any existing one:

js
window.dataLayer = window.dataLayer || [];

Your code then pushes facts and events into it:

js
dataLayer.push({ event: 'signup', plan: 'pro' });

In Tag Manager, a Custom Event trigger can listen for signup, and Data Layer Variables can read plan. Values pushed before the container snippet are available as soon as it loads.

Google's own cautions are worth repeating:

  • The name is case-sensitive: dataLayer, not datalayer.
  • Use the same key for the same thing on every page (visitorType everywhere, not visitor_type on some pages).
  • Add with push(). Assigning a new array discards what was there.
  • Keep one data layer per page.

Designing a data layer

Write down the keys before anyone writes code. A simple plan names each event (signup, checkout_started, purchase), the properties each one carries, and who is responsible for pushing it. Treat it like an interface between your developers and whoever manages tags. Many teams keep the plan in a short shared document.

Using a data layer with Reveata

Reveata does not need a data layer. Its script records page views on its own, and you send goals with reveata('goal', …) or HTML attributes (Custom goals).

If your site already has a data layer and Google Tag Manager, you can reuse it. The Reveata Analytics tag template loads the script, and further tags of the same template can Track a goal or Identify the visitor from any trigger. For identify, fill the user id, and optionally email and name, from your data layer variables (Install with Google Tag Manager). A signup event in the data layer can then fire a Reveata signup goal with the plan as a property.

Pitfalls

  • Personal data. A data layer is readable by every tag on the page, including third-party ones. Do not push names, emails or other personal data unless each tag that reads it is allowed to have it.
  • Timing. A push after a tag fires does not reach that tag. Push the facts before the event that triggers it.
  • Drift. Data layers decay when nobody owns them. Review them when you change checkout or sign-up flows.

Frequently asked questions

Is the data layer only for Google Tag Manager?

The dataLayer name comes from Google's tools, but the idea is general. Other tag managers and analytics tools use their own objects for the same purpose.

Does a data layer send data anywhere by itself?

No. It is just an object in the page. Nothing leaves the browser until a tag reads from it and sends something.

Do I need a developer to set up a data layer?

Usually, yes. The values come from your site's code, such as the plan in a checkout. Once they are pushed, someone without coding experience can build the tags in Tag Manager.

See it with your own numbersReveata ties every visit and sale to the source that brought it. Add your website in a minute.
Get started
Was this page useful?
GlossaryWhat is a tag manager?A tag manager is a tool, such as Google Tag Manager, that you install once on your website and then use to add, change and fire analytics and marketing scripts (tags) from a web dashboard instead of editing your site's code each time.GlossaryWhat is a custom event in analytics?A custom event is an action you define and send to your analytics tool yourself, such as signup, start_trial or download_pdf, so it can be counted, compared by traffic source and used as a goal or funnel step.GlossaryWhat are event properties?Event properties are key–value details attached to an analytics event, such as the plan chosen or the button clicked on a signup event, so you can break one event down by those details instead of creating a separate event for every variation.GlossaryWhat are Core Web Vitals?Core Web Vitals are three measurements Google uses to describe a page's real-world user experience, namely Largest Contentful Paint (loading), Interaction to Next Paint (responsiveness) and Cumulative Layout Shift (visual stability).GlossaryWhat is a canonical URL?A canonical URL is the one preferred address you want search engines to index and show for a page whose content is reachable at several URLs, usually declared with a rel="canonical" link in the page's head.GlossaryWhat is a Content Security Policy (CSP)?A Content Security Policy (CSP) is a set of rules a website sends to the browser, usually in a Content-Security-Policy header, listing which sources of scripts, styles, images and network connections the page is allowed to use, so injected or unexpected code is blocked.