I had a similar issue, and I'm self-employed, meaning I wasn't just losing time but also money. The problem was massively mitigated when I started using Toggl for time tracking. I became averse to stopping the clock, and would fight distractions and keep working. I still need about 2.5 hours of distractions to work 8 hours, be they lunch, breaks, etc., but it's much easier now.
And use the hosts file trick to break the habit of just opening a new tab and losing 15 minutes.
This is all assuming you like what you're doing. If you don't, you won't be able to fight distractions.