Your dog has to be completely engaged during the training, from beginning to end. You do this by making sure your training session has these things:
you need to have a reward that they actually want, whether that's a piece of food or a toy to play with.
The dog will always feed off of your energy. If you are excited, and you have something they want, they are more likely to be engaged during the training and block out any distractions.
The fun and engagement that the dog is having with you must always be higher than the level of distractions around your training area. As a beginner, always start your training sessions in a controlled environment where your dog isn't going to be distracted by anything.