Dogs (and most mammals, including humans!) have two glands inside of the anus which release a liquid when the animal defecates. This semi-oily liquid is used to mark territory and to identify other dogs.
A dog's anal glands (sacs) can become obstructed and inflamed, and if the anal fluid is not released, can become abscessed and infected.