• SEO
  • Google Search
  • web analytics
  • HTTP

Counting Google Search visits from the Referer header in your own logs

A beginner's explainer of Google's November–December 2026 guidance on the Referer values Google Search sends, why the header is often missing, the googsrc=ai-uk parameter, and a tested browser experiment and log script showing how redirects on your own site erase the evidence.

Say you run a small site without a JavaScript analytics tag. You only have the server’s access log, or the request log from your CDN. You want to know a simple thing: how many people arrived from Google Search today, and on which pages? Search Console answers part of that, but its numbers come later, are grouped by query and page, and never tell you what a visitor did after landing. Your own logs have every request, but nothing in a log line says “this came from Google” in plain words.

On November 12, 2026 Google added a page to its Search Central documentation that answers exactly this: Identify Google Search traffic in your web analytics or server logs. It lists the values Google Search puts in the Referer request header and explains why that header is often empty. On December 1, Google added a section to the same page about a new URL parameter, googsrc=ai-uk, for clicks from AI features in the United Kingdom. (Search Central documentation updates, November 12 and December 1)

This article explains those rules from zero, then goes one step further than the source. I ran a small browser experiment that shows, request by request, how redirects on your own site can erase the Google evidence before your log or analytics sees it, and a short Node.js script that counts Google visits in a log file. Both were run on Node.js 22.23.5 and Chromium 158 (driven by Playwright) on Linux.

A few terms first

  • HTTP request header: a Name: value line the browser sends with each request, before any body. Servers can log them.
  • Referer header: the header that tells the server which page the request came from. The name is a historical misspelling of “referrer”; the HTTP standard kept it. (MDN: Referer)
  • Origin: the scheme plus host (plus port, if any) of a URL, for example https://www.google.com. It has no path and no ?query.
  • Referrer policy: a rule, set by the page the user is leaving, that decides how much of its URL goes into Referer: the full URL, only the origin, or nothing. It is set with the Referrer-Policy response header or similar HTML attributes. (MDN: Referrer-Policy)
  • Landing page: the first page of your site a visitor loads after clicking a link elsewhere.
  • Access log: the text file (or CDN log stream) where a web server writes one line per request: time, IP address, method, path, status code, Referer and User-Agent.
  • Cross-origin: a request from a page on one origin to a different origin, such as a click from google.com to your site.
  • Google Discover: the feed of articles Google shows in its app and on its mobile home page without the user typing a search.
  • AI Overviews and AI Mode: Google Search features where a generated answer is shown with links to sources.
  • Playwright: a library that lets a script open and control a real browser, used here to click links automatically.
  • Redirect: a response that sends the browser to another URL. A server-side redirect uses a 301/302 status and a Location header. A client-side redirect is done by the page itself, with JavaScript (location.href = …) or a <meta http-equiv="refresh"> tag.

What Google Search actually sends

According to Google’s page, Google Search uses the origin referrer policy. So when someone clicks a result, your server sees only the scheme and host of the Google page, never the path or the search terms. Google states plainly that the Referer “doesn’t include the search query”; for queries you still need the Performance report in Search Console.

The values Google lists are:

Where the user clicked Referer value your server receives
Google Search on the web https://www.google.com/ or a local Google domain, such as https://www.google.co.uk/ or https://www.google.co.jp/
Google app on Android android-app://com.google.android.googlequicksearchbox/https/www.google.com when the app opens the link in a browser tab, otherwise https://www.google.com/ (or a local domain)
Google app on iOS https://www.google.com/ (or a local domain)

Two details from the same page matter when you write a filter. First, Discover traffic uses the value of the surface where Discover was shown (the Google app or Google Search on the web), so it is counted with these patterns too. Second, other Google services on the same origins, such as Google Images, send the same values, so you cannot separate them with the Referer alone.

Why the header is often empty

