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.
1. Publish the event
Section titled “1. Publish the event”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).
2. Add the tag
Section titled “2. Add the tag”<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().
In React
Section titled “In React”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)} />Options
Section titled “Options”Attribute (data- on the tag) | |
|---|---|
slug (data-event) | Required. The event’s slug. |
mode | button (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, color | Button text (default Get tickets) and colour (#RRGGBB); the text is white, or near-black where white wouldn’t read. |
title | Screen-reader name for the pop-up and frame (default Get tickets). |
ch | Where buyers came from, for your sales by source. |
Access codes and hidden tickets
Section titled “Access codes and hidden tickets”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.
Hear when tickets are bought
Section titled “Hear when tickets are bought”Two events bubble to window (and the element):
| Event | detail |
|---|---|
tuppence:tickets.completed | order: id, status, amount_total, currency, quantity (no buyer details, no codes) |
tuppence:tickets.cancelled | reason: "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).
What the buyer sees
Section titled “What the buyer sees”| Pop-up | A 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. |
| Inline | As tall as the event’s page; your page scrolls, not the frame. |
| Paying | Card fields, Apple Pay and Google Pay stay in the frame (allow="payment *"). |
| Their tickets | Links 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.
A site with a Content-Security-Policy
Section titled “A site with a Content-Security-Policy”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.