Getting distracted while writing is really easy.
With social media, it's difficult not to get distracted. I myself am constantly on Instagram and Twitter, or Blogger. I can't help myself. I'm always checking out what's going on, and checking in on friends. Texts and calls are another distraction.
Put your phone on do-not-disturb and turn the Internet off on your computer, and get writing. And if these things don't help you, maybe write in a notebook instead. Do whatever you have to in order to stay off your phone and the Internet entirely so you can be focused on your project.
It's the only way to get yourself motivated and focused!
Not all distractions are bad though. If you're really sucked into a book that you're reading, you shouldn't necessarily pull yourself away from it to write. You should always read more than you write. Reading gets the creative juices flowing. It helps the words flow from your mind so you can type it, or write it down on paper.
Reading also helps with writer's block. If you're in a rut, read a book. Finish it front to back, or just read it until you get inspired enough to say, "Okay, I'm ready to sit down and fill a blank page."
If nothing helps you focus and shake those distractions, there's only so much you can do.
Things can get frustrating if you can't focus your mind on the world you are trying to create and be part of. When you can't focus, you don't write the same way you normally would. The words you write can seem dull. If you can't focus at all after a certain amount of time, maybe your mind is trying to tell you something. Walk away and do something to get your mind off your frustration. Come back to it later and turn all distractions off again as you try to focus solely on writing.
Okay, so that's all I have to say about that. Now go write!