Google offers an analytics package that a huge amount of sites embed. Many other companies like Facebook have software available as well. Mostly people have these to track performance of Google-published ads, but it gathers a LOT more data than that. You also don’t need to use their ad system to put it on your site.
Anyway, it runs JavaScript to gather information about everything that a visitor does on the site and sends it to Google. You can “opt out” by using a browser extension like NoScript. I assume ad blockers could work too.
For people developing or running a site, it really gives you a ton of useful information - where your visitors are from, what pages people viewed, how they got to your site (search terms, ads, referrers), how long they spend on your site, even a “heat map” that shows what parts of the page people hovered on with their mouse pointer. The tradeoff is that Google gets all of this information too.