Price Alerts Widget

Use this page as the complete guide for embedding and integrating the Price Alerts Widget. It includes a live demo, step-by-step instructions, API details, and troubleshooting tips.

Live demo

The widget below is rendered by the exact script you will embed.

Quick start

  1. Add the script tag that serves the widget JavaScript from this service.
  2. Preferred: use the custom element directly in your markup.
  3. Alternative: use the legacy PriceAlertsWidget.render(target) API.

Preferred usage (replace https://your-domain.example with the host of this service if embedding elsewhere):

<!-- Include the widget script -->
<script src="https://your-domain.example/static/widget.js" async></script>

<!-- Use the custom element anywhere on the page -->
<price-alerts-widget lang="auto" symbol="BTC" currency="usd"></price-alerts-widget>

Legacy wrapper (still supported):

<script src="/static/widget.js"></script>
<div id="pa-root"></div>
<script>window.PriceAlertsWidget.render('pa-root', { lang: 'auto', symbol: 'BTC' })</script>

Embedding from the same host

If this page is served from the same host that will serve the widget, you can reference the relative path:

<script src="/static/widget.js"></script>
<price-alerts-widget lang="auto" currency="eur"></price-alerts-widget>

Rendering API

The widget can be used as a Custom Element or via a legacy wrapper.

Custom Element

Legacy wrapper

The global object window.PriceAlertsWidget exposes:

Return value: void.

Current behavior and capabilities

Styling and isolation

Theming (CSS Custom Properties)

You can theme the widget by setting CSS variables on the element. Defaults are shown below.

price-alerts-widget {
  --pa-font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --pa-bg: #fff;
  --pa-fg: #111827;
  --pa-border-color: #e2e8f0;
  --pa-border-width: 1px;
  --pa-radius: 8px;
  --pa-padding: 12px;
  --pa-shadow: none;
  --pa-accent: #2563eb;
  --pa-accent-weak: #2563eb22;
  --pa-muted: #6b7280;
  --pa-input-height: 40px;
  --pa-max-width: 480px;
  --pa-min-height: 352px;
  --pa-button-bg: #111827;
  --pa-button-fg: #fff;
  --pa-button-bg-hover: #0b1220;
}

Additionally, the outer container is exposed as a CSS part:

price-alerts-widget::part(container) {
  box-shadow: 0 0 15px rgba(0,0,0,.2);
}

Server endpoints

The widget calls the following endpoints on the same origin that serves /static/widget.js:

Response examples

/api/v1/coins (USD):

[
  { "id": "bitcoin",  "symbol": "btc", "name": "Bitcoin",  "price": 64000.12, "image": "https://<host>/images/btc.png" },
  { "id": "ethereum", "symbol": "eth", "name": "Ethereum", "price":  3200.45, "image": "https://<host>/images/eth.png" }
]

/api/v1/search?q=bit&currency=eur:

/api/v1/coin/eth?currency=usd:

{
  "id": "ethereum",
  "symbol": "eth",
  "name": "Ethereum",
  "price": 3200.45,
  "image": "https://<host>/images/eth.png"
}
[
  { "id": "bitcoin", "symbol": "btc", "name": "Bitcoin", "price": 59000.33, "image": "https://<host>/images/btc.png" }
]

POST /api/v1/alerts request body:

{
  "email": "you@example.com",
  "symbol": "BTC",
  "currency": "usd",
  "target": 65000,
  "above": true
}

Success response:

{ "ok": true, "id": "abc123", "validated": false }

Validation flow

After submitting an alert, a confirmation email with a validation link is sent (if SMTP is configured). The link targets /validate/{token} and must be visited to activate the alert.

Cross-origin embedding

Limitations

Troubleshooting