Web Development

I Finally Understand Why Our Analytics Keep Lying to Us

A

Adil Sher

Author

Nov 26, 2026
4 min read
3 views
I Finally Understand Why Our Analytics Keep Lying to Us

Last month, our marketing team celebrated hitting 150 leads from a campaign. When I checked the CRM three days later, we had 47. I sat with that number for a while. Not 150 people submitted forms, 150 form submissions happened. Some were validation failures. Some were double-clicks. Some were network retries. We were measuring button presses, not actual leads. That conversation with our marketing director felt like a reckoning, and I realized I'd been building tracking systems completely backwards.

I've been writing JavaScript for nearly a decade now, and I've shipped analytics implementations on WordPress sites, React SPAs, and hybrid setups. Every single time, I treated tracking as an afterthought, a quick GTM snippet thrown onto the form submission handler, maybe a Redux dispatch if I was feeling thorough. But afterthoughts compound into lies, and lies destroy trust between engineering and marketing teams.

The Problem Isn't Data, It's the Contract

Here's what I finally grasped: a data layer without a written contract is just noise. You need an explicit agreement about what an event actually means. Does "lead generated" mean someone clicked a button? Filled out a form? Passed client-side validation? Or did the backend actually accept and store the submission?

I've seen teams where three different people answer this three different ways. The front-end dev thinks it's a form submission. The GTM person thinks it's a page view. The CRM integration reads it as gospel. Everyone's technically right, but the dashboard tells a story no one believes.

The original article nails this: define what qualifies as an accepted lead before you write a single line of tracking code. Write it down. Get it signed off. Make it your north star.

The Backend Truth is the Only Truth

This was my biggest realization: a data layer push must follow backend acceptance, not precede it. I used to do this:

form.addEventListener('submit', async (e) => {
 e.preventDefault();
 
 // Push event immediately
 window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({ event: 'lead_generated' });
 
 // Then make the request
 const response = await fetch('/api/submit-lead', { ... });
});

This is backwards. I'm reporting success before I know if it actually succeeded. The network could fail. The backend could reject it. The database could be down. None of that matters because I already fired the event.

The right approach waits for the response:

async function submitEnquiry(formData) {
 try {
 const response = await fetch('/api/submit-lead', {
 method: 'POST',
 body: JSON.stringify(formData)
 });
 
 if (!response.ok) return; // Backend rejected it
 
 const data = await response.json();
 if (!data.accepted) return; // Business logic rejection
 
 // Only now, after confirmed success
 window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
 event: 'lead_generated',
 form_id: 'contact_form',
 lead_category: 'inquiry',
 form_location: 'homepage'
 });
 } catch (error) {
 console.error('Form submission failed:', error);
 }
}

This feels obvious written out, but I genuinely didn't think about it this way for years.

What Still Bothers Me

The article talks about data layer contracts like they're simple to define, but I work in contexts where they're genuinely messy. What if your backend accepts the lead provisionally but marketing only wants to count qualified leads? Do you fire the event immediately or wait for qualification? Who decides?

I also think the article undersells the duplicate problem. Yes, double-clicks and network retries happen. But in production SPAs with React Query or SWR, handling this correctly means thinking about race conditions, request deduplication, and state management. It's not just about avoiding multiple push() calls, it's about understanding your entire data flow.

My Next Move

I'm rewriting our tracking specifications across three active projects. For each form, each conversion point, each lead source, I'm documenting:

  1. What qualifies as acceptance (server response code? A specific field in the response?)
  2. Where in the code the event fires (which function, which callback)
  3. What fields go into the event (and which absolutely don't, no emails, no PII)
  4. How we test it (browser inspector, GTM preview, GA4 debug mode, plus CRM verification)

It feels like overhead until you realize how many problems it prevents.

If you're currently measuring form submissions instead of accepted leads, I'd genuinely like to know: what's your plan to fix it? Have you had the conversation with your marketing team about what the data actually means?

Source: This post was inspired by "A Data Layer Contract for Reliable Lead Tracking in WordPress and SPAs" by Dev.to. Read the original article

Share this article

Written by Adil Sher

Full stack developer building high-traffic platforms, AI services, and custom web applications. Explore my portfolio, learn about my background, or get in touch.

Related Articles

I Built My React Site For Humans, Not AI. That Was Stupid.
Web Development Nov 25

I Built My React Site For Humans, Not AI. That Was Stupid.

Last month, I spent three days optimizing a Next.js product page for search rankings. I did everything right, meta tags, structured data, mobile-first design. The site looked great in Chrome, performed well on Lighthouse, and my client was happy. Then a question hit me like a bug...

I've Been Shipping Inaccessible AI Code and Didn't Even Know It
Web Development Nov 23

I've Been Shipping Inaccessible AI Code and Didn't Even Know It

I had one of those moments last week where I realized I'd been doing something wrong for months, and the worst part wasn't the mistake, it was how obvious the solution was once I saw it. I was reviewing a landing page my team built using Claude with a detailed layout prompt. The s...