Action functions let your backend script perform side-effects — set session data, cookies, redirect the visitor, inject template variables, or send custom responses.Documentation Index
Fetch the complete documentation index at: https://docs.elasticfunnels.io/llms.txt
Use this file to discover all available pages before exploring further.
Session
Read and write values in the visitor’s server-side session.For security, some session keys are reserved and cannot be read or written via
session.get() / session.set(). Use your own key names (e.g. my_key, visit_count) for custom data.session.setCustomer(fields)
Establish an authenticated customer session from a custom login flow — magic link, external OTP, SSO callback, or any mechanism outside the built-in purchase pipeline. Writes the runtime’s canonical customer fields (is_customer, email, customer_id, customer) so downstream pages, template variables, and access rules see the visitor as logged in.
| Field | Type | Required | Description |
|---|---|---|---|
email | string | yes | The customer’s email (must contain @). |
name | string | no | Full display name. If omitted, derived from first_name + last_name. |
first_name | string | no | First name. Merged into session.customer.first_name. |
last_name | string | no | Last name. Merged into session.customer.last_name. |
id | any | no | Internal customer id. When set, also writes session.customer_id. |
true on success, false on invalid input or quota exhaustion.
setCustomer merges over any existing session.customer object, so tracking fields such as total, currency, or order_ids set by earlier checkout flows are preserved.session.getToken(ttlSeconds?) / session.setFromToken(token)
Mint and consume short-lived encrypted tokens that carry the current customer identity across brand-owned domains. Used for cross-domain session continuity — see Cross-domain session handoff for the full protocol and a worked example.
session.getToken(ttlSeconds?) returns the token string (or null if the session has no customer). ttlSeconds defaults to 60 and is capped at 600.
session.setFromToken(token) returns true on success, false on any failure (tamper, expiry, replay, wrong brand). It never throws.
Cookies
Set or delete cookies on the visitor’s browser.cookie.set(name, value, options?)
| Option | Type | Description |
|---|---|---|
maxAge | number | Cookie lifetime in seconds |
path | string | Cookie path (default: '/') |
cookie.delete(name)
Clears the cookie by name.
Some cookie names are reserved and cannot be set or deleted. Use your own cookie names for custom data.
Redirect
Redirect the visitor to a different URL. This stops page rendering — the visitor is immediately sent to the new URL.When
redirect() is called, the entire funnel flow and page rendering are skipped. The visitor receives only the redirect response.Template Variables
Inject values into the template engine. These become available as{{ var.key }} in page HTML.
Scoping inside @foreach
When you iterate over a variable with @foreach, the loop variable is its own scope — it does not use the var. prefix:
var. is only for the top-level reference to variables set by setVariable. Once a value is assigned to a loop variable (cat, course, etc.), you access its properties directly.
Variables set with setVariable take precedence over brand variables with the same key.
Response Headers
Set custom HTTP response headers.For security, certain response headers cannot be set (e.g. those that control cookies, CORS, or connection). Header values are sanitized.
Custom Response
Send a custom response instead of the rendered page. These stop page rendering.response.status(code)
Set the HTTP status code (used with response.send() or response.json(), or with the normal page render).
response.json(data)
Send a JSON response. Skips page rendering.
response.send(html)
Send raw HTML. Skips page rendering.
Logging and errors
console.log, console.info, console.warn, and console.error are captured and stored in execution logs. Use them for debugging.