Skip to content
← Blog

Visitor Statistics Without Google Analytics or Cookies

Burak Berk Şama · · 6 min read · Software Development

In short: This site has no Google Analytics and uses no tracking cookies. I measure visits with a small counter I wrote myself:

  • The browser sends only the page path, the referring site and, if present, a source tag.
  • Unique visitors are counted with a one-way digest of the IP address and browser string, made with a key that changes every day.
  • The IP address and browser string themselves are never stored.

This post explains how it works, what it does and doesn't measure, and what tagging shared links does for a business.

When I scanned 117 business websites in Denizli, 45% ran tracking code without a known cookie consent tool. Under the Turkish data protection authority's cookie guidance, analytics and advertising cookies shouldn't run until the visitor consents. There are two ways to handle that: install a cookie consent tool, or measure which pages are read without cookies at all.

On my own site I chose the second. It has a cost: most of the detail Google Analytics offers is missing. But it answers most of the questions a business owner actually asks.

What do I want to know?

For a business website, these questions are usually enough:

  • How many people visited the site this week?
  • Which pages are being read?
  • Where do visitors come from: Google, Instagram, LinkedIn?
  • Are they on a phone or a computer?
  • Did a post I shared bring anyone to the site?

None of these require recognising a visitor over days or sharing data with ad networks.

How it works

1. What the browser sends

When a page opens, the browser sends one small request to the server. It contains three things:

  • the path of the page (for example /services)
  • the referring site, if any (for example google.com)
  • a source tag, if any (explained below)

The request is sent with navigator.sendBeacon, which doesn't hold up page loading, so it doesn't slow the site down.

2. What the server stores

No session is started and no cookie is written for this request. Laravel's session, cookie and form protection layers are deliberately switched off for this endpoint. For each page view the server stores:

  • the page path and language
  • only the domain of the referring site, not the full URL
  • the source tag
  • the device type: mobile or desktop
  • a short digest for counting unique visitors

Requests to the admin panel, requests with no browser string and known automated visitors such as search engine bots are not recorded at all.

3. How unique visitors are counted

This is the most sensitive part. One person opening five pages in a day shouldn't show up as "five visitors". But that shouldn't require storing anything that identifies them.

The solution is a one-way digest of the IP address and browser string:

$visitor = substr(hash_hmac('sha256', $ip.'|'.$userAgent, $appKey.$today), 0, 16);
  • One-way: you can't get back to the IP address from the digest.
  • Keyed: the key includes the site's secret application key, so matching digests by trying IP addresses one by one isn't possible either.
  • Changes daily: the date is part of the key, so the same person appears with a different digest the next day. Following a visitor across days isn't possible.

The IP address and browser string are used only for this calculation during the request and are never stored.

4. How long records are kept

Records are kept for 400 days and expired ones are deleted automatically. That allows comparing a period with the same period a year earlier.

Source tags: which post actually worked?

The referring site isn't always reliable. Visitors arriving from the Instagram app, WhatsApp or a link in a PDF often show up as "direct". That's why most visits on my site appeared as "direct".

To fix that, I add a short tag to the links I share:

Where Link
Instagram profile burakberksama.com/?k=ig
Instagram story link burakberksama.com/site-analizi?k=igs
First comment on a LinkedIn post burakberksama.com/canli-demo?k=lip
Email signature burakberksama.com/?k=mail
QR code on a business card burakberksama.com/?k=kart

The tag is sent to the counter only on the first page of a visit. It isn't stored in the browser and is removed from the address bar straight away. If the visitor copies the link and sends it on, the tag doesn't go with it. The standard utm_source parameter works the same way.

The admin panel's "Source tags" table shows each tag's visits over the last 90 days. So "did the Instagram story or the LinkedIn post bring more visitors?" is answered with a number, not a guess.

Any business website can use this method. Adding ?k=gbp to the website link in your Google Business Profile, for example, shows visitors coming from Maps separately.

What the admin panel shows

  • page views and visitors for today, the last 7 days and the last 30 days
  • a daily visits chart for the last 30 days
  • the most-read pages in the last 30 days
  • the sites sending the most visitors in the last 30 days
  • source tags for the last 90 days

What it doesn't measure

To be honest, this counter doesn't fully replace Google Analytics:

  • No unique visitors across days: the same person visiting on Monday and Tuesday counts as two visitors. That's a deliberate choice.
  • No time on page, scrolling or clicks.
  • No conversion funnel: "which page did they read before filling in the quote form?" stays unanswered.
  • JavaScript is required: visitors with JavaScript turned off aren't counted.
  • Bots can't all be filtered out: bots posing as normal browsers may be counted.

For a business website these limits are usually acceptable. For an online shop that manages an ad budget and needs to measure conversions, it may not be enough; there, Google Analytics with a properly configured consent tool is the better fit.

The legal side

The counter uses no cookies and stores nothing that identifies a person, so it is in a different position from analytics cookies that depend on consent. Still, my privacy notice explains clearly what I measure, what I don't store, and how source tags work. This post isn't legal advice; if you use a similar method on your own site, update your privacy notice to match.

You can see whether your site runs tracking code without consent with the site check tool. For more on cookies, see my post on data protection for websites.

Frequently asked questions

Can you measure visitors without Google Analytics?

Yes. A simple request to the server can measure which page was opened, where the visitor came from and the device type without cookies. For unique visitors, a one-way digest can be made from the IP address and browser string with a key that changes every day.

Do cookieless statistics need cookie consent?

With no cookies, there is nothing for a cookie consent banner to cover. That doesn't mean there are no obligations, though: the privacy notice should explain clearly what is measured.

Why do visitors from Instagram show up as "direct"?

Links opened inside apps such as Instagram or WhatsApp often don't send referrer information. Adding a source tag such as ?k=ig to shared links makes those visits identifiable.

Is it a problem if the source tag stays in the link?

On this site, the tag is removed from the address bar right after it is sent with the first page view. So if a visitor shares the link, the visit isn't credited to the wrong source.

Is this approach enough for an online shop?

Usually not. Sites that need to measure ad spend and sales conversions are better served by a full analytics tool with a properly configured consent tool.

Web Regulation