TapCub is live — analytics, insights and live chat, free on one platform
Analytics

How Does Web Analytics Work? One Visit From Script to Report

Follow one sample visit through the five stages of web analytics: script, request, collector, bot filtering and sessions, and aggregation. See where numbers change, why two tools disagree and how to test each stage for data loss.

Su He Published Nov 28, 2026 17 min read Analytics
Sample data: one visitor's 11 attempted hits. Ten reached the collector; one went to the bot report and one was dropped as a duplicate, leaving 8 human hits that become 4 pageviews, 2 sessions and 1 conversion.Sample data

Web analytics works in five stages: a script on the page builds a hit, the browser sends it to a collector, the collector adds time, location, device and a visitor ID, bots are set aside and hits are grouped into sessions, and the result is added up into reports. Each stage can drop or reshape data, which is why two tools rarely match.

What you will learn

  • A report number passes through five stages, script, request, collector, bot filter and sessions, aggregation, and each one can lose or change it
  • Identity method, bot handling and session rules explain most gaps between two analytics tools on the same site
  • Test each stage directly and compare goal counts with your own database to know how much data your setup loses

What happens between a page load and a report number?

Web analytics works as a pipeline with five stages. Each stage changes the data, and each one is a place where a visit can be dropped or counted differently:

StageWhat happensWhere data can be lost or changed
1. TagA script on the page reads the URL, title, referrer and screen sizeBlockers, consent settings, script errors, people who leave before it loads
2. RequestThe browser sends a small "hit" to a collection endpointPage closes before the hit leaves; network or content security policy blocks it
3. CollectorThe server adds time, location from the IP address, device from the user agent, and a visitor IDIdentity method decides who counts as the same visitor
4. Bot filter and sessionsAutomated traffic is set aside; hits from one visitor are cut into sessionsDifferent bot rules and session rules give different totals
5. AggregationSessions and hits are rolled up into pageviews, visitors, time on page and conversionsDefinitions of each metric, time zones, deduplication

The rest of this guide walks a single sample visit through those stages, hit by hit, so you can see where each number in a report comes from. That is also the practical answer to the most common question about analytics: why two tools installed on the same site never show the same numbers. Server log analysis, which skips stage 1 and reads the web server's own records, works differently and is mentioned where it matters. If you are planning an installation rather than trying to understand one, start with how to implement web analytics.

Stage 1: what does the analytics script do in the browser?

The tag is a few lines of HTML that load a JavaScript file. When the page loads, the script:

  1. Reads the page address (location.href), the title (document.title) and the previous page (document.referrer).
  2. Reads device context the browser exposes: screen size, language, time zone.
  3. Listens for later activity: route changes in single-page apps, clicks on outbound links, file downloads, form submits, and the page being hidden or closed.
  4. Builds a hit and sends it (stage 2).

The script can also be prevented from running at all. Check these before blaming the collector:

  • Content blockers and privacy extensions that block the script's domain or its requests.
  • Consent and privacy signals. Depending on the tool and your settings, a missing consent or a browser signal such as Global Privacy Control can stop collection or switch it to a reduced mode.
  • Content security policy. If the page's connect-src does not allow the collection host, the request fails silently.
  • Early exits. Someone who leaves before a deferred script runs is never recorded.

None of these show up in the report as a "lost" row. They simply never become data, which is why script-based analytics always undercounts compared with server logs.

Stage 2: how does a hit reach the analytics server?

A hit is a small HTTP request carrying a few fields. Sample data for the first page of our example visit:

FieldExample valueSet by
EventpageviewScript
URLhttps://example.com/blog/crash-rate?utm_source=newsletterBrowser
Referrerhttps://www.google.com/Browser
Title"Crash rate explained"Page
Screen412 × 915Browser
Language and time zoneen-US, America/ChicagoBrowser
Site keythe property or project ID in the tagTag

Modern scripts send hits with navigator.sendBeacon, a browser API the W3C Beacon specification describes as asynchronous, non-blocking delivery of data. The specification says beacon requests are guaranteed to be initiated before the page is unloaded, and its example sends session data on visibilitychange, noting that this is the only event guaranteed to fire on mobile devices. That matters for anything measured at the end of a page view, such as time on page: if a script waits for an unload event, phones often never send it.

