How it works
Add a<script scope="backend"> tag anywhere in your page HTML. The server extracts and runs the code before funnel events and template rendering. The tag is always stripped from the final HTML — it never reaches the browser.
Execution order
Backend scripts run early in the page lifecycle, before funnel events:- Page resolved and loaded
- Access control checked
- Backend script extracted, stripped from HTML, and executed
- Funnel events processed (script rules, splits, etc.)
- Template engine renders the page
- HTML sent to visitor
Sandboxing & security
Backend scripts run inside a QuickJS WebAssembly sandbox. This means:- No access to
process,require,fs,net, or any Node.js APIs - No access to the file system or internal network
- 8 MB memory limit per execution
- 10 second CPU timeout — the QuickJS VM is interrupted if pure-JS execution exceeds this
- 30 second wall-clock timeout — the entire execution (including database queries and HTTP calls) is killed if it exceeds this
- The
<script scope="backend">tag is always removed from the HTML, even if execution fails - Session and cookie writes are restricted so app-internal state cannot be overwritten
- Redirects are limited to relative paths and
http:///https://URLs - Response headers and cookie access are restricted for security
When a script throws or times out
If your backend script throws an error or hits a timeout, the visitor does not see the error message. The page continues to render as normal. Any variables or actions your script applied before the error are still used; anything after the error is skipped. Errors are logged on the server and may be reported to administrators for debugging. For development, useconsole.log() and check your backend or event logs.
Multiple script blocks
You can have multiple<script scope="backend"> tags on a page. They are concatenated in document order and executed as a single script.