I Finally Understand Why Our Analytics Keep Lying to Us
Adil Sher
Author
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:
- What qualifies as acceptance (server response code? A specific field in the response?)
- Where in the code the event fires (which function, which callback)
- What fields go into the event (and which absolutely don't, no emails, no PII)
- 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