Two practical consequences:

  • The last hit of a visit is the fragile one. If the browser is killed, the phone loses signal or the tab crashes, that final hit never leaves.
  • A success response does not prove storage. Many collectors return the same status code whether they keep or discard a hit. To check delivery, look for the event in a realtime view, not at the network status.

Stage 3: what does the collector add?

The collection server receives the hit and adds what the browser did not send:

  • Receive time. Reports use server time, so a visitor's clock does not matter.
  • Location. The IP address of the request is looked up to a country, sometimes region or city. Privacy-focused tools then truncate or discard the IP address rather than store it.
  • Device and browser. Parsed from the user agent string and client hints: browser, operating system, device type.
  • Visitor identity. The collector decides whether this hit belongs to a visitor it has seen before. There are two common methods:
    • A cookie or stored ID in the browser, which persists until it expires or is cleared.
    • A hash of a server-side salt with request data such as the IP address and user agent. No cookie is written. If the salt rotates daily, the same browser is a new visitor every day.

The identity method is the biggest single reason visitor counts differ between tools. A cookie-based tool counts one person on a phone and a laptop as two visitors, and one person who clears cookies weekly as four a month. A daily-salt hash cannot recognise anyone across midnight, so its "returning visitors" over a week are lower. Neither is wrong; they count different things, and logged-in user IDs are the only way to join devices reliably.

Stage 4a: how are bots filtered out?

A large share of requests to websites are automated. Imperva's 2025 Bad Bot Report, published in April 2025, found that automated traffic made up 51% of all web traffic in 2024, the first time in a decade it surpassed human activity, with malicious bots at 37% of all internet traffic.

Most of that never reaches a script-based tool, because many crawlers do not execute JavaScript. The ones that do, such as headless browsers and some AI agents, have to be recognised by the collector. Common checks, usually combined:

  1. User agent lists. Known crawlers identify themselves (search engines, SEO tools, AI crawlers).
  2. Automation signals. A browser with navigator.webdriver set, or a headless user agent, is flagged.
  3. Network origin. Requests from data-centre address ranges are suspect.
  4. Behaviour. Dozens of pages per second, or no scrolling or input ever.

What happens next is a setting, and it changes your numbers: some tools delete bot hits, some keep them in a separate report, and some leave them in the totals. A traffic spike from one city on one day with a 100% bounce rate is the classic sign that bots are still in the denominator. Server logs show far more bots than a script does, because they see every request, including crawlers that never run JavaScript.

Stage 4b: how are hits grouped into sessions?

A session is a group of hits from one visitor with no long gap between them. Google's Analytics documentation states that a session times out after 30 minutes of user inactivity by default, and most tools use the same 30-minute idle rule, often with extra rules such as a maximum length or a split at midnight or when the campaign changes. The full definition is in our glossary entry on sessions.

Here is the complete sample visit after stages 1–4. One visitor, on a phone, arrives from Google:

#TimeWhat the browser sentWhat the collector decidedSession
121:40:00pageview /blog/crash-rate, referrer google.comCountry from IP, Chrome on Android, visitor V1, humanS1 starts, source: Google organic
221:41:12pageview /blog/crash-rate from a headless browserAutomation signal: bot, kept out of human reportsnone
321:43:20time-on-page 200 s, then pageview /pricingRoute change inside the siteS1
421:44:50time-on-page 90 s (tab hidden)/pricing viewed for 90 sS1
522:31:00pageview /pricing (tab reopened)46 min since last hit, over 30 min idleS2 starts, source: direct
622:33:00time-on-page 120 s, then pageview /signupRoute changeS2
722:33:01pageview /signup again (double reload)Same visitor, same page within 2 s: droppedS2
822:36:30event signup_completedGoalS2
9nevertime-on-page for /signupPhone ran out of battery; the hit never leftnone

The browser attempted 11 hits (rows 3 and 6 each carried two). Ten arrived. One went to the bot report, one was dropped as a duplicate, and eight human hits remain: four pageviews, three time-on-page records and one goal event.

The session rule decides the session count. Under a 30-minute idle rule this visit is 2 sessions, and the second one is credited to "direct" even though the person first came from Google. Under a 60-minute idle rule the 46-minute gap does not split it, so it is 1 session credited to Google. Same hits, different sessions, different channel report.

