My pug has this issue fairly regularly and it is soooo gross.
We took her to the vet the first time and they charged $20 to express her anal glands. Ohhhh no! We Youtubed some vet DIY videos and I've made poor DH do it ever since and it works fine. Gross, though. Lol.
(And yes, she's on premium food so it's not a matter of her not having good nutrition. Some breeds are more prone to this than others. I always say it smells like metallic ... butt
lol )