For example, the U.S. Treasury Secretary Albert Gallatin administered sanctions against Great Britain in retaliation for the impressment of American sailors dating back to the War of 1822. How can a country force sanctions on another country and expect them to follow through?
I'm not completely I understand your question.
As a matter of U.S. domestic law, the Constitution provides Congress with the power "to regulate commerce with foreign nations." Congress, then, can directly pass economic sanctions against other countries or it can delegate the authority to do so to the executive branch. In the period you're referencing leading up to the War of 1812, Congress passed a number of laws restricting U.S. trade with Britain in France in response to the rising diplomatic tensions including the Non-Importation Act of 1806, the Embargo Act of 1807, and the Non-Intercourse Act of 1809.
While Congress has the legal authority to pass these sorts of measures, actual implementation was carried out through the Treasury Department and the Navy (thus the role of Gallatin though he was not an embargo enthusiast). For example, the Embargo Act of 1807 authorized the president "to give such instructions to the officers of the revenue, and of the navy and revenue cutters of the United States as shall be best adapted for carrying the same [the embargo] into full effect."
The United States can't force another country to comply with sanctions. In general, a sanctions program provides civil or criminal penalties for U.S. persons who engage in prohibited trade/interactions. In cases where the U.S. is seeking to prevent trade between the U.S. and some foreign country, this is sufficient. It takes two to trade, so if you can block the U.S. side of the transaction, that's good enough.
While the early American pattern involved specific Congressional authorization for any given sanctions program, Congress has increasingly delegated the power to impose sanctions directly to the executive branch. In 1917, Congress passed the Trading with the Enemy Act (TWEA) allowing the President to impose sanctions (and other economic measures) in response to emergencies. Despite the title, the powers involved extend beyond what you might think of as "enemies." The main sanctioning authority today comes from the International Emergency Economic Powers Act of 1977 (IEEPA) which allows the president to impose sanctions in response to national emergencies though there are a variety of other specific legal authorities. The powers under IEEPA are extremely broad: in response to an "any unusual and extraordinary threat" (which is vague enough to encompass just about anything) the president may "investigate, block, or prohibit... any transactions in foreign exchange." Violation of IEEPA sanctions exposes the violator to civil penalties of twice the value of transaction in question and criminal penalties of up to 20 years imprisonment and a fine of $1,000,000.
There are other kinds of sanctions as well. Perhaps most pertinent to your question are attempts by the United States to impose economic sanctions affecting third parties. To be clear, this was not done before the War of 1812 but it has been done since. As a practical matter, if you want to sanction third parties you have to find some way to legally justify your sanctions and some way to punish violators. The United States has used military force to enforce arms embargoes imposed by the UN Security Council. Here, the goal is to prohibit third parties (not just U.S. person) from trading in arms.
In the Bosnian case, for example, the Security Council in Resolution 787 authorized states to take "such measures commensurate with the specific circumstances as may be necessary under the authority of the Security Council to halt all inward and outward maritime shipping in order to inspect and verify their cargoes." In the language of the UN, that's authorization to deploy military forces. Under Operation Sharp Guard, NATO (thus the US) undertook enforcement of this and inspected thousands of ships with a naval task force. In such cases, you're relying on coercion not consent.
You can also threaten to sanction third parties who trade with sanctioned entities. The most famous example of this, assuming you're interested in non-US cases, is the Arab League boycott of Israel. The countries of the Arab League agree to prohibit their own citizens and companies from doing business with Israel (the primary boycott) but they also impose a boycott of any company that does business in Israel (the secondary boycott). The extent to which this is enforced has varied considerably over time and place but it's another way of sanctioning someone over whom you don't have direct influence.
On sanctions before the War of 1812:
-Donald Hickey, "American Trade Restrictions during the War of 1812" (JSTOR)
-Herbert Heaton, "Non-Importation, 1806-1812" (JSTOR)
On IEEPA
-Congressional Research Service, "The International Emergency Economic Powers Act: Origins, Evolution, and Use" (ungated)
On Bosnia Arms Embargo
-Kathleen Reddy, "Operation Sharp Guard: Lessons Learned for the Policymaker and Commander" (ungated)
On Boycott of Israel
-Congressional Research Service, "Arab League Boycott of Israel" (ungated)