Docs Vector Expressions ProFeaturesGlobal Variables PRO

Global Variables

Global Variables let you define named values that persist across page loads, within a user’s session, or site-wide. This enables cross-page state without JavaScript or cookies managed manually — ideal for multi-step funnels, personalization chains, and feature flags.

Variable Scopes

ScopeLifetimeUse Case
sessionUntil browser session endsMulti-step form tracking, funnel state
userPersistent per logged-in user (WP usermeta)Dark mode preference, onboarding step
siteGlobal for all visitorsFeature flags, maintenance mode, sale state

Defining a Global Variable

In Settings → Vector Expressions Pro → Global Variables, click Add Variable and configure:

  • Key: The identifier used in expressions (e.g., sale_active)
  • Scope: session, user, or site
  • Default Value: The resolved value when no stored value exists

Reading Variables in Expressions

Global variables are accessible via the global data root:

{{ global.sale_active ? "50% OFF — Today Only!" : "" }}
{{ global.onboarding_step == "3" ? "is-step-3" : "" }}
{{ global.user_theme | default "light" }}

Writing Variables

Variables can be updated via the REST API endpoint provided by Pro:

POST /wp-json/vector-expressions-pro/v1/globals
{
  "key": "sale_active",
  "value": "true",
  "scope": "site"
}

Requires authentication with manage_options capability for site scope, or read for session/user scopes.

Use Case: Feature Flag

  1. Define a site-scoped variable: feature_new_checkout = false
  2. Use it to conditionally show a block:
Visibility: Show if True → {{ global.feature_new_checkout == "true" }}
  1. Flip the flag via the REST API to instantly enable the feature for all visitors, no deployment required.