If you can get a few blocks of 20-40 minutes of focus, punctuated by other stuff, you are doing pretty well
While the factors above are not possible to control in the moment, There are entirely controllable elements that you can use to increase your readiness to focus. There is your physical environment – you can remove clutter and things that you know typically attract your attention (examples – desk clutter, the cat). Make sure you are reasonably comfortable, warm (or cool – depending on your particular climate). Your digital environment provides untold opportunities for distractions. Close tabs, close applications, and just have open the one or two apps you need for the job. Disable notifications for anything that runs in the background that’s likely to pop-up or ping.
Then there are all those itches that you know you like to scratch – the distractions that we go looking for when boredom with the current task grows, or when it begins to get difficult. Things like snacking, going to the toilet, checking your phone. Take care of these things if you can, before you begin. The aim is to eliminate the power they have over you, for a while at least. You don’t have to see to them all, you can make a promise to yourself about when you will, to keep them quiet. Make a deal with yourself about the time you will spend staying focussed. Give yourself twenty minutes after which you promise yourself to indulge one or more of your itches – like a binge on social feeds, or a quick snack/coffee.
OK, almost ready start. Check your phone again if you must and now put it on silent, and out of arm’s reach, face down. No cheating.