For your own website
Checkout script
On this page
Put a link on any page of your own site, on WordPress, Webflow, Squarespace, Ghost or plain HTML, and it opens your product's card, or your email list's sign-up form, over that page. Your buyer pays on Stripe's checkout page, on your own connected Stripe account: the money goes from your buyer to you and never passes through Marktmorgen. Your page is told what happened, and so are your webhooks. Every plan has it. Make the code in your studio, under Checkout on your own website.
What you paste
A link, and once per page, the script. This is a link made in the studio:
<a href="https://marktmorgen.com/embed/harbor/k3j9x2p1ab?mm=page&utm_source=blog&utm_medium=checkout-script&utm_campaign=spring-launch&return=https%3A%2F%2Fwww.example.com%2Fthank-you" data-mm="overlay" referrerpolicy="origin" style="display:inline-block;padding:14px 28px;border-radius:999px;background:#15112e;color:#ffffff;font:600 16px/1.25 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;text-decoration:none;">Buy The 7-Day Reset</a>The link works with or without the script: followed as it is, it opens the card as a page of its own, whose buy button goes on to Stripe in the same tab. With the script on the page and data-mm="overlay", it opens the card in a frame over your page instead, and Stripe's checkout opens in a new tab, so your page stays where it was. With data-mm="page" the script lets the link be followed and only says it was pressed. A link to /embed/<store>/join opens your sign-up form the same two ways.
The address carries its own tags: utm_source is the place you name (website when you leave it empty), utm_medium is checkout-script, and utm_campaign is yours if you give one. A sale made through it carries them to Stripe and to your numbers, where it is listed under Where the money came from. return is the page the receipt sends the buyer back to; via is an affiliate's code, for a link an affiliate puts on their own site, which opens your product's page so your store's affiliate and consent rules apply there as they do to any affiliate link. Product ids are in your studio, and in the API's products list.
Your sites
List up to 10 of your own sites in the studio, each an https address such as https://www.example.com. Only on those does the card or the form open over the page, with its buy button or its box, and only those are told what happened. On any other site, or when the browser sends no address of the page, the frame shows a plain link, in a new tab, to your product's page (or, for the form, your store's page), and tells nobody anything. The return page has to be on one of your sites too, so the receipt can never send somebody to an address you did not name.
The frame knows which site it is on from the address the browser sends with it; the script asks for the site's origin only (referrerpolicy="origin"), never the page's path, and a web page cannot write that header itself. Once you list a site, the cards you pasted with the frame code show the plain link anywhere else as well. Until you list one, those cards work wherever they are pasted, as before.
Events on your page
The script dispatches these on the link that was pressed, so they bubble up to document. Each carries detail with kind (product or optin), handle, product (null for the form) and mode:
marktmorgen:open the link was pressed
marktmorgen:ready the card or form is showing (over the page)
marktmorgen:checkout the buy button was pressed; Stripe opens in a new tab
marktmorgen:optin the form was sent; detail.status is "sent" when the
confirmation email is on its way, else "email",
"limited", "closed" or "error"
marktmorgen:close the overlay closed; detail.reason says how
marktmorgen:purchase back from paying (on document); detail is
{ product, order }document.addEventListener("marktmorgen:purchase", (event) => {
// event.detail.order is the id of the sale.completed webhook for this order
showThankYou(event.detail.product);
});The purchase event: after paying, the receipt page shows a button back to the return page, whose address ends in #mm-purchase=<product>.<order>. The script on that page reads that mark from the address once, says marktmorgen:purchase, keeps it in window.Marktmorgen.purchase and takes the mark off the address. order is the same id as the sale.completed webhook's, so your server and your page can be matched.
These events are for what your page shows. Anybody can make a page say them, so never hand anything over because of one: what was paid is told to your server by the signed sale.completed webhook, and a confirmed sign-up by list.joined. The sign-up is a double opt-in: sent means the email with the button is on its way, and the address joins your list only once it is pressed.
Underneath, the frame sends window.postMessage messages of the form { marktmorgen: 1, type, height?, status? } to your site's origin alone, and the script takes a message only from https://marktmorgen.com and only from the frame it opened. The frame listens to no message from your page.
Webhooks
sale.completed now carries source: utm_source, utm_medium, utm_campaign and utm_content as the sale was tagged, and site, the listed site the checkout script opened it for, each null when there is none. list.joined is sent when somebody confirms their address to join your list, from your store page's box, one of your forms or the script, with their email, whether they allowed their link use in sequences to be seen, the form, the site and when they asked. Webhooks are signed and retried as on every other event; a store has up to 5 addresses.
What the script does, and does not
It listens for clicks on links that carry data-mm and point at https://marktmorgen.com/embed/, and reads that link's address, its data-mm and its text, which names the dialog. It reads nothing else on your page: no field, no cookie, no storage, no other element. It sets no cookie. It holds no key and no secret: the link names only your store and a product, and the price is always read from your store when the checkout opens. It makes no request when the page loads; Marktmorgen is asked for something only when somebody presses a link.
It draws the overlay as the browser's own modal dialog, with a close button. While it is open, the keyboard stays in the card and its close button, and the rest of your page cannot be reached. Once the card has loaded, the focus goes into it, unless the person has already moved it, for example to the close button. That button shows a ring of its own when it has the focus. Escape, the close button or a click beside the card closes it and gives the focus back to the link. A page that still has version 1 keeps working as before, without holding the keyboard in the dialog. It adds one global, window.Marktmorgen, with version, purchase and close(), and does nothing if it is on the page twice.
This is version 2, in full. It is the same for every store, so its hash is the same too:
/* Marktmorgen checkout script v2. What it does: https://marktmorgen.com/developers/checkout-script */
(function(w,d){
if(w.Marktmorgen)return;
var O="https://marktmorgen.com",open=null,api={version:2,purchase:null,close:function(){shut("page")}};
w.Marktmorgen=api;
function copy(a,b){var c={},k;for(k in a)c[k]=a[k];for(k in b)c[k]=b[k];return c}
function fire(t,detail,el){var e;try{e=new CustomEvent("marktmorgen:"+t,{detail:detail,bubbles:true})}catch(x){return}(el&&el.isConnected?el:d).dispatchEvent(e)}
function key(e){if(e.key==="Escape")shut("escape")}
function shut(why){if(!open)return;var o=open;open=null;w.removeEventListener("message",hear);d.removeEventListener("keydown",key,true);if(o.box.parentNode)o.box.parentNode.removeChild(o.box);d.documentElement.style.overflow=o.over;try{o.el.focus()}catch(x){}fire("close",copy(o.info,{reason:why}),o.el)}
function hear(e){if(!open||e.origin!==O||e.source!==open.frame.contentWindow)return;var m=e.data;if(!m||m.marktmorgen!==1||typeof m.type!=="string")return;if(m.type==="close")return shut("frame");if(m.type==="ready"){var h=Number(m.height);if(h>=160&&h<=800)open.frame.style.height=h+"px"}if(m.type!=="ready"&&m.type!=="checkout"&&m.type!=="optin")return;var more={};if(typeof m.status==="string"&&/^[a-z_]{1,20}$/.test(m.status))more.status=m.status;fire(m.type,copy(open.info,more),open.el);if(m.type==="checkout")shut("checkout")}
d.addEventListener("click",function(e){
if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;
var a=e.target&&e.target.closest?e.target.closest("a[data-mm]"):null;if(!a)return;
var u;try{u=new URL(a.href)}catch(x){return}var p=u.pathname.split("/");
if(u.origin!==O||p[1]!=="embed"||!p[2]||!p[3])return;
var join=p[3]==="join",info={kind:join?"optin":"product",handle:decodeURIComponent(p[2]),product:join?null:p[3],mode:a.getAttribute("data-mm")==="page"?"page":"overlay"};
if(info.mode==="page"){fire("open",info,a);return}
e.preventDefault();if(open)return;fire("open",info,a);u.searchParams.set("mm","overlay");
var box=d.createElement("dialog"),frame=d.createElement("iframe"),x=d.createElement("button"),name=(a.textContent||"").trim().slice(0,80)||"Checkout";
box.setAttribute("role","dialog");box.setAttribute("aria-modal","true");box.setAttribute("aria-label",name);
box.style.cssText="position:fixed;inset:0;z-index:2147483646;display:flex;align-items:center;justify-content:center;box-sizing:border-box;width:100%;height:100%;max-width:none;max-height:none;margin:0;border:0;padding:72px 16px 16px;background:rgba(17,14,36,.6)";
frame.src=u.href;frame.title=name;frame.referrerPolicy="origin";frame.onload=function(){frame.onload=null;var f=d.activeElement;if(f===frame||f===box)try{frame.contentWindow.focus()}catch(x){}};
frame.style.cssText="display:block;width:100%;max-width:400px;height:420px;max-height:calc(100vh - 96px);border:0;border-radius:24px;background:transparent";
x.type="button";x.setAttribute("aria-label","Close");x.textContent="\u00d7";
x.style.cssText="position:absolute;top:16px;right:16px;width:44px;height:44px;border:0;border-radius:999px;background:#fff;color:#15112e;font:600 26px/1 system-ui,sans-serif;cursor:pointer";
x.onfocus=function(){x.style.outline="3px solid transparent";x.style.boxShadow="0 0 0 3px #15112e,0 0 0 6px #fff"};x.onblur=function(){x.style.outline="";x.style.boxShadow="none"};
x.onclick=function(){shut("button")};box.onclick=function(ev){if(ev.target===box)shut("backdrop")};box.oncancel=function(ev){ev.preventDefault();shut("escape")};
box.appendChild(frame);box.appendChild(x);
open={box:box,frame:frame,el:a,info:info,over:d.documentElement.style.overflow};
d.documentElement.style.overflow="hidden";w.addEventListener("message",hear);d.addEventListener("keydown",key,true);d.body.appendChild(box);if(box.showModal)try{box.showModal()}catch(x){}frame.focus()
});
var mark=/^#mm-purchase=([a-z0-9]{6,40})\.(evt_[0-9a-f]{32})$/.exec(w.location.hash);
if(mark){api.purchase={product:mark[1],order:mark[2]};try{history.replaceState(history.state,"",w.location.pathname+w.location.search)}catch(x){}
var say=function(){fire("purchase",api.purchase)};if(d.readyState==="loading")d.addEventListener("DOMContentLoaded",say);else setTimeout(say,0)}
})(window,document);Content-Security-Policy
If your site sends a Content-Security-Policy, these let the script run and its frame open:
script-src 'sha256-vAy8ACKU0xMIEM+sArHeVlkwYaD9kOQ4dFDRNZIH22g='
frame-src https://marktmorgen.comThe hash matches the script exactly as the studio gives it. A builder that changes pasted code as it saves it changes the hash too; there, use the link on its own, which needs no policy at all.
- Your own HTML. Paste the link where it should show and the script once, anywhere in the page (before </body> is usual). If your server sends a Content-Security-Policy header, add the lines below to it.
- WordPress. In the block editor, add a Custom HTML block and paste both. The script can sit in the same block as the first link. WordPress sends no policy of its own. If a security plugin adds one, add the lines below in that plugin's settings.
- Webflow. Add a Code Embed element where the link goes and paste both, or put the script in the page's custom code, before </body>. If your site sends a policy, add the lines below to it.
- Squarespace. Add a Code block and paste both, with Display Source off. If your site sends a policy, add the lines below to it.
- Ghost. In a post or page, add an HTML card and paste both. If your site sends a policy, add the lines below to it.
- Wix and other builders that frame pasted code. An embed element there runs your code in a frame on the builder's own address, so the overlay would open inside that box. Use the link that opens a page instead (Opens: as a page), which works in any of them. Nothing to add: a plain link needs no policy.
On Marktmorgen's side, only the card and form pages under /embed/ may be framed by other sites; every other page of Marktmorgen may be framed only by Marktmorgen itself.
Limits
- Up to 10 sites per store, https only.
- Up to 30 cards or forms opened per connection per store in ten minutes; past that, the plain link shows until the ten minutes are over.
- Each person who opens a card or a form counts as a visit to your store, once a day, toward the visits your plan covers. A store past them shows the plain link, as its other pages rest.
- The checkout and the sign-up form keep their own limits: 20 checkouts per connection per store in ten minutes, and 10 sign-ups per connection per store and 5 per address in an hour.
- A view of a page that holds the script costs nothing and counts nothing: the script is written into your page and asks for nothing until it is pressed.
What it does not do
- It does not draw Stripe's card form inside your page. Stripe's checkout opens on Stripe's own page.
- It does not pick one of a product's price options for the buyer: a product with options, a plan, a box at checkout or a time to book opens its own page, where the buyer chooses.
- It does not read your page's address for tags or affiliate codes: what a link carries is what you put in it.
- The overlay inside a builder that frames pasted code opens inside that frame. Use the link that opens a page there.