Web counters started out as a fad on the internet around 1995-1996. The first web counters were perl scripts or C programs that were included in web pages using "server-side includes" in .shtml files (for "server-parsed html"). This technology has been almost entirely supplanted by the likes of PHP.
Then, someone had the idea of offering a hosted counter service. You would include an image tag on your page. The counter server would increment its count for your site and piece together an image that usually resembled an odometer.
In 1996, a site opened up called the Web-Counter, at counter.digits.com. It was a classic case of viral marketing. People would sign up, put the counter on their pages, which others would see, who would then sign up for their own. Digits.com was quickly overwhelmed with demand, and soon copycats began offering similar services.
Offering free web counters required a lot of bandwidth and was not terribly profitable. New services popped up and quickly disappeared very often.
Some had another idea: rather than simply showing a hit count on an image, why don't we use the same technique to compile hit count statistics over time and show them on a separate page? These services also gathered more information from the headers that browsers would send along with requests for the image such as the User-agent of the browser from which, with a little dark magic, one could deduce the proportions of the brands of browsers people were using.
These new services which sometimes called themselves "trackers" began to compete with each other with the kinds and details of statistics they could gather. Some sent a cookie with the image to try to determine if a hit came from a unique visitor.
So that's the history of hosted web counters and web analytics.