Counting clicks without reading the link text
A counter answers "how many came". The more useful question is usually "how many did something" — clicked the contact link, opened the download, went out to a social profile. This site has had events for that since they were built: put data-s4u-event="contact" on an element and clicks on it get counted by name.
Almost nobody used it, because almost nobody knew. So there is now a checkbox: count clicks on links automatically, no attributes required. The interesting part is not the switch. It is what the counted thing gets called.
Not the link text
The obvious name for a click is the words the visitor clicked on. It is also the wrong one.
Link text is free content. A link can read "Order 4711", or "Message from Anna", or carry a house number, a booking reference, an e-mail address. All of that would land in a database column named name and sit there. This service's privacy policy says the statistics contain no personal data, and that has to stay true without depending on what any site owner happens to write inside an anchor tag.
There is a second problem, smaller but real: twenty links reading "here" on one page are one name that says nothing, and the same link in eleven translations would be eleven names out of the fifty a counter is allowed.
So the name comes from the target path. The site owner chose it, it is stable, and it is already the key the page statistics use.
Three normalisations, each for a reason
- Language prefix removed.
/de/blogand/pl/blogare the same page. Without this, one multilingual site's language switcher alone would consume eleven of the fifty names. - Digit runs of five or more become
n. Two statistics pages with different counter numbers are not two pages; they are the same page twice. - Links leaving the site become
ex-plus the host. The path of a stranger's page tells the owner nothing. Where the click went does.
Anchors, mailto:, tel: and javascript: are skipped — they are not destinations anyone needs a count for. Elements that already carry their own event name are skipped too, or the same click would be counted twice.
What it costs
The browser script grew by 1,022 bytes compressed, once per first visit. Nothing else: the flag rides along in a request the script already makes on every page load — a request that until now always answered the same constant — so there is no second round trip. On the server, the list of counters with the switch on lives in a small file rather than a query, because that query is a full scan of 166,433 rows and costs a measured 143.9 milliseconds.
The default is off, and it stays off. At this site's volume, turning it on everywhere would add roughly nine thousand writes a day to the busiest table there is. That is a thing you switch on, not a thing that happens to you.