1. Vacuum your carpet at least once a week ,more if needed.
2. Have some indoor / outdoor mats at each entrance to reduce soil tracked into your home
3. Treat spots & spills Immediately to prevent them from becoming a permanent stain.
4.Almost any kind of spot remover that you can purchase will do the job,
as a last resort you may even make your own with a little amount of Liquid dish soap & cold water or Windex which will also work for spot removal.
As with any spot cleaning ,use the least amount.