You can buy repellent to spray onto your carpet to prevent your dog from peeing on the carpet or you can also make your own home remedy for repelling your dog from peeing on your carpet.
To make a homemade dog urine repellent take some freshly squeezed lemon juice and mix it with some water in a spray bottle.
Then spray the lemon juice and water mixture onto your carpet. The lemon juice will repel the dog and stop them from peeing on your carpet and will make the carpet smell fresh.
You should also have your dog spayed or neutered since a dog who's been spayed or neutered will stop peeing in the house and marking their territory.