app.tapcub.com

Where the visit's 11 hits ended up

sample visit
Pageviews in reports4
Time-on-page records3
Goal event1
Bot report only1
Dropped as duplicate1
Never sent1
Sample data
Sample data: one visitor's 11 attempted hits. Ten reached the collector; one went to the bot report and one was dropped as a duplicate, leaving 8 human hits that become 4 pageviews, 2 sessions and 1 conversion.

Stage 5: how do hits become report rows?

Aggregation counts the cleaned, sessionised hits. From the sample visit, under the 30-minute rule:

MetricValueHow it was counted
Pageviews4Rows 1, 3, 5 and 6; the bot hit and the duplicate are excluded
Sessions2S1 and S2
Visitors1One visitor ID, V1
Pages per session2.04 pageviews ÷ 2 sessions
Bounced sessions0Each session has two pageviews
Goal conversions1signup_completed in S2
Average time on page136.7 s(200 + 90 + 120) ÷ 3 measured pages; /signup has no measurement
Bot requests1Shown only in a bot report

Time on page shows how much the measurement method matters. Our sample script sends a time-on-page record when the page changes or is hidden, so three of four pages have a value and the average is 410 ÷ 3 = 136.7 seconds. A tool that only measures the gap between two pageviews would get 200 seconds for /blog/crash-rate and 120 seconds for the second /pricing, but nothing for the first /pricing (the session ended there) or /signup. Its average would be (200 + 120) ÷ 2 = 160 seconds. Same visit, a 23-second difference, with no tool doing anything wrong.

Reports are also usually built from pre-computed daily rollups, so the day boundary depends on the reporting time zone you set. A visit at 23:50 in New York is "tomorrow" in a report set to UTC.

Why do two analytics tools show different numbers?

Now map the pipeline to the differences you see when two tools run on one site. Check them in this order, because the first ones usually explain the largest gaps:

  1. The tag did not run in one tool. Different blocker lists, consent rules or a tag missing on some templates. Compare pageviews for one URL you know well.
  2. Bot handling. One tool keeps bots in totals, the other removes them. Compare a day with an obvious spike.
  3. Identity. Cookie versus cookieless hash, and how long an ID lives. This mostly moves visitors and returning visitors, not pageviews.
  4. Session rules. Idle timeout, midnight split and campaign split. This moves sessions, bounce rate and channel credit.
  5. Metric definitions. Time on page, engagement and bounce are defined differently in different tools, as the 136.7 s versus 160 s example shows.
  6. Reporting settings. Time zone, filters, URL normalisation such as dropping query strings, and data thresholds or sampling.

A rule of thumb: if pageviews agree within a few percent but visitors differ a lot, it is identity. If pageviews differ, it is the tag, consent or bots. If only sessions and bounce rate differ, it is the session rule.

What differsMain metric it movesHow to check
Tag blocked or missingPageviews and everything belowCompare pageviews for one known URL
Bots kept vs removedVisitors, bounce rateCompare a day with an obvious spike
Cookie vs cookieless identityVisitors, returning visitorsPageviews match but visitors differ
Session rulesSessions, bounce rate, channel creditIdle timeout, midnight and campaign splits
Metric definitionsTime on page, engagementRead each tool's definition
Reporting settingsDaily totalsTime zone, filters, URL normalisation, sampling

Check in this order; the first rows usually explain the largest gaps.

How can you check that your analytics is not losing data?

Each stage has a test you can run in under ten minutes:

StageTestWhat a pass looks like
TagOpen the page with browser developer tools; check the console and that the script file loadsScript loads once, no errors
RequestIn the network panel, filter for the collection host; navigate and switch tabsOne request per pageview, another when the tab is hidden
CollectorVisit from your phone and watch the realtime viewYour visit appears with the right page, country and device
Bots and sessionsVisit, wait 31 minutes, returnA second session appears in the session list
AggregationCompare a goal count with your own records for a full day, such as orders in your databaseWithin a few percent, with the gap explained by blockers and consent

The last test is the one most teams skip. Your order database or signup table is the ground truth for conversions. If analytics shows 180 signups and the database shows 200, a 10% gap tells you how much stages 1 and 2 lose on your audience, which is a number to keep in mind every time you read a conversion rate.

