How can a country ensure its national currency is used by its citizens? I am wondering how countries are able to force everyone to use its own currency, instead of some external currency (like the U.S. dollar or Bitcoin or cookies or something else not under government control). If businesses and citizens decide that they do not like the national currency (perhaps it is too turbulent or some other reason), and instead decide that they would like to "barter" a third-party currency for goods and services rather than "buying" those goods and services with the national currency, then the country would lose control of its own currency. This does happen at a small scale, where small businesses may accept a cryptocurrency instead of the local currency.

What different methods can a country employ to ensure that it does not lose control of its currency because its citizens switch to an unofficial alternate currency not controlled by the government?

If this situation does occur, how can a government still collect taxes on the exchange of this alternate money for goods and services? If I wanted to pay someone to mow my lawn in cookies instead of currency, the government could not tax this. If every business and citizen began treating cookies as the main form of payment, the government would lose all tax revenue. How can it stop this from happening?

If the answer involves creating a law that says "10% of all cookies (or bitcoins or something else) must be given to the government", then what prevents that currency from swiftly changing its name? Perhaps cookies become brownies, which do not fall under the law. Or bitcoins become a different cryptocurrency, or just change their name. This would become a game of cat-and-mouse between the laws and the currency. It seems like accepting alternate, nontaxable unofficial currencies, would become economically beneficial for both companies and individuals. Yet established governments in the world do not have this problem. How?
First of all, please check the properties of money and keep them in mind. Indeed money is a convention, but nobody forces you to use it. For example, prisoners use ciggarettes as a medium of exchange.

But let's assume you are the absolute ruler of a country and you want your people to use your currency. You can either do it by force or you have to give incentives to your citizens.

The most important function of a new currency is to hold its value. If let's say my new currency holds value against yen, dollar or euro, then there's no reason for not using it. It's convenient and stable.

How to do this? Via monetary and fiscal policy, using gold standard or by giving it prefix value against another stable currency. For example, a bunch of eastern european countries have a prefixed exchange like Bulgaria (check Bulgarian lev in wikipedia).