# The ticket widget

Sell tickets inside your own website. The widget shows an event's ticket tiers in your page; **Buy** opens Lupeno's checkout in its own window (a popup on a computer, a tab on a phone), where the buyer pays your gateway or your bank account as on the event page. A sold-out type with a waitlist links to it, and bundles that include the event are linked under the tickets; both open Lupeno's page in a new tab. Your page hears back when the order is done.

## Paste the snippet

```html
<a href="https://lupeno.com/e/your-event-slug" data-lupeno-link>Buy tickets</a>
<script src="https://lupeno.com/widget.js" data-event="your-event-slug" async></script>
```

The widget appears where the script is. The link before it is for a visitor whose browser never runs the script — a site with a strict Content-Security-Policy, a content blocker that drops third-party scripts: they still get a way to buy. Where the script runs, it hides the link while the widget loads and removes it once the widget shows; word the link as you like, it only has to carry `data-lupeno-link` and stand right before the script (or inside the `data-target` element). The event's **Integrations → Embed** section gives you the snippet with the link already in your event's language. The event's slug is the last part of its address, `lupeno.com/e/your-event-slug`. It needs no key: the widget shows only what the event page shows.

| Attribute | Default | What it does |
|---|---|---|
| `data-event` | — (required) | The event's slug |
| `data-lang` | the event's language | `cs` or `en` |
| `data-theme` | the event's embed theme | `auto` (follows the visitor's system), `light` or `dark` |
| `data-target` | right after the script | A CSS selector of the element to put the widget in |
| `data-title` | "Vstupenky" / "Tickets" | The frame's accessible name, read by screen readers |

The frame sizes itself to its content. If the frame cannot load — a site not on the event's list, a browser refusing the frame — the widget becomes a plain link to the event page: your own link from the snippet, or one the script makes when you left it out. If the script itself cannot load, only your own link is there, so keep it in the snippet.

**If your site sends a Content-Security-Policy**, allow `https://lupeno.com` in both `script-src` (the script) and `frame-src` (the widget's frame) — otherwise the browser refuses one or the other and your visitors see only the link.

## Which sites may show it

In Lupeno, the event's **Integrations → Embed** section lists the sites allowed to frame the widget (`festival.cz`, or `*.festival.cz` for every subdomain). An empty list allows any site. The browser enforces it: on a site not on the list the frame does not load and the plain link appears instead.

## Hear about orders

When a buyer completes an order in the checkout window, the widget dispatches a `lupeno:order` event on its container. It bubbles, so you can listen anywhere above it:

```html
<script>
  document.addEventListener('lupeno:order', (event) => {
    const { event: slug, status, orderNumber, totalMinor, currency } = event.detail;

    // Only a paid order is a purchase: 'awaiting_payment' and 'pending_approval' are not (yet).
    if (status !== 'paid') return;

    window.dataLayer?.push({ event: 'purchase', transaction_id: orderNumber, currency, value: totalMinor / 100 });
  });
</script>
```

`status` is one of:

| Status | Means |
|---|---|
| `paid` | The order is paid (or free) and its tickets are issued |
| `awaiting_payment` | A bank transfer not yet received — the frame says "waiting for your payment" |
| `pending_approval` | A request the organizer decides (a ticket type that needs approval); nothing is paid yet |

Handle a status you do not know as "not paid". When a transfer arrives or a request is approved and paid, Lupeno pays the order, which a [webhook](https://lupeno.com/developers/guides/webhooks) (`order.paid`) tells your server. **Treat the DOM event as a signal for your page, never as proof of payment** — a page script can dispatch it too. The webhook, signed, is the proof.

## Attribution

The checkout window carries your page's UTM parameters, ad click ids and your site's address, so the order is attributed to the campaign that brought the buyer to *your* page — in the event's analytics as a widget sale from your site.

## On WordPress

The **Lupeno Tickets** plugin puts the same widget on a WordPress site without touching code. Install it from its zip:

1. Download [`lupeno-tickets.zip`](https://lupeno.com/developers/lupeno-tickets.zip). In WordPress, open **Plugins → Add New Plugin → Upload Plugin**, choose the file, select **Install Now**, then **Activate**. (It is not in the plugin directory.)
2. In Lupeno, open your organization's **Integrations** tab and make an API key with the **Read** scope. A key for one event works too; the plugin then offers that event alone.
3. In WordPress, open **Settings → Lupeno Tickets**, paste the key and select **Connect**. The page shows the organization the key belongs to.
4. Add the **Lupeno tickets** block to a page and pick the event from your upcoming events, with its language and theme. On a site without the block editor, use the shortcode:

```text
[lupeno_tickets event="your-event-slug" lang="cs" theme="auto" title="Vstupenky"]
```

`event` takes the slug, or the event's `lupeno.com/e/…` address (an event on its own domain has no slug in its address: use the slug); the other attributes are optional and mean what the script's do. Without the plugin, the script tag above works in a **Custom HTML** block just the same. The key stays on your server: the plugin reads only your organization's name and its upcoming events, and your pages load `widget.js` exactly as above, so `lupeno:order` and the allowed-sites list work the same.

## Your own iframe

You can frame `https://lupeno.com/e/<slug>/embed` yourself, without `widget.js`. You then size it yourself and receive the frame's raw messages; accept them only when `event.origin === 'https://lupeno.com'`:

```js
window.addEventListener('message', (event) => {
  if (event.origin !== 'https://lupeno.com' || event.data?.type !== 'lupeno:order') return;
  // event.data: { v: 1, type: 'lupeno:order', status, orderNumber, totalMinor, currency }
});
```
