E-commerce platform

Server-Side Tracking for VTEX

Stop losing conversions to iOS ITP, short-lived cookies, and ad-blockers. TrakSolv hosts a first-party server-side GTM container for your VTEX store and forwards clean, deduplicated conversions to GA4, Meta CAPI, Google Ads and more. Live in minutes, flat monthly pricing.

No credit card to startFlat monthly pricingNative VTEX dataLayerGA4 · Meta CAPI · Google Ads
Why it matters for VTEX

The pixel alone is leaking your data.

Browser-side tracking on VTEX loses a growing share of conversions. Here's what moving to a server-side setup fixes.

Recover conversions lost to ITP & ad-blockers

On VTEX, browser-side pixels are throttled by Safari/Firefox ITP, capped 7-day cookies, and blocked outright by ad-blockers and consent walls. Server-side tracking moves the measurement off the browser, so purchases and add-to-carts that the pixel silently drops are recovered and reported.

First-party data, served from your own domain

TrakSolv hosts your Google Tag Manager server container on a subdomain of your VTEX site. Requests come from a first-party context — they survive 3rd-party cookie deprecation, last far longer than client-side cookies, and look like your own traffic, not a tracker.

Clean, deduplicated conversions to every ad platform

The VTEX dataLayer fires every GA4 enhanced-ecommerce event with a stable event_id, so your server-side container can forward purchases and add-to-carts to GA4, Meta CAPI, Google Ads Enhanced Conversions, TikTok and more — deduplicated against the browser pixel, with higher match quality.

Step by step

How to set up server-side tracking on VTEX

Paste the TrakSolv loader and the VTEX dataLayer snippet into your store's custom-code area, save, and you're done. Every step below has the exact snippet with a copy button.

Install guide

How to install on VTEX

