Data Layer Setup for Tag Manager

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Setting Up Data Layer for Tag Manager

Data Layer is a JavaScript array through which your site sends structured data to Google Tag Manager. GTM reads the Data Layer and uses this data in tags and triggers. Proper Data Layer architecture allows marketers to configure tags independently without code changes.

Initialization

Data Layer must be initialized before loading GTM:

<script>
window.dataLayer = window.dataLayer || [];
// Global page data
window.dataLayer.push({
    pageType:    '{{ $pageType }}',   // 'product', 'category', 'checkout', 'confirmation'
    siteLanguage: '{{ app()->getLocale() }}',
    {% if auth()->check() %}
    userId:      {{ auth()->id() }},
    userType:    '{{ auth()->user()->isB2B() ? "b2b" : "b2c" }}',
    userPlan:    '{{ auth()->user()->plan }}',
    {% endif %}
});
</script>
<!-- GTM snippet follows -->

Event Structure

Standard: each event contains event (name), thematic data, and optionally ecommerce:

// Good structure
dataLayer.push({
    event: 'product_add_to_cart',
    ecommerce: {
        currency: 'RUB',
        value:    product.price,
        items: [{
            item_id:       product.id,
            item_name:     product.name,
            item_brand:    product.brand,
            item_category: product.category,
            price:         product.price,
            quantity:      qty
        }]
    }
});

Clearing Previous ecommerce Data

Before each e-commerce event, clear previous data — otherwise GTM may mix them:

// Must do before each e-commerce event
dataLayer.push({ ecommerce: null });
dataLayer.push({
    event: 'view_item',
    ecommerce: { /* new data */ }
});

Setting Up Variables in GTM

In GTM, create variables of type "Data Layer Variable":

  • dlv - ecommerce.valueecommerce.value
  • dlv - ecommerce.itemsecommerce.items
  • dlv - userIduserId

These variables are used in GA4 tags to pass parameters.

Triggers for Events

In GTM, create a "Custom Event" trigger with the event name from Data Layer:

  • Trigger type: Custom Event
  • Event name: product_add_to_cart
  • Fire on: All Custom Events

Debugging

// View all Data Layer events in console
window.dataLayer.forEach((item, index) => {
    if (item.event) console.log(index, item.event, item);
});

GTM Preview Mode shows Data Layer in the right panel for each event — this is the main debugging tool.

Server-Side Data Layer (SSR)

With SSR (Next.js, Nuxt), data can be embedded in HTML on the server, eliminating undefined flashing:

// On server
const initialDataLayer = [
    {
        event:    'page_data',
        pageType: 'product',
        product: { id: product.id, name: product.name, price: product.price }
    }
];
<script>
window.dataLayer = <?= json_encode($initialDataLayer) ?>;
</script>

Setup time: 2–3 days for complete Data Layer architecture with documentation for marketers.