It is possible to have fully digital ticketing with complete anonymity (again, assuming no external surveillance) using zero-knowledge proofs. As far as I'm aware, no such systems have been implemented for ticketing yet, but rapid progress is being made in implementing these for general-purpose digital identity situations.
There's also the much more pedestrian^ option, used for instance in Brussels, where the transport company simply promises not to track individuals even when it would be possible for them to do just that. That said, in Brussels I personally got the impression that a large proportion of passengers did not present tickets when entering a bus or tram, and indeed the Brussels Metro trains don't require that anyway. Thus tracking of individuals' movements would be quickly thwarted by apathy on the part of passengers!
^: not the most pedestrian option, naturally.