This is probably from straining to have a bowel movement. The easiest way to prevent this is to use a well moistened food. If you put the dry food in water for a while to soak it before you feed it, that makes it move through better. If you have not had the dog to the vet for a worm check, that may also be a cause of blood inthe stool.
Respond if you need more information or if my answer didn't exactly answer your question. If I have been helpful, please accept the answer and please leave feedback.
Dr. Louis Gotthelf
Animal Hospital of Montgomery
Pet Skin and Ear Clinic