This is your install. Every step below has its exact snippet with a Copy button — go step by step. The Loader card above and DataLayer card below are reference copies of the same snippets.

  1. 1

    Pick your install path

    Navigate

    VTEX Admin → Storefront (or Account Settings → CMS for legacy stores)

    VTEX IO storefronts: paste in a Custom Script slot on the home / category / product templates (Site Editor → custom script block). Legacy CMS / Portal: Admin → Account Settings → CMS → Files → global Footer Scripts.

  2. 2

    Loader — head half

    Loader • Head

    Header / pre-body Custom Script slot → paste the Loader Head snippet

  3. 3

    Loader — body half + DataLayer

    Loader • Body

    Footer / post-body Custom Script slot → paste the Loader Body snippet FIRST

  4. 4

    DataLayer snippet

    DataLayer

    Same Footer Custom Script slot → append the DataLayer right after the Body

    Subscribes to all VTEX window events. Works on both VTEX IO storefronts and legacy CMS. NOTE: VTEX's checkout pages run in a separate iframe context — for in-checkout events also paste this in Account Settings → Checkout → Code → checkout6-custom.js (or the GTM equivalent).

    HTML
    <!-- Traksolv · VTEX DataLayer — paste in CMS Footer scripts or Custom Script slot -->
    <script>
    (function (w) {
      w.dataLayer = w.dataLayer || [];
      var DEBUG = false;
      try {
        var q = new URLSearchParams(location.search);
        if (q.get('tcDebug') === '1') { DEBUG = true; try { localStorage.setItem('tcDebug', '1'); } catch (e) {} }
        else if (q.get('tcDebug') === '0') { DEBUG = false; try { localStorage.removeItem('tcDebug'); } catch (e) {} }
        else { try { if (localStorage.getItem('tcDebug') === '1') DEBUG = true; } catch (e) {} }
      } catch (e) {}
      w.tcDebug = DEBUG;
      if (DEBUG && w.console && w.console.log) {
        try { w.console.log('%c[Traksolv]%c dataLayer debug ON — every push will log here. Disable with ?tcDebug=0', 'color:#22c55e;font-weight:600;background:#0a1f0c;padding:2px 6px;border-radius:3px', ''); } catch (e) {}
      }
      function log() {
        if (!DEBUG || !w.console || !w.console.log) return;
        try { w.console.log.apply(w.console, ['[Traksolv]'].concat([].slice.call(arguments))); } catch (e) {}
      }
      function push(eventName, eventId, params) {
        try {
          if (params && params.ecommerce !== undefined) w.dataLayer.push({ ecommerce: null });
          var ev = { event: eventName, event_id: eventName + '.' + eventId };
          if (params) for (var k in params) if (Object.prototype.hasOwnProperty.call(params, k)) ev[k] = params[k];
          w.dataLayer.push(ev);
          log('push ' + eventName, ev);
        } catch (e) {}
      }
      function once(key) {
        try { if (sessionStorage.getItem(key)) return false; sessionStorage.setItem(key, '1'); return true; }
        catch (e) { return true; }
      }
    
      w.tcFirePurchase = function (o) {
        try {
          if (!o || !o.orderId) return;
          if (!once('tc_purchase_' + o.orderId)) return;
          push('purchase', String(o.orderId), {
            ecommerce: {
              transaction_id: String(o.orderId),
              value:    Number(o.value) || 0,
              currency: o.currency || 'BRL',
              items:    Array.isArray(o.items) ? o.items : []
            }
          });
        } catch (e) {}
      };
    
      // VTEX product → GA4 item
      function vtexProductToItem(p, i) {
        if (!p) return null;
        var sku = p.selectedSku || (Array.isArray(p.skus) && p.skus[0]) || p.sku || {};
        var cats = p.categories || p.categoryTree || [];
        return {
          item_id:       String(sku.itemId || p.productId || p.id || ''),
          item_name:     p.productName || p.name || sku.name || '',
          item_brand:    p.brand || undefined,
          item_category: typeof cats[0] === 'string' ? cats[0].replace(/^\/|\/$/g, '').split('/').pop() : (cats[0] && cats[0].name) || undefined,
          item_variant:  sku.name || sku.variant || undefined,
          item_sku:      sku.referenceId && (sku.referenceId[0] && sku.referenceId[0].Value) || sku.ean || undefined,
          price:         Number((sku.price != null ? sku.price : p.price)) / 100 || Number(p.priceValue) || 0,
          quantity:      Number(p.quantity) || 1,
          index:         typeof p.position === 'number' ? p.position : (typeof i === 'number' ? i : undefined)
        };
      }
      function vtexProductsToItems(arr) { return (arr || []).map(function (p, i) { return vtexProductToItem(p, i); }).filter(Boolean); }
    
      // VTEX orderFormItems → GA4 items (orderPlaced payload uses different shape)
      function vtexOrderItemsToItems(items, i) {
        return (items || []).map(function (it, idx) {
          return {
            item_id:       String(it.id || it.skuId || it.productId || ''),
            item_name:     it.name || it.productName || '',
            item_brand:    it.additionalInfo && it.additionalInfo.brandName || undefined,
            item_category: it.productCategories && Object.values(it.productCategories)[0] || undefined,
            item_variant:  it.skuName || undefined,
            item_sku:      it.skuRefId || undefined,
            price:         (Number(it.sellingPrice) || Number(it.price) || 0) / 100,
            quantity:      Number(it.quantity) || 1,
            index:         typeof i === 'number' ? i : idx
          };
        });
      }
    
      // Centralised subscribe — every VTEX event is dispatched on window.
      function on(name, cb) {
        try { w.addEventListener(name, function (e) { try { cb(e && e.detail ? e.detail : e); } catch (err) {} }); } catch (e) {}
      }
    
      on('vtex:productView', function (data) {
        var p = data && data.product;
        if (!p) return;
        var pid = p.productId || p.id;
        if (!pid || !once('tc_view_item_' + pid)) return;
        var item = vtexProductToItem(p);
        push('view_item', String(pid), {
          ecommerce: { currency: data.currency || (item && item.currency) || 'BRL', value: item ? item.price : 0, items: item ? [item] : [] }
        });
      });
    
      on('vtex:productImpression', function (data) {
        var list = data && (data.list || data.impressions || (data.product ? [data.product] : []));
        if (!list || !list.length) return;
        var key = String(data.list || location.pathname);
        if (!once('tc_view_item_list_' + key)) return;
        push('view_item_list', key, {
          ecommerce: { item_list_id: key, item_list_name: data.listName || key, items: vtexProductsToItems(list) }
        });
      });
    
      on('vtex:productClick', function (data) {
        var p = data && data.product;
        if (!p) return;
        var pid = p.productId || p.id || 'item';
        var item = vtexProductToItem(p);
        push('select_item', String(pid) + '.' + Date.now(), {
          ecommerce: { item_list_id: data.list || location.pathname, items: item ? [item] : [] }
        });
      });
    
      on('vtex:addToCart', function (data) {
        var items = vtexProductsToItems(data && data.items);
        if (!items.length) return;
        var first = items[0];
        push('add_to_cart', String(first.item_id) + '.' + Date.now(), {
          ecommerce: { currency: data.currency || 'BRL', value: items.reduce(function (s, i) { return s + (i.price || 0) * (i.quantity || 1); }, 0), items: items }
        });
      });
    
      on('vtex:removeFromCart', function (data) {
        var items = vtexProductsToItems(data && data.items);
        if (!items.length) return;
        var first = items[0];
        push('remove_from_cart', String(first.item_id) + '.' + Date.now(), {
          ecommerce: { currency: data.currency || 'BRL', value: items.reduce(function (s, i) { return s + (i.price || 0) * (i.quantity || 1); }, 0), items: items }
        });
      });
    
      on('vtex:cartLoaded', function (data) {
        var items = vtexProductsToItems(data && data.items);
        if (!items.length) return;
        var key = String((data && data.orderFormId) || 'cart');
        if (!once('tc_view_cart_' + key)) return;
        push('view_cart', key, {
          ecommerce: { currency: data.currency || 'BRL', value: items.reduce(function (s, i) { return s + (i.price || 0) * (i.quantity || 1); }, 0), items: items }
        });
      });
    
      on('vtex:beginCheckout', function (data) {
        var items = vtexProductsToItems(data && data.items);
        if (!items.length) return;
        var key = String((data && (data.orderFormId || data.id)) || 'co');
        if (!once('tc_begin_checkout_' + key)) return;
        push('begin_checkout', key, {
          ecommerce: { currency: data.currency || 'BRL', value: items.reduce(function (s, i) { return s + (i.price || 0) * (i.quantity || 1); }, 0), items: items }
        });
      });
    
      on('vtex:addShippingInfo', function (data) {
        var items = vtexProductsToItems(data && data.items);
        push('add_shipping_info', String(Date.now()), {
          ecommerce: {
            currency:       data.currency || 'BRL',
            shipping_tier:  (data && (data.shippingTier || data.shipping_tier)) || undefined,
            items:          items
          }
        });
      });
    
      on('vtex:addPaymentInfo', function (data) {
        var items = vtexProductsToItems(data && data.items);
        push('add_payment_info', String(Date.now()), {
          ecommerce: {
            currency:     data.currency || 'BRL',
            payment_type: (data && (data.paymentType || data.payment_type)) || undefined,
            items:        items
          }
        });
      });
    
      on('vtex:orderPlaced', function (data) {
        var orderGroup = (data && (data.transactionId || data.orderGroup || data.orderId)) || '';
        var orders = (data && data.orders) || [data];
        if (!orderGroup) return;
        if (!once('tc_purchase_' + orderGroup)) return;
        var totalValue = 0, totalTax = 0, totalShipping = 0, totalDiscount = 0, allItems = [];
        for (var i = 0; i < orders.length; i++) {
          var o = orders[i];
          totalValue    += Number(o.value || o.transactionTotal || 0) / 100;
          totalTax      += Number(o.transactionTax || o.tax || 0) / 100;
          totalShipping += Number(o.transactionShipping || o.shipping || 0) / 100;
          totalDiscount += Number(o.transactionDiscounts || o.discount || 0) / 100;
          allItems = allItems.concat(vtexOrderItemsToItems(o.transactionProducts || o.items));
        }
        push('purchase', String(orderGroup), {
          ecommerce: {
            transaction_id: String(orderGroup),
            affiliation:    (data && data.affiliation) || 'VTEX',
            value:          totalValue,
            tax:            totalTax || undefined,
            shipping:       totalShipping || undefined,
            discount:       totalDiscount || undefined,
            coupon:         (data && data.coupon) || undefined,
            currency:       (data && data.currency) || 'BRL',
            items:          allItems
          }
        });
      });
    
      on('vtex:userData', function (data) {
        var u = (data && data.user) || data || {};
        if (!u || !u.id) return;
        if (!once('tc_identified_' + u.id)) return;
        push('tc_user_identified', String(u.id), {
          user_id:    String(u.id),
          user_email: u.email || undefined,
          user_first_name: u.firstName || undefined,
          user_last_name:  u.lastName  || undefined
        });
      });
    
      on('vtex:search', function (data) {
        push('search', String(Date.now()), { search_term: (data && data.term) || '' });
      });
    
      on('vtex:refund', function (data) {
        var orderId = data && (data.transactionId || data.orderId);
        if (!orderId) return;
        push('refund', String(orderId), {
          ecommerce: { transaction_id: String(orderId), currency: data.currency || 'BRL', value: Number(data.value || 0) / 100 }
        });
      });
    
      on('vtex:promoView', function (data) {
        push('view_promotion', String((data && data.id) || Date.now()), {
          ecommerce: { promotion_id: (data && data.id) || undefined, promotion_name: (data && data.name) || undefined }
        });
      });
      on('vtex:promotionClick', function (data) {
        push('select_promotion', String((data && data.id) || Date.now()), {
          ecommerce: { promotion_id: (data && data.id) || undefined, promotion_name: (data && data.name) || undefined }
        });
      });
      on('vtex:login',  function () { push('login',   String(Date.now()), { method: 'vtex' }); });
      on('vtex:signUp', function () { push('sign_up', String(Date.now()), { method: 'vtex' }); });
    
      on('vtex:addToWishlist', function (data) {
        var items = vtexProductsToItems(data && data.items);
        if (!items.length) return;
        push('add_to_wishlist', String(items[0].item_id) + '.' + Date.now(), {
          ecommerce: { currency: data.currency || 'BRL', items: items }
        });
      });
    
      // Page-type detection for the enrichment block.
      function pageType() {
        var path = (location.pathname || '').toLowerCase();
        if (/checkout\/orderplaced|finishorder|orderform\/\?orderid/i.test(path + location.search)) return 'order';
        if (/checkout/i.test(path)) return 'checkout';
        if (/cart/i.test(path)) return 'cart';
        if (/\/p\b/.test(path) || /productname/i.test(path)) return 'product';
        return 'other';
      }
      w.tcPageType = pageType;
    })(window);
    </script>
    <!-- End Traksolv VTEX DataLayer -->
    
    <!-- Traksolv · DataLayer enrichment — customer lifecycle + remarketing + attribution -->
    <script>
    (function (w, d) {
      function readLT() {
        try {
          var raw = localStorage.getItem('tc_lifetime');
          var p = raw ? JSON.parse(raw) : null;
          return {
            orderCount:    (p && p.orderCount)    || 0,
            lifetimeValue: (p && p.lifetimeValue) || 0,
            firstOrderTs:  (p && p.firstOrderTs)  || null,
            lastOrderTs:   (p && p.lastOrderTs)   || null,
            lastOrderId:   (p && p.lastOrderId)   || null
          };
        } catch (e) {
          return { orderCount: 0, lifetimeValue: 0, firstOrderTs: null, lastOrderTs: null, lastOrderId: null };
        }
      }
      function writeLT(lt) {
        try { localStorage.setItem('tc_lifetime', JSON.stringify(lt)); } catch (e) {}
      }
      function tier(v) {
        if (v >= 1000) return 'vip';
        if (v >= 250)  return 'mid';
        if (v > 0)     return 'low';
        return 'guest';
      }
      function readCookie(n) {
        try {
          var m = d.cookie.match(new RegExp('(^|; )' + n + '=([^;]+)'));
          return m ? decodeURIComponent(m[2]) : null;
        } catch (e) { return null; }
      }
      function readAttr() {
        try { var r = readCookie('_tc_attr'); return r ? JSON.parse(r) : null; } catch (e) { return null; }
      }
    
      w.tcReadLifetime    = readLT;
      w.tcCustomerTier    = function (v) { return tier(v != null ? v : readLT().lifetimeValue); };
      w.tcReadAttribution = readAttr;
    
      // ── Wrap tcFirePurchase to add customer-lifecycle + attribution ──
      // before the underlying snippet pushes the purchase event. Idempotent
      // per orderId, so customer refreshing the thank-you page doesn't
      // inflate their lifetime counters.
      var orig = w.tcFirePurchase;
      if (typeof orig === 'function') {
        w.tcFirePurchase = function (o) {
          try {
            if (!o || !o.orderId) return orig.apply(this, arguments);
            var lt = readLT();
            var firstFire = lt.lastOrderId !== String(o.orderId);
            var orderCount    = firstFire ? lt.orderCount + 1 : lt.orderCount;
            var lifetimeValue = firstFire ? lt.lifetimeValue + (o.value || 0) : lt.lifetimeValue;
            var firstOrderTs  = lt.firstOrderTs || Date.now();
            var newCustomer   = orderCount === 1;
            var daysSinceFirst = Math.floor((Date.now() - firstOrderTs) / 86400000);
    
            if (firstFire) {
              writeLT({
                orderCount:    orderCount,
                lifetimeValue: lifetimeValue,
                firstOrderTs:  firstOrderTs,
                lastOrderTs:   Date.now(),
                lastOrderId:   String(o.orderId)
              });
            }
    
            var attr = readAttr();
            // Build the enriched order. Preserve every original field; add
            // customer + attribution on top.
            var enriched = {};
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) enriched[k] = o[k];
            enriched.new_customer            = newCustomer;
            enriched.customer_type           = newCustomer ? 'new' : 'returning';
            enriched.customer_status         = 'customer';
            enriched.customer_lifetime_value = Math.round(lifetimeValue * 100) / 100;
            enriched.customer_order_count    = orderCount;
            enriched.customer_aov            = orderCount > 0 ? Math.round((lifetimeValue / orderCount) * 100) / 100 : 0;
            enriched.purchase_number         = orderCount;
            enriched.days_since_first_order  = daysSinceFirst;
            enriched.value_tier              = tier(lifetimeValue);
            if (attr) enriched.attribution = {
              landing:   attr.u   || null,
              referrer:  attr.r   || null,
              utm:       attr.utm || null,
              click_ids: attr.cid || null
            };
            return orig.call(this, enriched);
          } catch (e) {
            try { return orig.apply(this, arguments); } catch (e2) {}
          }
        };
      }
    
      // ── tc_visitor_context — emits visitor lifecycle + remarketing on
      //    every page-view. GTM / GA4 audience triggers + Google Ads
      //    dynamic remarketing tag read these.
      function visitorContext() {
        try {
          var lt = readLT();
          var attr = readAttr();
          var pageType = (typeof w.tcPageType === 'function') ? (w.tcPageType() || 'other') : 'other';
          w.dataLayer = w.dataLayer || [];
          w.dataLayer.push({
            event:                   'tc_visitor_context',
            event_id:                'tc_visitor_context.' + Date.now() + '.' + Math.random().toString(36).slice(2, 6),
            customer_status:         lt.orderCount > 0 ? 'returning_customer' : 'guest',
            customer_type:           lt.orderCount > 0 ? 'returning' : 'guest',
            value_tier:              tier(lt.lifetimeValue),
            customer_lifetime_value: Math.round(lt.lifetimeValue * 100) / 100,
            customer_order_count:    lt.orderCount,
            days_since_first_order:  lt.firstOrderTs ? Math.floor((Date.now() - lt.firstOrderTs) / 86400000) : null,
            ecomm_pagetype:          pageType,
            attribution: attr ? {
              landing:   attr.u   || null,
              referrer:  attr.r   || null,
              utm:       attr.utm || null,
              click_ids: attr.cid || null
            } : null
          });
        } catch (e) {}
      }
      if (d.readyState === 'loading') d.addEventListener('DOMContentLoaded', visitorContext);
      else visitorContext();
    })(window, document);
    </script>
    <!-- End Traksolv enrichment -->
  5. 5

    Save and publish

    Save

    Save (each slot) → Publish (IO: deploy the workspace; CMS: file is live on save)