Setting a referrer policy on Google’s side does not force the browser to send the header. Google lists common cases where the browser or operating system drops it: private browsing and anti-fingerprinting protection, opening a result in a new tab in some browsers, moving from a native mobile search widget into an external browser, and privacy extensions or strict browser settings. JavaScript analytics can miss even more visits because of consent banners and ad blockers.

The practical consequence: a visit with no Referer is unknown, not “direct”. Many tools label an empty referrer as “direct” traffic, and some of those visits really came from Google. Keep that bucket separate in your own reports instead of folding it into another channel.

The googsrc=ai-uk parameter

When a user in the United Kingdom clicks an organic link inside a Search generative AI feature (Google names AI Overviews, AI Mode and generative AI features in Discover), Google adds googsrc=ai-uk to the link, for example https://example.com/ramen?googsrc=ai-uk. If the URL already has a query string, the parameter is appended to it. Google’s page says it is not added to Google Ads links and does not affect crawling, indexing or ranking.

This is a narrow signal. It only covers UK users, so its count is part of your AI-feature traffic, not all of it. For the full figure Google points to the generative AI performance report in Search Console, which covers AI Overviews and AI Mode; Discover has its own report. And because it lives in the URL, anything that strips the query string before your log or tag records the request destroys it. The experiment below shows how easily that happens.

Experiment: what your server sees after a click

Google’s page warns that client-side redirects may replace the Referer with your own URL, that redirects which drop the query string lose googsrc, and that a redirect sending a stricter Referrer-Policy can remove the Referer. I wanted to see each case in a real browser, so I built a small lab.

Setup. One Node.js server on http://127.0.0.1:8001 plays the search page: it sends Referrer-Policy: origin, like Google, and shows one link. A second server on http://localhost:8002 plays your site and records the path and Referer of every request. The two hosts are different origins, so the click is cross-origin, like a real search click. Playwright opens the search page, clicks the link, and prints what your site received. The core of the “site” server looks like this:

// "Your site": logs every request, then answers with a page or a redirect.
if (u.pathname === '/old-keepqs') { res.writeHead(301, { Location: '/new' + u.search }); return res.end(); }
if (u.pathname === '/old-dropqs') { res.writeHead(301, { Location: '/new' }); return res.end(); }
if (u.pathname === '/old-strict') {
  res.writeHead(301, { Location: '/new' + u.search, 'Referrer-Policy': 'no-referrer' });
  return res.end();
}
if (u.pathname === '/js-redirect') return res.end(`<script>location.href='/new'+location.search</script>`);
if (u.pathname === '/meta-refresh') return res.end(`<meta http-equiv="refresh" content="0;url=/new">`);
res.end('<p>landing</p><img src="/logo.png">');

Every link in the test carries ?googsrc=ai-uk, so we can also watch what happens to the parameter. This is the actual output:

Click -> /ramen?googsrc=ai-uk
  /ramen?googsrc=ai-uk       Referer: http://127.0.0.1:8001/
  /logo.png                  Referer: http://localhost:8002/ramen?googsrc=ai-uk

Click -> /old-keepqs?googsrc=ai-uk
  /old-keepqs?googsrc=ai-uk  Referer: http://127.0.0.1:8001/
  /new?googsrc=ai-uk         Referer: http://127.0.0.1:8001/

Click -> /old-dropqs?googsrc=ai-uk
  /old-dropqs?googsrc=ai-uk  Referer: http://127.0.0.1:8001/
  /new                       Referer: http://127.0.0.1:8001/

Click -> /old-strict?googsrc=ai-uk
  /old-strict?googsrc=ai-uk  Referer: http://127.0.0.1:8001/
  /new?googsrc=ai-uk         Referer: (none)

Click -> /js-redirect?googsrc=ai-uk
  /js-redirect?googsrc=ai-uk Referer: http://127.0.0.1:8001/
  /new?googsrc=ai-uk         Referer: http://localhost:8002/js-redirect?googsrc=ai-uk

