There are two things I did that have had a big positive impact. I use a website blocker - I use Inmotion.app, which also has some other bells and whistles and that was very helpful.
Another thing that helped was tracking my time in a spreadsheet in 15 minute intervals. I color code the time - green for coding and building, red for 'unproductive', purple for necessities - family, working out, meditation etc. I don't make entries every 15 minutes, just whenever I remember but the sheet is open in front of me all the time. This has finally brought the discipline I sometimes lacked.
There is a power to looking back over the last x blocks of 15 minutes and coloring them red. It makes me want to make my day as green as possible and I find myself competing with myself - I highly recommend it.