The loader Head + Body snippets are generated for your container inside the TrakSolv dashboard. Create a free account to grab them, or see the full how-it-works walkthrough.

FAQ

Server-side tracking for VTEX, answered

Does server-side tracking work with VTEX?

Yes. TrakSolv works with VTEX via a lightweight loader snippet plus a VTEX-specific dataLayer that fires every GA4 enhanced-ecommerce event. You paste it once in VTEX's custom-code area and conversions start flowing through your own server-side GTM container.

How do I install TrakSolv on VTEX?

Add the TrakSolv loader (head + body) and the VTEX dataLayer snippet to your store's custom-code settings, then save. The full step-by-step is on this page. Most VTEX merchants are live in a few minutes — no developer required.

What can I track server-side on VTEX?

Page views, product views, purchases and add-to-carts, begin-checkout and more — every standard GA4 enhanced-ecommerce event, forwarded server-side to GA4, Meta CAPI, Google Ads and other destinations with deduplication.

How much does server-side tracking for VTEX cost?

TrakSolv uses flat monthly pricing — one event sent to many destinations still counts as one event, and paid plans never auto-pause at quota. You can start free and go live in minutes.

Recover your VTEX conversions — start free.

Spin up a first-party server-side GTM container for VTEX and watch your match quality climb. No credit card, live in minutes.

WhatsApp
Server-Side Tracking for VTEX — TrakSolv | Traksolv