Click -> /meta-refresh?googsrc=ai-uk
  /meta-refresh?googsrc=ai-uk Referer: http://127.0.0.1:8001/
  /new                       Referer: http://localhost:8002/meta-refresh?googsrc=ai-uk

(I removed the /logo.png lines after the first case; they follow the same pattern.) How to read it, case by case:

  1. Direct landing. The page request carries only the origin of the search page, http://127.0.0.1:8001/, exactly what the origin policy promises. The image on that page has your own URL as its Referer. That is why Google says to count only landing-page requests: asset requests carry your own page’s URL. (My own addition: if you counted them, every Google visit would also produce several “internal” requests that inflate your totals.)
  2. 301 that keeps the query string. Both the first request and the redirected request keep the search page as Referer, and googsrc survives. A server-side redirect done right loses nothing.
  3. 301 that drops the query string. The Referer survives, but /new arrives without googsrc. Your log can still see Google, but not the UK AI feature.
  4. 301 with Referrer-Policy: no-referrer. The parameter survives, but the redirected request has no Referer at all. If your analytics only sees /new, this visit becomes “unknown”.
  5. JavaScript redirect. The final page’s Referer is now your own URL. Only the first hop still shows the search page. An analytics tag that runs on /new would see an internal referral.
  6. Meta refresh. Same problem, and because the target URL was written without the query string, googsrc is gone too.

The lab simulates Google with a local server, so it shows browser behaviour, not Google’s. Other browsers and versions may differ, especially around privacy features, so repeat the test in the browsers your visitors use if a number really matters.

Counting Google visits in a log file

Once the landing requests reach your server intact, counting them is a small text-processing job. The script below reads an access log in the common “combined” format (used by default by many Nginx and Apache setups), keeps only successful GET requests for pages, and sorts each one into Google, unknown (no Referer) or other.

Save it as classify-google.mjs:

// Usage: node classify-google.mjs access.log
import { readFileSync } from 'node:fs';

const LINE = /^(\S+) \S+ \S+ \[[^\]]+\] "(\S+) (\S+) [^"]*" (\d{3}) \S+ "([^"]*)" "([^"]*)"/;
const GOOGLE_WEB = /^https:\/\/www\.google\.(?:com|[a-z]{2}|co\.[a-z]{2}|com\.[a-z]{2})\/$/;
const GOOGLE_ANDROID_APP = /^android-app:\/\/com\.google\.android\.googlequicksearchbox(?:\/|$)/;
const ASSET = /\.(?:css|js|mjs|png|jpe?g|gif|svg|webp|avif|ico|woff2?|map)$/i;

const counts = { pageViews: 0, googleSearch: 0, googleAiUk: 0, noReferer: 0, other: 0 };
for (const line of readFileSync(process.argv[2], 'utf8').split('\n')) {
  const m = LINE.exec(line);
  if (!m) continue;
  const [, , method, target, status, referer] = m;
  const url = new URL(target, 'https://example.com');
  // Only successful GETs of pages count as landings; assets carry your own URL as Referer.
  if (method !== 'GET' || status !== '200' || ASSET.test(url.pathname)) continue;
  counts.pageViews++;
  if (referer === '' || referer === '-') counts.noReferer++;
  else if (GOOGLE_WEB.test(referer) || GOOGLE_ANDROID_APP.test(referer)) {
    counts.googleSearch++;
    if (url.searchParams.get('googsrc') === 'ai-uk') counts.googleAiUk++;
  } else counts.other++;
}
console.log(counts);

