When I socialized my lab to anything I thought could be frightening (including gun shots) I crouched down next to him and hugged him while stroking his side.
By the time he heard his first gunshot he was older and wasn't that startled but I remember the first time he saw a train when he was about 3 months old. We sat at the crossing crouched down and when the train blew its horn he freaked out a bit but I was holding on to him and saying comforting things and he relaxed in a second and refocoused on the treat in my other hand. Now he doesn't even flinch at the trains.
The goal is to make the gunshot associated with positive emotions. You know your dog better than anyone but usually a treat elicits pretty positive emotions.