Building Custom Real-Time Tracking for Ads: Beyond Google Analytics

7 min read

By Tiago Basilio

The Problem with Off-the-Shelf Tracking

Most e-commerce sites rely on Google Analytics 4 and a handful of ad platform pixels (Meta, Google Ads, TikTok) dropped into the <head> tag. It works, until it doesn’t.

Here’s what typically goes wrong:

  • Ad blockers kill 30-40% of your client-side tracking. You’re optimizing campaigns based on incomplete data.
  • Cookie restrictions in Safari (ITP) and Firefox degrade attribution windows to 7 days or less. A customer who clicks your ad on Monday and buys on Thursday might not get attributed.
  • Consent management under GDPR/nDSG means a significant percentage of users decline tracking cookies. Those conversions vanish from your reports.
  • Data discrepancies between GA4, your ad platforms, and your actual order database become a constant headache. Everyone has different numbers, and nobody trusts any of them.
  • Latency: by the time GA4 processes and surfaces data, you’re looking at yesterday’s numbers. For high-spend campaigns, that delay costs real money.

I’ve seen this pattern across almost every e-commerce client I’ve worked with. The solution isn’t better configuration of existing tools, it’s building a tracking layer you actually control.


What Custom Real-Time Tracking Looks Like

The core idea is simple: instead of relying on client-side JavaScript to fire events to third-party services, you capture events server-side, enrich them with your own data, and distribute them to wherever they need to go, in real time.

The Architecture

A typical setup I build looks like this:

  1. Minimal client-side layer: A lightweight script captures user interactions (page views, add-to-cart, checkout steps) and sends them to your own endpoint. No third-party scripts blocking the page. No dependency on cookies for core tracking.

  2. Server-side event collection: A Laravel endpoint receives events, validates them, enriches them with server-side data (user ID, order value, product metadata), and pushes them into a queue.

  3. Real-time processing pipeline: Queued events are processed and dispatched to multiple destinations simultaneously:

    • Google Ads Conversion API
    • Meta Conversions API (CAPI)
    • GA4 Measurement Protocol
    • Your own database for custom dashboards
    • Any other ad platform’s server-side API
  4. Attribution engine: A custom attribution layer that matches ad clicks to conversions using first-party data (hashed email, user ID, click IDs) rather than relying on third-party cookies.

  5. Real-time dashboard: A simple internal dashboard showing conversions, revenue, and ROAS as they happen, not hours later.


Why Server-Side Changes Everything

Immune to Ad Blockers

When tracking happens on your server, ad blockers can’t touch it. The client sends a request to your own domain, indistinguishable from any other API call. The server then forwards the data to Google, Meta, or wherever it needs to go. Your data completeness goes from 60-70% to 95%+.

Better Attribution

Server-side tracking lets you use the ad platforms’ Conversion APIs, which accept hashed first-party identifiers (email, phone) alongside click IDs. This gives the platforms much stronger match rates compared to cookie-based pixel tracking, typically 80-95% match rates versus 50-60% with client-side pixels alone.

GDPR/nDSG Compliance Built In

With server-side tracking, you control exactly what data gets sent where. You can:

  • Respect consent preferences before forwarding any data
  • Hash or anonymize PII before it leaves your server
  • Keep a complete audit trail of what was sent to which platform
  • Strip data for users who withdraw consent

This is much harder to guarantee with client-side pixels, where scripts from Meta, Google, and others collect data directly from the browser.

Accurate Numbers

When your order database is the source of truth for conversions, not a JavaScript pixel that may or may not have fired, your numbers are reliable. No more reconciliation meetings where marketing, finance, and engineering all have different conversion counts.


Implementation: The Key Pieces

1. The Data Layer

I define a consistent event schema that every part of the system speaks. Every event has:

