# Data layer

> The data layer is a JavaScript array that passes page information to Google Tag Manager. How push works, the event key, common mistakes and a console check.

Canonical: https://scaplet.com/glossary/data-layer

Glossary Glossary · Measurement

The data layer is a JavaScript array that passes page information to Google Tag Manager. How push works, the event key, common mistakes and a console check.

2 min

read

1

sources

Oct 29, 2026

updated

Scaplet Editorial Team

author

In one line

The data layer is a JavaScript array, window.dataLayer, that holds information passed from your site to Google Tag Manager or gtag.js. Tags can fire on events you push or on variable values you set, so the page and the tags stay decoupled.

30-second check

## Is this costing your site traffic?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Fdata-layer%20(%22Data%20layer%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Fdata-layer%20(%22Data%20layer%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Fdata-layer%20(%22Data%20layer%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fglossary%2Fdata-layer%20(%22Data%20layer%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

## At a glance

5 facts from the sources below

window.dataLayer (an array)

Object

dataLayer.push({...})

Add data

event

Event key

Case-sensitive

Case

One data layer

Per page

_01_At a glance

## Anatomy of a push

Part

### `window.dataLayer = window.dataLayer || [];`

Job

Creates the array if it does not exist. Place it near the top of the page, before the container [snippet](/glossary/snippet)

Part

### `'event': 'sign_up_click'`

Job

The key event-based triggers listen for. A Custom Event trigger matches the name

Part

### `'plan_name': 'starter'`

Job

A variable. Pushing a name that already exists replaces its value

Part

### `push`

Job

Adds a message to the queue; [Tag Manager](/glossary/google-tag-manager) processes the queue first in, first out

Declare, then push

```
window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event': 'sign_up_click', 'plan_name': 'starter' });
```

Names here are examples. Use one variable name for one concept on every page, as Google advises.

_02_At a glance

## Rules that cause most bugs

Rule

### Never overwrite or re-assign `window.dataLayer`

What goes wrong if you break it

Google says not to do it, because reassigning replaces the array the container reads

Rule

### `dataLayer` is case-sensitive

What goes wrong if you break it

`datalayer.push` fails

Rule

### Quote variable names

What goes wrong if you break it

Unquoted names break the push

Rule

### Variables last for the current page only

What goes wrong if you break it

Push again on each page load

Rule

### Push above the container snippet to have data when the container loads

What goes wrong if you break it

Later pushes arrive after the container has loaded

Rule

### Use one data layer per page

What goes wrong if you break it

Google's guidance is one data layer per page

**Pushes from custom code are queued**Google notes that pushes from page code, custom templates or Custom HTML tags are processed after pending messages, so a value may not be ready for the next event. Attach an event name and use a Custom Event trigger.

_03_Your call

## Data layer or tag settings?

If this fits

### Use the data layer when

- The value exists in page code or your backend, such as plan or logged-in status
- Several tags need the same value
- You want to rename a front-end element without breaking tracking

Or

### Skip it when

- The value is already in the URL or a cookie and a built-in variable reads it
- One tag needs a fixed value you can type into the tag

**Consent and gtag code**Google says not to put gtag.js code or consent settings in Custom HTML tags. Use the native tag templates and the Consent APIs. See [consent mode](/glossary/consent-mode).

_04_Check it

## Check it in 2 minutes

Open DevTools on a page with a container, go to the Console and read the array. It should list the entries your page and container have pushed, in order.

If `window.dataLayer` is undefined, the array was never declared or the container is not on that page.

Console check

```
window.dataLayer // then push a test event and watch it in GTM Preview: window.dataLayer.push({ event: 'console_test' });
```

Questions

## Asked a lot.

2 questions people ask next, answered from the sources on this page.

_01_ What is the difference between the data layer and Google Tag Manager?

The data layer is the array that holds your data. Tag Manager is the container that reads it and fires tags.

_02_ Can I rename the data layer?

Yes. Google says you can rename it by changing the snippet parameter, and for gtag.js by adding the l query parameter.

Sources · 1

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- google.com

1. 01 [The data layer](https://developers.google.com/tag-platform/tag-manager/datalayer) developers.google.com · checked 2026-11-01

## Keep learning

[All glossary](/glossary)

[Learn Custom dimensions Measurement](/glossary/custom-dimensions) [Related Google Tag Manager Measurement](/glossary/google-tag-manager) [Read next Server-side tagging Measurement](/glossary/server-side-tagging) [Do Run a free site audit Free, about two minutes](/site-audit)

More in Measurement
[CAC payback](/glossary/cac-payback) [Churn rate](/glossary/churn-rate) [Click-through rate](/glossary/click-through-rate) [Consent mode](/glossary/consent-mode) [Conversion rate](/glossary/conversion-rate) [Conversion rate optimization (CRO)](/glossary/conversion-rate-optimization) [Conversion tracking](/glossary/conversion-tracking) [Cross-domain tracking](/glossary/cross-domain-tracking) [CSAT (customer satisfaction score)](/glossary/csat) [Custom dimensions](/glossary/custom-dimensions) [Customer acquisition cost (CAC)](/glossary/customer-acquisition-cost) [Dark social](/glossary/dark-social) [Data layer](/glossary/data-layer) [Data retention](/glossary/data-retention) [Data streams](/glossary/data-streams) [Data thresholds](/glossary/data-thresholds) [Data-driven attribution](/glossary/data-driven-attribution) [Default channel group](/glossary/default-channel-group) [Direct traffic](/glossary/direct-traffic) [Dwell time](/glossary/dwell-time) [Engagement rate](/glossary/engagement-rate) [GA4 audiences](/glossary/ga4-audiences) [GA4 DebugView](/glossary/ga4-debugview) [GA4 events](/glossary/ga4-events)

Terms on this page
[Search snippet](/glossary/snippet) [Google Tag Manager](/glossary/google-tag-manager) [Consent mode](/glossary/consent-mode)

Free · 2 minutes

## Know the term. _Now check your site._

The free audit reads robots.txt, sitemaps, status codes, canonicals, redirects and structured data.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **+212%** organic clicks in 90 days Ledgerly
