Could be diet related, but more often than not it is boredom or just a dirty habit.
My first ever dog waaaaay back, was a rescue GSD that did this. We went through everything, pineapple, courgette, rattle bottle, diet, more exercise, extra training, puzzle toys - you name it. Nothing worked. She then cleverly managed to teach it to our next pup who then taught it to the next so on. 20 years later and we still have one of those pups that will occasionally try to snatch a snack given the opportunity.
At the end of the day if you've tried everything else and those pills don't work you just have to do what we did, train them to 'go' on cue and then you can always be there to clean up before they do iyswim.
I founf this on the internet and it says what I was going to try to say, only better!
The best means of stopping this behaviour is prevention. With close supervision and plenty of other stimulation, most dogs grow out of this habit. Keep your dog on the lead if need be, particularly in areas where you know there are lots of animal faeces around. Take special care to regularly clean up stools from the garden. Some say that this should be done out of site of your dog, so that it does not itself pick up a learned behaviour from watching you picking them up.
Ensure your dog is getting a balanced diet with all the correct vitamins and minerals. If you feed your dog once a day, consider spreading your dog's food across two or three meals if that is convenient. This may help reduce coprophagia if it is related to hunger problems.
If you catch your dog about to eat a stool, startle them with a loud "No" and call them over to you. Only do this if you catch them in the act, not a few seconds later. Praise your dog if they respond to your command. Although unlikely in well treated and confident dogs, care must be taken with disciplining this behaviour as some dogs may use coprophagia as a means of getting your attention, even if it is negative attention.
To prevent against ingestion of internal parasites from faeces, always ensure your dog is regularly de-wormed.