This smelly liquid helps your dog mark its territory. Sometimes anal glands become blocked which causes irritation and pain. The most common sign of blocked anal glands is scooting your dog rubbing their bottom on the ground. Contact your vet if you think your dog has an anal gland problem. Blocked anal glands can usually be cured by careful emptying.
Pet Health Hub
Anal gland - Wikipedia
The anal glands or anal sacs are small glands near the anus in many mammals , including dogs  and cats. They are paired sacs on either side of the anus between the external and internal sphincter muscles. Sebaceous glands within the lining secrete a liquid that is used for identification of members within a species. These sacs are found in many carnivorans , including wolves ,  bears ,   sea otters  and kinkajous. The anal glands are in the wall of the anal canal. They secrete into the anal canal via anal ducts which open into the anal crypts along the level of the dentate line. The glands are at varying depths in the anal canal wall, some between the layers of the internal and external sphincter the intersphincteric plane.
Dog Anal Glands: The DIY Solution To Stinky Problems
There are a few theories as to why dogs have anal sacs and what purpose they serve. Some say the excretion from the anal gland act as a territorial scent marker. Others argue the excretion acts as a lubricant that helps a dog pass a hard stool. Like it or not, your dog is a predator. And as such your dog has two anal sacs, also called anal glands, located on the lower sides of his anus.
To help the anal glands to function properly, dogs need to consume the right amounts of fiber. Sadly, due to a lack of good fiber in the average canine diet, many dogs have to have their anal glands expressed manually … meaning the vet or groomer squeezes them by hand to get the fluid out. You know your dog marks his or her — girls do it too!