What each part does:

  1. LINE pulls the method, path, status code, Referer and User-Agent out of one log line. If your log uses a different format, this is the only line to change.
  2. GOOGLE_WEB matches https://www.google. followed by com, a two-letter country domain (google.de), co.xx (google.co.uk) or com.xx (google.com.vn), and then a single /. Because it must end with exactly one / right after the domain, https://www.google.com.evil.example/ does not match. The pattern also misses a few rare Google domains with longer endings, such as google.cat; add them if they matter to your audience.
  3. GOOGLE_ANDROID_APP matches the Android app value from Google’s table.
  4. ASSET skips CSS, JavaScript, images and fonts, because their Referer is your own page.
  5. googsrc is read with URLSearchParams, so it is found whether it is the first parameter or appended after others.

I tested it on an eight-line sample log with: a visit from google.com, the CSS file that page loaded, visits from google.com.vn, from google.co.uk with googsrc=ai-uk, and from the Android app, one request with - as Referer, one with the fake google.com.evil.example, and one from Hacker News. Run it with:

node classify-google.mjs access.log

Expected output:

{
  pageViews: 7,
  googleSearch: 4,
  googleAiUk: 1,
  noReferer: 1,
  other: 2
}

The CSS request was skipped, the fake domain landed in other, and the empty Referer was counted as unknown, not as Google or “direct”.

Common mistakes

  • Counting every request. Images, scripts and fonts outnumber pages, and their Referer is your own URL. Filter to landing pages first.
  • Matching google anywhere in the string. A pattern like /google/ also matches google.com.evil.example, googleusercontent.com or a blog post whose URL contains the word. Anchor the pattern to the exact host shapes.
  • Treating an empty Referer as “direct”. Google’s list of privacy cases means part of that bucket is search traffic. Report it as unknown.
  • Expecting the search query. The origin policy removes it. Use Search Console for queries.
  • Assuming googsrc measures all AI traffic. It covers UK users only.
  • Trusting the header as proof. Referer is set by the client and anyone can fake it with curl -H. Use it for traffic analysis, never for access control.

Limits: why your numbers won’t match Search Console

Google’s page lists the main reasons log counts and Search Console clicks differ: privacy settings that hide the header or block scripts, redirects on your site (shown above), different methods (Search Console counts a click when the user selects the result, while analytics counts a visit only after your page loads and its tag runs), and paid traffic that your analytics may include but Search Console never does. Beyond Google’s list, I would add one more: a log-based count also sees bots that send a fake Google Referer, which never appear as Search Console clicks. So use the two sources for trends on the same pages, not for an exact daily match. If a page’s Google traffic suddenly drops in both sources at once, my earlier guide on diagnosing a Google Search traffic decline walks through the next steps.

How to check your own site

  1. List your redirects. Look at the redirect rules in your server, CDN or framework config. For each rule, check that the query string is passed through (for example $args or $query_string in Nginx, %{QUERY_STRING} or the QSA flag in Apache).
  2. Click through one real redirect. Open a search result for one of your old URLs, or simulate it as in the lab, and look at the final request in your log. It should show a Google Referer and any original parameters.
  3. Look for client-side redirects. Search your templates for location.href, location.replace and http-equiv="refresh". Replace them with server-side redirects where you can.
  4. Check Referrer-Policy on redirect responses. A strict policy on the page itself is fine for your outgoing links, but on a redirect response it can remove the incoming Referer from the next request, as case 4 showed.
  5. Compare weekly totals. Run the script on a week of logs and compare the trend with Search Console’s clicks for the same pages. Expect a gap; watch for a gap that suddenly changes.

Conclusion

Google Search sends only an origin such as https://www.google.com/ (or a local domain, or the Android app value) in the Referer header, never the query, and browsers often send nothing at all. To count search visits in your own logs, match those exact values on landing-page requests only, keep “no referrer” as its own unknown bucket, and use googsrc=ai-uk only as a partial signal for UK AI-feature clicks. Most importantly, check your own redirects: a JavaScript redirect, a meta refresh, a rule that drops the query string or a strict policy on a redirect response can wipe the evidence before your log sees it.

Written by Duy Pham Independent developer. I build the apps on this site and write about how they work.

More about me