{
  event_name: "purchase",
  event_id: "evt_abc123",       // for deduplication
  timestamp: "2025-06-01T14:23:00Z",
  user: {
    id: "usr_456",
    email_hash: "sha256...",    // hashed, never plain text
    consent: ["analytics", "marketing"]
  },
  data: {
    order_id: "ORD-789",
    value: 249.90,
    currency: "CHF",
    items: [...]
  },
  attribution: {
    gclid: "...",               // Google click ID
    fbclid: "...",              // Meta click ID
    utm_source: "google",
    utm_medium: "cpc",
    utm_campaign: "summer-sale"
  }
}

This schema is used everywhere: client to server, server to queue, queue to destinations. One format, no translation errors.

2. Click ID Capture and Storage

When a user arrives from an ad, the landing page URL contains click identifiers (gclid for Google, fbclid for Meta, ttclid for TikTok, etc.). I capture these server-side on the first request and store them in the user’s session and database record.

This is critical because these click IDs are what allow the ad platforms to match your conversion data back to the specific ad click. If you lose the click ID, you lose the attribution.

3. Server-Side API Integration

Each ad platform has its own server-side conversion API:

  • Google Ads: Enhanced Conversions / Conversion API. Accepts hashed email, phone, and address alongside the gclid.
  • Meta: Conversions API (CAPI). Requires a pixel ID and access token. Accepts hashed PII and the fbclid.
  • GA4: Measurement Protocol. Sends events directly to your GA4 property without client-side JavaScript.
  • TikTok: Events API. Similar pattern to Meta CAPI.

Each gets its own dispatcher class. They all receive the same event object and transform it into the platform-specific format. If one API is down or slow, it doesn’t affect the others. They’re processed independently from the queue.

4. Deduplication

If you run both client-side and server-side tracking (which I recommend during the transition period), you need deduplication to avoid counting conversions twice. The event_id field solves this: both the client-side pixel and the server-side API send the same event ID, and the platform deduplicates automatically.

5. Real-Time Dashboard

I build a simple internal dashboard using Laravel + Inertia that queries the events table directly. No waiting for GA4 to process. You see:

  • Conversions in the last hour / today / this week
  • Revenue by channel (Google, Meta, organic, direct)
  • ROAS by campaign in real time
  • Funnel drop-off rates updated live

This doesn’t replace GA4 for deep analysis, but it gives you operational visibility that GA4 can’t.


What This Costs (In Effort)

Building custom tracking isn’t trivial. Here’s what’s involved:

  • Initial setup: 2-4 weeks for a standard e-commerce site, depending on how many ad platforms and how complex the funnel
  • Data layer definition: 2-3 days to define the event schema and map it to each platform’s requirements
  • Server-side API integration: 1-2 days per platform (Google, Meta, TikTok, etc.)
  • Dashboard: 3-5 days for a functional real-time dashboard
  • Testing and validation: 1 week of parallel running (client-side + server-side) to verify data matches

Ongoing maintenance is minimal, mostly updating API versions when platforms change their specs, which happens once or twice a year.


When You Don’t Need This

Not every business needs custom tracking. If you’re spending less than CHF 5,000/month on ads and your conversion volume is low, GA4 + standard pixels will get you 80% of the way there. The effort of building a custom pipeline isn’t justified.

But if you’re spending serious money on ads, operating in a consent-heavy market like Switzerland or the EU, or making decisions based on attribution data, the accuracy gap between standard and custom tracking translates directly into wasted ad spend.


Key Takeaways

  1. Client-side tracking is unreliable. Ad blockers, cookie restrictions, and consent management make pixel-based tracking increasingly incomplete
  2. Server-side is the foundation. Capture events on your server and forward them via each platform’s Conversion API
  3. First-party data is your edge. Hashed email, user IDs, and stored click IDs give you attribution that doesn’t depend on cookies
  4. Own your data. Store events in your own database so you’re not dependent on any single analytics platform
  5. Real-time matters. For high-spend campaigns, seeing conversions as they happen (not the next day) lets you react faster

Need help building a tracking pipeline for your e-commerce platform? Get in touch or visit tedbin.com.