The API Is Connected. The Numbers Don’t Add Up
A practical look at API discrepancies in web analytics across two million visits and the places where measurement quietly breaks.
That is usually where real analytics begins.
I was building an internal tool to handle analytics data on a fairly large e-commerce setup. The goal was straightforward. Pull raw data directly through the API, compare matching periods without the cosmetic smoothing of visual dashboards, and feed the verified numbers into an LLM-based analytical agent.
Not to let the model do math. Using a language model as a calculator is pointless, it makes basic arithmetic mistakes and delivers them with unshakeable confidence. The model should receive deterministic, pre-calculated facts from backend code and focus on forming hypotheses. What actually shifted in user behavior, where the unit economics broke, and where an analyst needs to look next.
Pulling JSON from an API takes ten minutes. The real problem is figuring out how much of that data you can actually trust.
Parallel API Calls and the Unassigned Traffic Gap
Standard analytics interfaces are designed to present a tidy, self-contained picture. If a session fails to fit attribution rules, the system quietly dumps the gap into an “Other” bucket or bridges the trail using internal modeling.
Once you start pulling data via the API, that protective layer disappears.
Over the test month, the application processed roughly two million sessions and over sixty thousand transactions. That is enough volume to make systemic discrepancies visible.
To verify data integrity, I ran two parallel API calls with the same metrics, visits, users, transactions, and revenue. The first request went without any dimension parameters, pulling raw totals for the thirty day window. The second request added the attribution dimension to split those exact metrics across channels.
We added up the channel rows. The sum did not match the total.
Transactions and revenue matched down to the cent across both requests. Sixty thousand orders distributed cleanly. But the traffic metrics broke. 1.2% of sessions and 2.3% of unique users simply vanished when broken down by channel. Across two million visits, that is twenty four thousand unassigned sessions. It will not kill a business, but it is more than enough reason to stop blindly summing spreadsheet cells.
Pre packaged dashboards rarely expose this. High level summaries come from one aggregation, channel breakdowns come from another, or the discrepancy gets buried in an uncategorized bucket. In reality, thousands of people arrived without an attributed source, completed a purchase, and generated revenue.
Ignore that gap, and your budget optimization turns into guesswork because marketing starts taking credit for sales it did not generate. This is the same trap behind The Illusion of Cheap Auto Attribution and Broken CPO. The application now runs both queries side by side, explicitly isolating the difference as unassigned traffic.
Payment Gateways and Broken Session Attributions
The second distortion comes from internal traffic.
To an analytics engine, it is just another session. In e-commerce, internal referrals showing up as traffic sources almost always point to technical friction. In our dataset, internal referrals accounted for over two percent of total orders. That was more than a thousand actual purchases.
The mechanics are familiar. A customer selects an item, gets redirected to a third party bank gateway, takes a couple of minutes to approve the payment, and returns to the confirmation page. If the delay exceeds the session timeout, the tracking script starts a brand new visit. The system then attributes the sale to the payment gateway or to the website’s own domain.
That is not a marketing victory. It is a prompt to audit session timeouts, cross domain tracking, and payment return URLs. When that data gets lumped into general acquisition tables, channel performance metrics become fiction.
Relative Percentages vs Percentage Points
Then comes period over period comparison.
The tool takes a thirty day window and pairs it with the preceding thirty days without overlap. Over that stretch, conversion rate moved from 4.70% to 4.56%.
A careless report might frame this as a minor dip of 0.14%. It sounds harmless, almost like statistical noise.
In relative terms, that is an exact 3% decline. At scale, three percent of lost conversion translates into a very noticeable hole in actual revenue.
Reports routinely conflate percentage drops with percentage point shifts, usually picking whichever number looks less alarming to executive leadership. We separated them in the engine. The code calculates relative change and logs the percentage point shift on a separate track.
Traffic Growth Masking Revenue Declines
The first run on live production data immediately justified the effort. Over the selected month, total traffic increased by 8%. Order volume remained flat. Gross revenue dropped by 16%.
A standard high level dashboard would show a green arrow for traffic growth. In reality, the business made less money.
Paid acquisition followed the same pattern. Ad clicks climbed, orders ticked up slightly, but revenue dropped hard. The issue was not traffic volume or cost per click. Average order value had degraded. The campaigns were pulling buyers toward cheaper SKUs and discount promotions while acquisition costs stayed flat.
One channel showed an even stranger anomaly. Plenty of purchases, but an average order value three times lower than the site benchmark.
The instinctive reaction from a media buyer is usually to call the traffic low quality and kill the campaign.
Practical experience suggests checking data pipelines first. It could be an e commerce script passing a service fee instead of the basket total, broken currency conversion, or duplicated transaction IDs on specific devices.
A data anomaly should trigger a diagnostic of your measurement instruments, not an immediate budget cut.
Deterministic Code Before LLM Reasoning
That is the entire premise behind this analytical agent.
The arithmetic, sampling checks, unassigned traffic audits, referral filtering, and deltas live entirely in deterministic server side code, backed by automated tests. Math belongs in rigid algorithms.
The language model enters only after the numbers are validated. It receives verified facts rather than raw tables.
The observed discrepancy.
Potential tracking failures.
Shifts in purchasing behavior.
The exact metrics an analyst needs to verify before pulling any levers.
Until this engine pulls direct ad spend through platform APIs, we are only looking at half the picture. Once confirmed revenue aligns with actual acquisition costs and ROAS, the loop closes.
Businesses rarely need another colorful dashboard. They need a tool that points out measurement discrepancies and explains why actual revenue is moving.