GuidesBuy buttons
Sell with buy buttons
on any site.
Paste a script tag and a button into any page: a blog, a landing page, your docs. The button opens anyshop's checkout for one product, in an overlay on the sites you list and in a new tab anywhere else, and anyshop takes the payment and delivers the order. No API key, no server.
Make a button
In the dashboard, open Storefront, then Buy buttons. Choose the product, the button's text and its style, and copy the code under Paste this where the button goes:
<script src="https://js.anyshop.io/v1.js" async></script>
<anyshop-buy store="pixelforge-supply" product="nightfall-audio-suite" variant="var_01m3rs9d2f4k6m8p0r2t4v6x8z" theme="dark">
Buy for $49
</anyshop-buy>Load the script once per page, wherever you like; every <anyshop-buy> on the page becomes a button. The button is a real link, so it opens checkout in a new tab even before the script has loaded, or without it.
| Attribute | |
|---|---|
store | Your store's address name, as in pixelforge-supply.anyshop.io. |
product | The product's address name, from the builder. |
variant | The product option it sells (var_...). |
quantity | Optional: how many, by default the product's minimum (1 unless you set one), between its minimum and its per-order limit. The buyer can change it at checkout. |
theme | dark (the default), light, or brand for your store's accent color. |
color | With theme="brand": the button's color as #rrggbb. |
The text between the tags is the button's label. The button's style lives in its own shadow root, so your page's CSS does not change it; style the part named button with anyshop-buy::part(button) if you want to.
A link instead
Any link to your checkout works as a buy button too. Mark it with data-anyshop, and the same script gives it the overlay:
<a data-anyshop href="https://pay.anyshop.io/?store=pixelforge-supply&product=nightfall-audio-suite&variant=var_01m3rs9d2f4k6m8p0r2t4v6x8z">
Buy Nightfall Audio Suite
</a>Sites allowed to open checkout
Checkout opens in an overlay on the page only on the sites you list, under Sites allowed to open checkout on the Buy buttons page. On any other site the same button opens checkout in a new tab, so a copied button still sells, but no other site can show your checkout inside its own page.
- A site is an address without a path:
nightfall-audio.commeanshttps://nightfall-audio.com. - Each name is exact, with no wildcards:
www.nightfall-audio.comandshop.nightfall-audio.comare entries of their own. - Up to 10 sites. anyshop's own addresses are never one.
- Owners and admins add and remove them. Removing a site turns its buttons back into new tabs.
The same list says where a headless checkout may send buyers back to.
What the buyer sees
- When the buyer points at, focuses or taps the button, the script asks
js.anyshop.ioonce whether this site may show checkout in an overlay. Until then, the script sends nothing. - On click, checkout opens in an overlay over your page, with "Opening checkout" until it has loaded, or in a new tab on a site that is not listed. Holding Ctrl, Cmd or Shift opens a new tab anyway.
- The buyer pays in the overlay. Stripe's, PayPal's and NOWPayments' own pages open in a new tab, and the overlay follows the payment until it is confirmed.
- Paid, the overlay shows the thank-you page with the order, and the buyer gets it by email.
The overlay is a dialog: focus stays inside it, Escape or the close button closes it, and focus goes back to the button.
Events on your page
The button fires DOM events that bubble up through your page, and carry no buyer data:
| Event | When | detail |
|---|---|---|
anyshop:open | The overlay opened | |
anyshop:close | The overlay closed | |
anyshop:completed | The order is paid | { order }, the order number the buyer also sees |
document.addEventListener("anyshop:completed", (event) => {
analytics.track("purchase", { order: event.detail.order });
});Treat anyshop:completed as a signal for your page, not as proof of payment: for that, use the order.paid webhook (see React to orders).
Privacy and your site's policy
The script is small (under 3 KB compressed), sets no cookies, and talks only to anyshop's own hosts. Browsers cache it for 5 minutes, so a fix reaches every site within the hour. If your site has a Content-Security-Policy, allow:
| Directive | Source |
|---|---|
script-src | https://js.anyshop.io |
connect-src | https://js.anyshop.io |
frame-src | https://pay.anyshop.io |