Skip to content

Sell tickets on your own website

The event widget shows a published event on your site, in a frame from book.tuppence.ai: its dates, ticket types and the whole checkout. Buyers stay on your site, pay in the frame, and get their tickets by email as they would on the event’s own page.

Your pageTuppenceYour serverembed.js draws the event in a framebuyer picks tickets and paystuppence:tickets.completedticket_order.paid webhook

The widget shows an event that is on sale. Its slug is the end of its page’s address: book.tuppence.ai/e/agents-after-dark has the slug agents-after-dark (the slug field of the event).

<script async src="https://book.tuppence.ai/embed.js"></script>
<tuppence-event slug="agents-after-dark" mode="button"></tuppence-event>

Or on the tag itself, where it should draw:

<script async src="https://book.tuppence.ai/embed.js"
data-event="agents-after-dark" data-mode="inline"></script>

From your own button: TuppenceBook.open({ event: "agents-after-dark" }), and TuppenceBook.close().

The component loads embed.js once and draws the element. Save it as tuppence-event.tsx:

import { useEffect, useRef } from "react";
type Order = { id: string; status: string; amount_total: number; currency: string; quantity: number };
export function TuppenceEvent(props: {
slug: string;
mode?: "button" | "inline" | "popup";
label?: string;
color?: string;
onCompleted?: (order: Order) => void;
}) {
const ref = useRef<HTMLElement | null>(null);
const { onCompleted } = props;
useEffect(() => {
const src = "https://book.tuppence.ai/embed.js";
if (!document.querySelector(`script[src="${src}"]`)) {
const script = document.createElement("script");
script.async = true;
script.src = src;
document.head.append(script);
}
const el = ref.current;
if (!el || !onCompleted) return;
const heard = (e: Event) => onCompleted((e as CustomEvent<{ order: Order }>).detail.order);
el.addEventListener("tuppence:tickets.completed", heard);
return () => el.removeEventListener("tuppence:tickets.completed", heard);
}, [onCompleted]);
return (
// @ts-expect-error: a custom element, drawn by embed.js
<tuppence-event ref={ref} slug={props.slug} mode={props.mode} label={props.label} color={props.color} />
);
}
<TuppenceEvent slug="agents-after-dark" onCompleted={(order) => console.log(order.id)} />
Attribute (data- on the tag)
slug (data-event)Required. The event’s slug.
modebutton (default: a button where the element is), popup (a floating corner button) or inline (the event in the page, full height, never scrolling itself).
label, colorButton text (default Get tickets) and colour (#RRGGBB); the text is white, or near-black where white wouldn’t read.
titleScreen-reader name for the pop-up and frame (default Get tickets).
chWhere buyers came from, for your sales by source.

Ticket types that are hidden or access_code_only don’t show in the widget, as on the event’s page. A buyer types the code in checkout’s Promo code field, and the types it opens appear. Give the code to the people it’s for; the widget never needs it in your page’s code. Promo codes work the same way. See promo and access codes.

Two events bubble to window (and the element):

Eventdetail
tuppence:tickets.completedorder: id, status, amount_total, currency, quantity (no buyer details, no codes)
tuppence:tickets.cancelledreason: "closed": the pop-up was closed without buying
window.addEventListener("tuppence:tickets.completed", (event) => {
console.log("tickets", event.detail.order.id);
});

Browser events are lost if the page closes. Rely on webhooks for anything that matters (ticket_order.paid, ticket.issued).

Pop-upA dialog that holds focus until closed (Close, Escape or a click outside), then gives it back to the button. Full-screen on a small screen.
InlineAs tall as the event’s page; your page scrolls, not the frame.
PayingCard fields, Apple Pay and Google Pay stay in the frame (allow="payment *").
Their ticketsLinks to a ticket open in a new tab: ticket pages are never framed.

The widget follows the event’s mode: a test-mode event takes test cards only. See Testing.

Allow https://book.tuppence.ai in script-src and frame-src; no inline script or style is needed. To pin the loader with Subresource Integrity, see the booking widget’s notes: it is the same embed.js.

  • Events: create the event and its ticket types.
  • Webhooks: orders and tickets on your server.

Docs assistant

Open as a page
Loading the assistant…