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 locked-down sandbox. This means:- No access to
process,require,fs,net, or similar host APIs - No access to the file system or private networks
- 8 MB memory limit per execution
- 10 second CPU timeout — pure JavaScript execution stops if it exceeds this
- 30 second wall-clock timeout — the entire run (including data loads and HTTP calls) stops if it exceeds this
- The
<script scope="backend">tag is always removed from the HTML, even if execution fails - Session and cookie writes are limited to safe, documented keys
- 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. Failures are recorded for your team to review in logs. 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.
Importing shared modules
You can share reusable functions and constants across pages using backend script modules. Create a module in your brand’s Backend Scripts section (with a code likeapp or utils), then import from it:
export statements, managed separately from pages. See Imports for the full reference.