CDPGuidesSupport

Data Layer

Push events and values from your website code to the Ours Privacy Tag Manager with the standard dataLayer array.

Use this page to send events and values from your own code to the Tag Manager. The data layer is the standard window.dataLayer array, so existing Google Tag Manager pushes work unchanged.


Set up

Declare the array before the install tag so nothing pushed during page load is missed:

<script>
  window.dataLayer = window.dataLayer || [];
</script>
<!-- Tag Manager install tag follows -->

To use a different array name, change Data Layer Name in the container settings and declare that name instead.

The Tag Manager Settings panel open over the container overview, with the container Name and a Data Layer Name of dataLayer above Cancel and Save Changes buttons.

Push an event

window.dataLayer.push({
  event: 'purchase',
  transactionId: 'TXN-12345',
  value: 99.99,
});

A Custom Event trigger with Event Name purchase fires. Names are case-sensitive and must match exactly.

A push without an event key fires nothing. Its values are still stored for variables to read, which is useful for user or page context:

window.dataLayer.push({ userTier: 'premium' });

Read a value

Create a Data Layer variable with the key you want, for example value or user.profile.name, and use it as an event property or in a condition. For a one-off, reference the key directly as {{value}} without creating a variable. A variable you define wins over a data layer key with the same name.


Debug

Type window.dataLayer in the browser console to see everything pushed so far, or open Preview mode to see which events matched a trigger. If a trigger does not fire, check the event name's spelling and case first.


Next steps

  • Triggers: Custom Event and the other trigger types.
  • Variables: Data Layer variables and direct references.
  • Recipes: purchase and form tracking from the data layer.

How is this guide?

On this page