How a visit becomes a report in TapCub

Here is the same sample visit in TapCub, stage by stage, with where to look at each step.

  1. Tag and request. The website script reads the page and sends each pageview to the collection endpoint with navigator.sendBeacon, falling back to fetch with keepalive. On a route change, when the tab is hidden or when the page closes, it sends the time spent on the page if it was open for more than one second; there is no heartbeat. The script writes no cookie or local storage, and does not run when the browser sends Do Not Track or Global Privacy Control. Install and check it under Web analytics › Configuration › SDK code, and watch hits arrive in Web analytics › Realtime.
  2. Collector and identity. The collector derives the visitor ID from a site salt hashed with address and browser data. The default balanced preset keeps a site-level salt so new and returning visitors can be compared; the strict preset rotates the salt daily. IP addresses are not stored on events. These choices live in Configuration › Privacy center.
  3. Bots. New projects default to detecting bots and reporting them separately: row 2 of the sample would appear under Web analytics › Bots, not in human visitors, sessions or pageviews. With only the page script, only bots that execute JavaScript are visible; crawlers that do not run scripts need server-side collection or a log import.
  4. Sessions and duplicates. The default session rule is 30 minutes idle and 24 hours maximum, adjustable per project; a tab that returns after more than 30 minutes in the background records a new pageview that starts a new session, as in row 5. The collector keeps one pageview when the same visitor repeats it within 2 seconds, as in row 7. Inspect real visits in Web analytics › Sessions.
  5. Reports. Pageviews, visitors and time on page roll up into Web analytics › Overview and Web analytics › Pages, and signup_completed counts as a conversion once it is set up under Web analytics › Goals. Compare that goal count with your own signup table, as in the data-loss test above.

For the beacon itself, see the glossary entry on beacons.

FAQ

How does web analytics work in simple terms?

A script on each page sends a small message to an analytics server whenever someone views a page or does something tracked. The server adds the time, an approximate location and the device, filters out bots, groups each visitor's hits into sessions, and adds everything up into reports such as pageviews, visitors and conversions.

How do analytics tools collect data without cookies?

Instead of storing an ID in the browser, the collector computes one from data in each request, typically a hash of the IP address and user agent with a secret salt. The browser stores nothing. The trade-off is that recognition only lasts as long as the salt and the request data stay the same, so returning-visitor counts are less precise.

Why does my analytics show fewer visitors than my server logs?

Server logs record every request, including bots that never run JavaScript, images, and visitors whose blockers stop the analytics script. Script-based analytics only counts browsers that load and run the tag, and usually removes the bots it can identify. A gap is normal; check how much of it is bots before treating it as lost data.

How does web analytics track a session?

It groups hits from one visitor into a session until there is a long enough gap. The common default is 30 minutes of inactivity; some tools also split at midnight or when the campaign changes. In the sample visit, a 46-minute gap made two sessions under a 30-minute rule and one session under a 60-minute rule.

Can web analytics see who I am?

Not by name unless the site tells it. The tool sees a visitor ID, an approximate location derived from the IP address, and device details. It knows who a person is only when the site sends a logged-in user ID or an email with a hit, which is a separate, deliberate setup.

Sources

  • W3C Web Performance Working Group. Beacon, Candidate Recommendation Draft, 3 August 2022 — non-blocking delivery, beacons initiated before unload, visibilitychange as the event guaranteed to fire on mobile. Checked 2026-11-28.
  • Google Analytics Help. About Analytics sessions — session defined as a period of interaction, 30-minute inactivity timeout by default. Checked 2026-11-28.
  • Imperva. 2025 Imperva Bad Bot Report: How AI is Supercharging the Bot Threat, 15 April 2025 — automated traffic 51% of web traffic in 2024; malicious bots 37%. Checked 2026-11-28.
Filed underAnalytics

Was this article helpful?

We use your answers to fix and expand this page.

Su He

Data Analyst

Explores traffic sources, conversion funnels, and retention, using clear metric definitions and concrete examples to explain what the numbers mean.

See bots and humans counted separately

A cookie-free script, bots kept out of visitor and session totals, and a session list to check real visits hit by hit.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics