# Sign-up forms on your site

Pop-ups, flyouts and embedded forms you publish in Rasket, shown by one script. Each form has rules, and the visitor's browser decides which form to show from what the page already knows. Nothing about the visitor is sent to decide it.

## Put forms on a site

On Shopify, turn on the Rasket app embed in your theme. Anywhere else, start the script with your publishable key, then add the `rasket.js` tag your form's page in Rasket gives you:

The forms snippet:

```text
<script>
  window.rasket = window.rasket || function () { (rasket.q = rasket.q || []).push(arguments); };
  rasket("init", { key: "rk_pub_…", forms: true });
</script>
```

Pop-ups and flyouts appear by themselves. An embedded form fills every `<div data-rasket-form="<form id>">` on the page; give the div a `min-height` so the page does not move when it fills.

## Targeting rules

A pop-up or flyout shows only when every rule it has holds. A rule that needs something the page has not said, such as a cart rule on a site that never sends a cart, waits rather than guessing, so a form without that rule still shows.

| Rule | Holds when |
| --- | --- |
| Device | Computer, phone, or both. |
| Pages | Every page, only these paths, or every path but these. `/sale*` matches a prefix. |
| Page type | Home, product, collection, cart, search, blog, article or page. Shopify says which; elsewhere the rule waits for `context`'s `page_type`. |
| Subscribers | Hide from people who already get your emails: a logged-in Shopify customer who accepts marketing, anyone who signed up through a form in this browser, a visit that came from one of your Rasket emails, or `identify({ subscribed: true })`. |
| Customers | Hide from people who have bought: a logged-in Shopify customer with an order, or `identify({ customer: true })`. |
| Visitor | Anyone, new, or returning. A visit ends after thirty minutes without a page; a second visit, or a logged-in customer, is returning. |
| Country | Only in, or never in, these countries. When the country is unknown, the rule waits. |
| Cart | A cart worth at least an amount in your shop's currency, or holding at least so many items. On Shopify a cart in another currency is converted at the store's rate. |
| Products | One of these products is on screen, was looked at this visit, or is in the cart. |
| Schedule | Shows from a start time, until an end time. |

An embedded form shows wherever you put it, by its page rule alone: hiding it would leave the space you kept for it empty.

## Priority and frequency

- When several pop-ups and flyouts qualify, only those with the highest priority can open, and among them the first whose trigger fires. Equal priorities behave like forms without one.
- At most one pop-up or flyout opens per visit, in every tab together.
- Closing a form keeps it away for its “show again after” days. Signing up keeps it away for its “after a sign-up” days, or for good.
- Triggers: after a delay, at a scroll depth, on leaving the page (on a phone, a quick scroll back up), and after something is added to the cart. A pop-up never opens in the first five seconds on a phone.
- Nothing opens by itself in Shopify's theme editor.

## Tell the rules what your site knows

On Shopify the app embed does this for you. Anywhere else, two calls give the rules their inputs:

The identify and context hooks:

```text
// This visitor already gets your emails, or has bought from you.
rasket("identify", { subscribed: true, customer: true });

// What the page knows: the cart, in your shop's currency, and the product on screen.
rasket("context", {
  cart: { value: 82.5, items: 3, products: ["red-tee"] },
  product: "red-tee",
});

// Something was just added to the cart.
rasket("context", { cart: { value: 102.5, items: 4, products: ["red-tee", "cap"] }, added: true });
```

- `identify` with `subscribed` or `customer` stays in the page. With an `email` it is also a store event, sent only after the visitor's consent, as it always was.
- `context` takes any of `page_type`, `product`, `cart` (`value`, `items`, `products`) and `added`. Call it again whenever something changes; a form that now qualifies is armed from that moment.
- A link carrying `rk_s=1`, such as one you put in a Rasket email, marks the visit as a subscriber's and is removed from the address bar; it holds no id.

> Forms set no cookie and send no event, so they run before any consent answer. The browser keeps a few things in local storage, with no identifier: when each form may show again, that this browser signed up, and the visit (how many there have been, whether a form showed, the products looked at).
