# Drop-in script

For sites without a build step (static HTML, Webflow, Framer, Shopify themes, WordPress, landing-page builders) SplitHub Cloud serves a small script that runs redirect experiments and tracks goals from the hosted config.

```html
<script src="https://go.splithub.io/sh.js" data-key="pk_live_…"></script>
```

Put it in `<head>`, as early as possible. The public key is safe to publish: it can only send events and read the public config.

## What it does on every page

1. Reads the hosted config and live overrides (cached in `localStorage`, refreshed on load when older than 60 s).
2. For `redirect` experiments whose `match` fits the current path: assigns the visitor with the same hash as the SDK (targeting flows included) and, when the variant points elsewhere, navigates to that destination. The rendering hold below reduces flashes.
3. Records the exposure, fires `pageview` goals, binds `click` goals from their selectors, and exposes `window.splithub.track()`.

```html
<button onclick="splithub.track('signup')">Start</button>
<script>
  (window.splithubq = window.splithubq || []).push(['track', 'purchase', { revenue: 49 }]);
</script>
```

## Hold rendering during the decision

On a page that is the subject of a redirect experiment, name it so the script holds rendering until the decision is made, even on the first visit with an empty cache:

```html
<meta name="splithub-experiment" content="landing">
```

The script also holds rendering when there is no cached config or a cached redirect matches the page. The meta tag explicitly requests a decision for this page. The hold lasts up to 1,500 ms by default; a timeout can reveal the original page. Put the meta tag before the script.

## What it cannot do

`component` and `value` experiments need the SDK in the app: the script does not change your markup. Use the script for whole-page tests and goal tracking, the SDK for everything inside the page.

## Options

| Attribute | Default | Meaning |
|---|---|---|
| `data-key` | required | the project's public key |
| `data-endpoint` | script origin + `/v1/events` | full events URL for a self-hosted cloud or staging |
| `data-hold` | `1500` | maximum rendering hold in ms; `off` disables the hold |

Use `?sh_debug=1` in the page URL for console diagnostics.

## Where experiments come from

Create redirect experiments in the dashboard (New experiment → Redirect) or in `splithub.config.ts` and `push`. Targeting flows (country, device, UTM…) created in the dashboard are evaluated by the script with the visitor's geo from the edge.
