The Root of the Behavior
Tail wagging seems to be the same for dogs as smiling is with humans. Researchers believe that dogs use the tail to communicate on purpose, but at times it is an instinctual reflex that gets his tail wagging as well. Studies have found that a dog also only wags his tail when another person or animal is around, much like you typically only talk when you have company. This suggests that whether he is intentionally or reflexively trying to communicate does not matter as much as the fact that his tail is a form of communication. With this in mind, it seems that a dog that hits you with his tail is doing so purely by accident. He may be wagging as a reflex, or to express himself, but he is not using it as a weapon or a way to reach out and touch someone like he would his snout or paws.
Encouraging the Behavior
If his tail is whipping back and forth in the high position, known as flagging, he is most definitely about to go on the attack and should be avoided. In dogs with curled tails, such as the Pug, a tense tail does not necessarily get higher but rather the curl gets tighter. This expression could simply mean the Pug is aroused and you need to observe his other body language signs to determine if he is also aggressive. It is important to note that not all friendly dogs wag their tails, and not all tail wagging is friendly. If you are close enough to your dog that his tail can touch you while it wags, you will undoubtedly get hit. Finding a tail in your face can be startling, but it is important to assess his tail and get out of his way if you sense he is in a heightened state and possible aggressive.