# For developers

Your site has the line. Here is what its page can hear from a widget, how it opens one, and what a strict security policy has to allow.

## Hear from your widgets, and open one from your page

Events

Each is an event on your page, coming up from the widget’s own element, so a listener on `document`, or on the element you gave it as its spot, hears it. `event.detail` holds the widget’s id and its type, and nothing a visitor wrote.

`widgetjoy:ready` when a widget is drawn for a visitor. `widgetjoy:submit` when a message or a sign-up is accepted, and `widgetjoy:error` when one does not go. `widgetjoy:ended` when a countdown reaches its end while it is watched. `widgetjoy:action` when a button or link in a bar or a countdown is followed, with `button` saying which: `first`, `second` or `end`, the countdown’s own at zero.

Opening a widget

A contact form or a newsletter sign-up in a corner opens, one inside your page is scrolled to, and a popup opens whatever its moment says; the first field takes the cursor. Use its widget id, which is in its address in your Dashboard. A widget that is not on this page is left alone: the link you gave goes where its address says.

Count what visitors do

```
// Count what visitors do in your widgets, in Google Analytics.
for (const name of ["ready", "submit", "error", "ended", "action"]) {
  document.addEventListener(`widgetjoy:${name}`, (event) => {
    const { widgetId, type, button } = event.detail
    gtag("event", `widgetjoy_${name}`, { widget_id: widgetId, widget_type: type, button })
  })
}
```

Open a widget from your own button

```
<!-- A button of your own that opens a widget of yours -->
<button data-widgetjoy-open="wj_wg_…">Contact us</button>

<script>
  // Or from your own code: true when that widget is on this page. Where the line is not installed,
  // window.widgetjoy is not there, and the?. stops the call.
  window.widgetjoy?.open("wj_wg_…")
</script>
```

## If your site sets a Content-Security-Policy

An allow-list

Allow `https://widgetjoy.com` in `script-src` and `connect-src`.

A nonce with `'strict-dynamic'`

That ignores addresses in `script-src`, so put your page’s nonce on the line instead — `<script nonce="…" src="…" async crossorigin>` — and keep `https://widgetjoy.com` in `connect-src`.

Nothing else

`style-src`, `img-src` and `font-src` need no change.
