I use two different tricks.
One a sprinkle baking soda all over the carpet and let sit for overnight, then I vacumn it up.
(Caution - this can make your vacumn bag very heavy)
Two - put white vinegar on a plate and set on a table in the middle of the room. This helps absorb the ordors in the air.
Hope this helps,